diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 05c8aca7..f22105e3 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -461,43 +461,12 @@ declare module es { */ static divide(value1: Vector2, value2: Vector2): Vector2; static divideScaler(value1: Vector2, value2: number): Vector2; - /** - * - * @param value1 - * @param value2 - */ - static multiply(value1: Vector2, value2: Vector2): Vector2; - /** - * - * @param value1 - * @param value2 - * @returns - */ - static multiplyScaler(value1: Vector2, value2: number): Vector2; - /** - * - * @param value1 - * @param value2 - */ - static subtract(value1: Vector2, value2: Vector2): Vector2; - /** - * 创建一个新的Vector2 - * 它包含来自另一个向量的标准化值。 - * @param value - */ - static normalize(value: Vector2): Vector2; - /** - * 返回两个向量的点积 - * @param value1 - * @param value2 - */ - static dot(value1: Vector2, value2: Vector2): number; /** * 返回两个向量之间距离的平方 * @param value1 * @param value2 */ - static distanceSquared(value1: Vector2, value2: Vector2): number; + static sqrDistance(value1: Vector2, value2: Vector2): number; /** * 将指定的值限制在一个范围内 * @param value1 @@ -539,7 +508,7 @@ declare module es { * @param value2 * @returns 两个向量之间的距离 */ - static distance(value1: Vector2, value2: Vector2): number; + static distance(vec1: Vector2, vec2: Vector2): number; /** * 返回两个向量之间的角度,单位是度数 * @param from @@ -568,6 +537,7 @@ declare module es { */ static smoothStep(value1: Vector2, value2: Vector2, amount: number): Vector2; setTo(x: number, y: number): void; + negate(): Vector2; /** * * @param value @@ -598,18 +568,20 @@ declare module es { */ sub(value: Vector2): Vector2; subEqual(v: Vector2): Vector2; + dot(v: Vector2): number; /** * * @param size * @returns */ scale(size: number): Vector2; + scaleEqual(size: number): Vector2; + transform(matrix: Matrix2D): Vector2; + normalize(): Vector2; /** * 将这个Vector2变成一个方向相同的单位向量 */ - normalize(): this; - /** 返回它的长度 */ - length(): number; + normalizeEqual(): Vector2; magnitude(): number; distance(v?: Vector2): number; /** @@ -632,7 +604,7 @@ declare module es { * @param other 要比较的对象 * @returns 如果实例相同true 否则false */ - equals(other: Vector2 | object): boolean; + equals(other: Vector2, tolerance?: number): boolean; isValid(): boolean; /** * 创建一个新的Vector2,其中包含来自两个向量的最小值 @@ -1337,6 +1309,8 @@ declare module es { } declare module es { abstract class Collider extends Component { + static readonly lateSortOrder: number; + castSortOrder: number; /** * 对撞机的基本形状 */ @@ -2652,7 +2626,10 @@ declare module es { * 在这个过程中,t被修改为在曲线段的范围内。 * @param t */ - pointIndexAtTime(t: Ref): number; + pointIndexAtTime(t: number): { + time: number; + range: number; + }; /** * 设置一个控制点,考虑到这是否是一个共享点,如果是,则适当调整 * @param index @@ -3078,6 +3055,7 @@ declare module es { * @returns */ static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: any): number; + static fromAngle(angle: number): Vector2; } } declare module es { @@ -3139,6 +3117,8 @@ declare module es { * 返回标识矩阵 */ static readonly identity: Matrix2D; + setIdentity(): Matrix2D; + setValues(m11: number, m12: number, m21: number, m22: number, m31: number, m32: number): Matrix2D; /** * 储存在该矩阵中的位置 */ @@ -3155,35 +3135,25 @@ declare module es { * 储存在这个矩阵中的缩放 */ scale: Vector2; - /** - * 构建一个矩阵 - * @param m11 - * @param m12 - * @param m21 - * @param m22 - * @param m31 - * @param m32 - */ - constructor(m11: number, m12: number, m21: number, m22: number, m31: number, m32: number); /** * 创建一个新的围绕Z轴的旋转矩阵2D * @param radians */ - static createRotation(radians: number): Matrix2D; + static createRotation(radians: number, result: Matrix2D): void; static createRotationOut(radians: number, result: Matrix2D): void; /** * 创建一个新的缩放矩阵2D * @param xScale * @param yScale */ - static createScale(xScale: number, yScale: number): Matrix2D; + static createScale(xScale: number, yScale: number, result: Matrix2D): void; static createScaleOut(xScale: number, yScale: number, result: Matrix2D): void; /** * 创建一个新的平移矩阵2D * @param xPosition * @param yPosition */ - static createTranslation(xPosition: number, yPosition: number): Matrix2D; + static createTranslation(xPosition: number, yPosition: number, result: Matrix2D): Matrix2D; static createTranslationOut(position: Vector2, result: Matrix2D): void; static invert(matrix: Matrix2D): Matrix2D; /** @@ -3194,7 +3164,7 @@ declare module es { substract(matrix: Matrix2D): Matrix2D; divide(matrix: Matrix2D): Matrix2D; multiply(matrix: Matrix2D): Matrix2D; - static multiply(matrix1: Matrix2D, matrix2: Matrix2D, result: Matrix2D): Matrix2D; + static multiply(matrix1: Matrix2D, matrix2: Matrix2D, result: Matrix2D): void; determinant(): number; /** * 创建一个新的Matrix2D,包含指定矩阵中的线性插值。 @@ -3353,7 +3323,10 @@ declare module es { * @param value 另一个用于测试的矩形 */ intersects(value: Rectangle): boolean; - rayIntersects(ray: Ray2D, distance: Ref): boolean; + rayIntersects(ray: Ray2D): { + intersected: boolean; + distance: number; + }; /** * 获取所提供的矩形是否在此矩形的边界内 * @param value @@ -3558,9 +3531,8 @@ declare module es { */ centroid: Vector2; constructor(collider?: Collider, fraction?: number, distance?: number, point?: Vector2, normal?: Vector2); - setValues(collider: Collider, fraction: number, distance: number, point: Vector2): void; - setValuesNonCollider(fraction: number, distance: number, point: Vector2, normal: Vector2): void; setAllValues(collider: Collider, fraction: number, distance: number, point: Vector2, normal: Vector2): void; + setValues(fraction: number, distance: number, point: Vector2, normal: Vector2): void; reset(): void; clone(): RaycastHit; toString(): string; @@ -3662,8 +3634,7 @@ declare module es { * @param end * @param layerMask */ - static linecast(start: Vector2, end: Vector2, layerMask?: number): RaycastHit; - static linecastIgnoreCollider(start: Vector2, end: Vector2, layerMask?: number, ignoredColliders?: Set): RaycastHit; + static linecast(start: Vector2, end: Vector2, layerMask?: number, ignoredColliders?: Set): RaycastHit; /** * 通过空间散列强制执行一行,并用该行命中的任何碰撞器填充hits数组 * @param start @@ -3671,8 +3642,7 @@ declare module es { * @param hits * @param layerMask */ - static linecastAll(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask?: number): number; - static linecastAllIgnoreCollider(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask?: number, ignoredColliders?: Set): number; + static linecastAll(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask?: number, ignoredColliders?: Set): number; /** * 检查是否有对撞机落在一个矩形区域中 * @param rect @@ -3693,10 +3663,13 @@ declare module es { * 不是真正的射线(射线只有开始和方向),作为一条线和射线。 */ class Ray2D { - start: Vector2; - end: Vector2; - direction: Vector2; - constructor(position: Vector2, end: Vector2); + readonly start: Vector2; + readonly direction: Vector2; + readonly end: Vector2; + constructor(pos: Vector2, end: Vector2); + private _start; + private _direction; + private _end; } } declare module es { @@ -3762,8 +3735,7 @@ declare module es { * @param hits * @param layerMask */ - linecast(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask: number): number; - linecastIgnoreCollider(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask: number, ignoredColliders: Set): number; + linecast(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask: number, ignoredColliders: Set): number; /** * 获取所有在指定矩形范围内的碰撞器 * @param rect @@ -3819,8 +3791,7 @@ declare module es { _ray: Ray2D; _layerMask: number; private _ignoredColliders; - start(ray: Ray2D, hits: RaycastHit[], layerMask: number): void; - startIgnoreCollider(ray: Ray2D, hits: RaycastHit[], layerMask: number, ignoredColliders: Set): void; + start(ray: Ray2D, hits: RaycastHit[], layerMask: number, ignoredColliders: Set): void; /** * 如果hits数组被填充,返回true。单元格不能为空! * @param cellX @@ -3935,7 +3906,11 @@ declare module es { * @param distanceSquared * @param edgeNormal */ - static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Ref, edgeNormal: Vector2): Vector2; + static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { + distanceSquared: number; + edgeNormal: Vector2; + closestPoint: Vector2; + }; /** * 旋转原始点并复制旋转的值到旋转的点 * @param radians @@ -3991,6 +3966,7 @@ declare module es { overlaps(other: Shape): any; collidesWithShape(other: Shape, result: CollisionResult): boolean; collidesWithLine(start: Vector2, end: Vector2, hit: RaycastHit): boolean; + getPointAlongEdge(angle: number): Vector2; /** * 获取所提供的点是否在此范围内 * @param point @@ -4017,18 +3993,20 @@ declare module es { * 不是所有冲突类型都使用!在依赖这个字段之前,请检查ShapeCollisions切割类! */ point: Vector2; + reset(): void; + cloneTo(cr: CollisionResult): void; /** * 改变最小平移向量,如果没有相同方向上的运动,它将移除平移的x分量。 * @param deltaMovement */ - removeHorizontal(deltaMovement: Vector2): void; - invertResult(): this; + removeHorizontalTranslation(deltaMovement: Vector2): void; + invertResult(): void; toString(): string; } } declare module es { class RealtimeCollisions { - static intersectMovingCircleBox(s: Circle, b: Box, movement: Vector2, time: Ref): boolean; + static intersectMovingCircleBox(s: Circle, b: Box, movement: Vector2, time: number): boolean; /** * 支持函数,返回索引为n的矩形vert * @param b @@ -4060,6 +4038,7 @@ declare module es { } declare module es { class ShapeCollisionsCircle { + static circleToCircleCast(first: Circle, second: Circle, deltaMovement: Vector2, hit: RaycastHit): boolean; static circleToCircle(first: Circle, second: Circle, result?: CollisionResult): boolean; /** * 适用于中心在框内的圆,也适用于与框外中心重合的圆。 diff --git a/source/bin/framework.js b/source/bin/framework.js index 97a043ed..adb458f2 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -1174,70 +1174,13 @@ var es; result.y = value1.y / value2; return result; }; - /** - * - * @param value1 - * @param value2 - */ - Vector2.multiply = function (value1, value2) { - var result = es.Vector2.zero; - result.x = value1.x * value2.x; - result.y = value1.y * value2.y; - return result; - }; - /** - * - * @param value1 - * @param value2 - * @returns - */ - Vector2.multiplyScaler = function (value1, value2) { - var result = es.Vector2.zero; - result.x = value1.x * value2; - result.y = value1.y * value2; - return result; - }; - /** - * - * @param value1 - * @param value2 - */ - Vector2.subtract = function (value1, value2) { - var result = es.Vector2.zero; - result.x = value1.x - value2.x; - result.y = value1.y - value2.y; - return result; - }; - /** - * 创建一个新的Vector2 - * 它包含来自另一个向量的标准化值。 - * @param value - */ - Vector2.normalize = function (value) { - var d = value.distance(); - if (d > 0) { - return new Vector2(value.x / d, value.y / d); - } - else { - return new Vector2(0, 1); - } - }; - /** - * 返回两个向量的点积 - * @param value1 - * @param value2 - */ - Vector2.dot = function (value1, value2) { - return (value1.x * value2.x) + (value1.y * value2.y); - }; /** * 返回两个向量之间距离的平方 * @param value1 * @param value2 */ - Vector2.distanceSquared = function (value1, value2) { - var v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return (v1 * v1) + (v2 * v2); + Vector2.sqrDistance = function (value1, value2) { + return Math.pow(value1.x - value2.x, 2) + Math.pow(value1.y - value2.y, 2); }; /** * 将指定的值限制在一个范围内 @@ -1290,9 +1233,8 @@ var es; * @param value2 * @returns 两个向量之间的距离 */ - Vector2.distance = function (value1, value2) { - var v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return Math.sqrt((v1 * v1) + (v2 * v2)); + Vector2.distance = function (vec1, vec2) { + return Math.sqrt(Math.pow(vec1.x - vec2.x, 2) + Math.pow(vec1.y - vec2.y, 2)); }; /** * 返回两个向量之间的角度,单位是度数 @@ -1300,9 +1242,9 @@ var es; * @param to */ Vector2.angle = function (from, to) { - from = Vector2.normalize(from); - to = Vector2.normalize(to); - return Math.acos(es.MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * es.MathHelper.Rad2Deg; + from = from.normalize(); + to = to.normalize(); + return Math.acos(es.MathHelper.clamp(from.dot(to), -1, 1)) * es.MathHelper.Rad2Deg; }; /** * 创建一个包含指定向量反转的新Vector2 @@ -1341,6 +1283,9 @@ var es; this.x = x; this.y = y; }; + Vector2.prototype.negate = function () { + return this.scale(-1); + }; /** * * @param value @@ -1372,9 +1317,7 @@ var es; * @param value */ Vector2.prototype.multiply = function (value) { - this.x *= value.x; - this.y *= value.y; - return this; + return new Vector2(value.x * this.x, value.y * this.y); }; /** * @@ -1399,6 +1342,9 @@ var es; this.y -= v.y; return this; }; + Vector2.prototype.dot = function (v) { + return this.x * v.x + this.y * v.y; + }; /** * * @param size @@ -1407,10 +1353,27 @@ var es; Vector2.prototype.scale = function (size) { return new Vector2(this.x * size, this.y * size); }; + Vector2.prototype.scaleEqual = function (size) { + this.x *= size; + this.y *= size; + return this; + }; + Vector2.prototype.transform = function (matrix) { + return new Vector2(this.x * matrix.m11 + this.y * matrix.m21 + matrix.m31, this.x * matrix.m12 + this.y * matrix.m22 + matrix.m32); + }; + Vector2.prototype.normalize = function () { + var d = this.distance(); + if (d > 0) { + return new Vector2(this.x / d, this.y / d); + } + else { + return new Vector2(0, 1); + } + }; /** * 将这个Vector2变成一个方向相同的单位向量 */ - Vector2.prototype.normalize = function () { + Vector2.prototype.normalizeEqual = function () { var d = this.distance(); if (d > 0) { this.setTo(this.x / d, this.y / d); @@ -1421,10 +1384,6 @@ var es; return this; } }; - /** 返回它的长度 */ - Vector2.prototype.length = function () { - return Math.sqrt((this.x * this.x) + (this.y * this.y)); - }; Vector2.prototype.magnitude = function () { return this.distance(); }; @@ -1453,8 +1412,8 @@ var es; * @param right */ Vector2.prototype.angleBetween = function (left, right) { - var one = Vector2.subtract(left, this); - var two = Vector2.subtract(right, this); + var one = left.sub(this); + var two = right.sub(this); return es.Vector2Ext.angle(one, two); }; /** @@ -1462,11 +1421,9 @@ var es; * @param other 要比较的对象 * @returns 如果实例相同true 否则false */ - Vector2.prototype.equals = function (other) { - if (other instanceof Vector2) { - return other.x == this.x && other.y == this.y; - } - return false; + Vector2.prototype.equals = function (other, tolerance) { + if (tolerance === void 0) { tolerance = 0.001; } + return Math.abs(this.x - other.x) <= tolerance && Math.abs(this.y - other.y) <= tolerance; }; Vector2.prototype.isValid = function () { return es.MathHelper.isValid(this.x) && es.MathHelper.isValid(this.y); @@ -1503,9 +1460,9 @@ var es; }; Vector2.unsignedAngle = function (from, to, round) { if (round === void 0) { round = true; } - from.normalize(); - to.normalize(); - var angle = Math.acos(es.MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * es.MathHelper.Rad2Deg; + from.normalizeEqual(); + to.normalizeEqual(); + var angle = Math.acos(es.MathHelper.clamp(from.dot(to), -1, 1)) * es.MathHelper.Rad2Deg; return round ? Math.round(angle) : angle; }; Vector2.prototype.clone = function () { @@ -2103,8 +2060,8 @@ var es; */ Transform.prototype.lookAt = function (pos) { var sign = this.position.x > pos.x ? -1 : 1; - var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos)); - this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY)); + var vectorToAlignTo = this.position.sub(pos).normalize(); + this.rotation = sign * Math.acos(vectorToAlignTo.dot(es.Vector2.unitY)); }; /** * 相对于父变换的旋转设置变换的旋转。如果转换没有父元素,则与transform.rotation相同 @@ -2159,15 +2116,15 @@ var es; this.parent.updateTransform(); if (this._localDirty) { if (this._localPositionDirty) { - this._translationMatrix = es.Matrix2D.createTranslation(this._localPosition.x, this._localPosition.y); + es.Matrix2D.createTranslation(this._localPosition.x, this._localPosition.y, this._translationMatrix); this._localPositionDirty = false; } if (this._localRotationDirty) { - this._rotationMatrix = es.Matrix2D.createRotation(this._localRotation); + es.Matrix2D.createRotation(this._localRotation, this._rotationMatrix); this._localRotationDirty = false; } if (this._localScaleDirty) { - this._scaleMatrix = es.Matrix2D.createScale(this._localScale.x, this._localScale.y); + es.Matrix2D.createScale(this._localScale.x, this._localScale.y, this._scaleMatrix); this._localScaleDirty = false; } es.Matrix2D.multiply(this._scaleMatrix, this._rotationMatrix, this._localTransform); @@ -2183,7 +2140,8 @@ var es; if (this.parent != null) { es.Matrix2D.multiply(this._localTransform, this.parent._worldTransform, this._worldTransform); this._rotation = this._localRotation + this.parent._rotation; - this._scale = es.Vector2.multiply(this.parent._scale, this._localScale); + this._scale = this.parent._scale.multiply(this._localScale); + ; this._worldInverseDirty = true; } this._worldToLocalDirty = true; @@ -2195,13 +2153,13 @@ var es; if ((this.hierarchyDirty & dirtyFlagType) == 0) { this.hierarchyDirty |= dirtyFlagType; switch (dirtyFlagType) { - case es.DirtyType.positionDirty: + case DirtyType.positionDirty: this.entity.onTransformChanged(transform.Component.position); break; - case es.DirtyType.rotationDirty: + case DirtyType.rotationDirty: this.entity.onTransformChanged(transform.Component.rotation); break; - case es.DirtyType.scaleDirty: + case DirtyType.scaleDirty: this.entity.onTransformChanged(transform.Component.scale); break; } @@ -2464,8 +2422,7 @@ var es; */ ArcadeRigidbody.prototype.addImpulse = function (force) { if (!this.isImmovable) { - this.velocity = es.Vector2.add(this.velocity, es.Vector2.multiplyScaler(force, 100000) - .multiplyScaler(this._inverseMass * es.Time.deltaTime * es.Time.deltaTime)); + this.velocity.addEqual(force.scale(100000 * (this._inverseMass * (es.Time.deltaTime * es.Time.deltaTime)))); } }; ArcadeRigidbody.prototype.onAddedToEntity = function () { @@ -2487,7 +2444,7 @@ var es; } if (this.shouldUseGravity) this.velocity.addEqual(es.Physics.gravity.scale(es.Time.deltaTime)); - this.entity.position = es.Vector2.add(this.entity.position, es.Vector2.multiplyScaler(this.velocity, es.Time.deltaTime)); + this.entity.position = this.entity.position.add(this.velocity.scale(es.Time.deltaTime)); var collisionResult = new es.CollisionResult(); // 捞取我们在新的位置上可能会碰撞到的任何东西 var neighbors = es.Physics.boxcastBroadphaseExcludingSelf(this._collider, this._collider.bounds, this._collider.collidesWithLayers.value); @@ -2509,7 +2466,7 @@ var es; } else { // 没有ArcadeRigidbody,所以我们假设它是不动的,只移动我们自己的 - this.entity.position = es.Vector2.subtract(this.entity.position, collisionResult.minimumTranslationVector); + this.entity.position = this.entity.position.sub(collisionResult.minimumTranslationVector); var relativeVelocity = this.calculateResponseVelocity(this.velocity, collisionResult.minimumTranslationVector); this.velocity.addEqual(relativeVelocity); } @@ -2550,14 +2507,14 @@ var es; // 我们计算两个相撞物体的响应。 // 计算的基础是沿碰撞表面法线反射的物体的相对速度。 // 然后,响应的一部分会根据质量加到每个物体上 - var relativeVelocity = es.Vector2.subtract(this.velocity, other.velocity); + var relativeVelocity = this.velocity.sub(other.velocity); relativeVelocity = this.calculateResponseVelocity(relativeVelocity, minimumTranslationVector); // 现在,我们使用质量来线性缩放两个刚体上的响应 var totalinverseMass = this._inverseMass + other._inverseMass; var ourResponseFraction = this._inverseMass / totalinverseMass; var otherResponseFraction = other._inverseMass / totalinverseMass; - this.velocity = es.Vector2.add(this.velocity, relativeVelocity.scale(ourResponseFraction)); - other.velocity = es.Vector2.subtract(other.velocity, relativeVelocity.scale(otherResponseFraction)); + this.velocity = this.velocity.add(relativeVelocity.scale(ourResponseFraction)); + other.velocity = other.velocity.sub(relativeVelocity.scale(otherResponseFraction)); }; /** * 给定两个物体和MTV之间的相对速度,本方法修改相对速度,使其成为碰撞响应 @@ -2567,13 +2524,13 @@ var es; */ ArcadeRigidbody.prototype.calculateResponseVelocity = function (relativeVelocity, minimumTranslationVector) { // 首先,我们得到反方向的归一化MTV:表面法线 - var inverseMTV = es.Vector2.multiplyScaler(minimumTranslationVector, -1); - var normal = es.Vector2.normalize(inverseMTV); + var inverseMTV = minimumTranslationVector.scale(-1); + var normal = inverseMTV.normalize(); // 速度是沿碰撞法线和碰撞平面分解的。 // 弹性将影响沿法线的响应(法线速度分量),摩擦力将影响速度的切向分量(切向速度分量) - var n = es.Vector2.dot(relativeVelocity, normal); - var normalVelocityComponent = es.Vector2.multiplyScaler(normal, n); - var tangentialVelocityComponent = es.Vector2.subtract(relativeVelocity, normalVelocityComponent); + var n = relativeVelocity.dot(normal); + var normalVelocityComponent = normal.scale(n); + var tangentialVelocityComponent = relativeVelocity.sub(normalVelocityComponent); if (n > 0) normalVelocityComponent = es.Vector2.zero; // 如果切向分量的平方幅度小于glue,那么我们就把摩擦力提升到最大 @@ -2844,10 +2801,10 @@ var es; if (i === 0 && this.supportSlopedOneWayPlatforms && this.collisionState.wasGroundedLastFrame) { - this._raycastHit = es.Physics.linecastIgnoreCollider(ray, ray.add(rayDirection.multiplyScaler(rayDistance)), this.platformMask, this.ignoredColliders); + this._raycastHit = es.Physics.linecast(ray, ray.add(rayDirection.scaleEqual(rayDistance)), this.platformMask, this.ignoredColliders); } else { - this._raycastHit = es.Physics.linecastIgnoreCollider(ray, ray.add(rayDirection.multiplyScaler(rayDistance)), this.platformMask & ~this.oneWayPlatformMask, this.ignoredColliders); + this._raycastHit = es.Physics.linecast(ray, ray.add(rayDirection.scaleEqual(rayDistance)), this.platformMask & ~this.oneWayPlatformMask, this.ignoredColliders); } if (this._raycastHit.collider) { if (i === 0 && @@ -2893,7 +2850,7 @@ var es; } for (var i = 0; i < this.totalVerticalRays; i++) { var rayStart = new es.Vector2(initialRayOriginX + i * this._horizontalDistanceBetweenRays, initialRayOriginY); - this._raycastHit = es.Physics.linecastIgnoreCollider(rayStart, rayStart.add(rayDirection.multiplyScaler(rayDistance)), mask, this.ignoredColliders); + this._raycastHit = es.Physics.linecast(rayStart, rayStart.add(rayDirection.scaleEqual(rayDistance)), mask, this.ignoredColliders); if (this._raycastHit.collider) { deltaMovement.y = this._raycastHit.point.y - rayStart.y; rayDistance = Math.abs(deltaMovement.y); @@ -2932,7 +2889,7 @@ var es; var slopeCheckRayDistance = this._slopeLimitTangent * (this._raycastOrigins.bottomRight.x - centerOfCollider); var slopeRay = new es.Vector2(centerOfCollider, this._raycastOrigins.bottomLeft.y); - this._raycastHit = es.Physics.linecastIgnoreCollider(slopeRay, slopeRay.add(rayDirection.multiplyScaler(slopeCheckRayDistance)), this.platformMask, this.ignoredColliders); + this._raycastHit = es.Physics.linecast(slopeRay, slopeRay.add(rayDirection.scaleEqual(slopeCheckRayDistance)), this.platformMask, this.ignoredColliders); if (this._raycastHit.collider) { var angle = es.Vector2.unsignedAngle(this._raycastHit.normal, es.Vector2.up); if (angle === 0) { @@ -2976,10 +2933,10 @@ var es; var raycastHit = null; if (this.supportSlopedOneWayPlatforms && this.collisionState.wasGroundedLastFrame) { - raycastHit = es.Physics.linecastIgnoreCollider(ray, ray.add(deltaMovement), this.platformMask, this.ignoredColliders); + raycastHit = es.Physics.linecast(ray, ray.add(deltaMovement), this.platformMask, this.ignoredColliders); } else { - raycastHit = es.Physics.linecastIgnoreCollider(ray, ray.add(deltaMovement), this.platformMask & ~this.oneWayPlatformMask, this.ignoredColliders); + raycastHit = es.Physics.linecast(ray, ray.add(deltaMovement), this.platformMask & ~this.oneWayPlatformMask, this.ignoredColliders); } if (raycastHit.collider) { deltaMovement.x = raycastHit.point.x - ray.x; @@ -3228,6 +3185,7 @@ var es; __extends(Collider, _super); function Collider() { var _this = _super !== null && _super.apply(this, arguments) || this; + _this.castSortOrder = 0; /** * 如果这个碰撞器是一个触发器,它将不会引起碰撞,但它仍然会触发事件 */ @@ -3347,12 +3305,12 @@ var es; var height = renderableBounds.height / this.entity.transform.scale.y; if (this instanceof es.CircleCollider) { this.radius = Math.max(width, height) * 0.5; - this.localOffset = es.Vector2.subtract(renderableBounds.center, this.entity.transform.position); + this.localOffset = renderableBounds.center.sub(this.entity.transform.position); } else if (this instanceof es.BoxCollider) { this.width = width; this.height = height; - this.localOffset = es.Vector2.subtract(renderableBounds.center, this.entity.transform.position); + this.localOffset = renderableBounds.center.sub(this.entity.transform.position); } } } @@ -3466,8 +3424,8 @@ var es; if (neighbor.isTrigger) continue; if (this.collidesWithNonMotion(neighbor, result)) { - motion = es.Vector2.subtract(motion, result.minimumTranslationVector); - this.shape.position = es.Vector2.subtract(this.shape.position, result.minimumTranslationVector); + motion = motion.sub(result.minimumTranslationVector); + this.shape.position = this.shape.position.sub(result.minimumTranslationVector); didCollide = true; } } @@ -3510,6 +3468,7 @@ var es; } return false; }; + Collider.lateSortOrder = 999; return Collider; }(es.Component)); es.Collider = Collider; @@ -6509,8 +6468,8 @@ var es; * @param t */ Bezier.getFirstDerivative = function (p0, p1, p2, t) { - return new es.Vector2(2 * (1 - t)).multiply(es.Vector2.subtract(p1, p0)) - .addEqual(new es.Vector2(2 * t).multiply(es.Vector2.subtract(p2, p1))); + return p1.sub(p0).scale(2 * (1 - t)) + .addEqual(p2.sub(p1).scale(2 * t)); }; /** * 得到一个三次贝塞尔函数的一阶导数 @@ -6523,9 +6482,9 @@ var es; Bezier.getFirstDerivativeThree = function (start, firstControlPoint, secondControlPoint, end, t) { t = es.MathHelper.clamp01(t); var oneMunusT = 1 - t; - return new es.Vector2(3 * oneMunusT * oneMunusT).multiply(es.Vector2.subtract(firstControlPoint, start)) - .addEqual(new es.Vector2(6 * oneMunusT * t).multiply(es.Vector2.subtract(secondControlPoint, firstControlPoint))) - .addEqual(new es.Vector2(3 * t * t).multiply(es.Vector2.subtract(end, secondControlPoint))); + return firstControlPoint.sub(start).scale(3 * oneMunusT * oneMunusT) + .addEqual(secondControlPoint.sub(firstControlPoint).scale(6 * oneMunusT * t)) + .addEqual(end.sub(secondControlPoint).scale(3 * t * t)); }; /** * 递归地细分bezier曲线,直到满足距离校正 @@ -6555,16 +6514,16 @@ var es; */ Bezier.recursiveGetOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance) { // 计算线段的所有中点 - var pt12 = es.Vector2.divideScaler(es.Vector2.add(start, firstCtrlPoint), 2); - var pt23 = es.Vector2.divideScaler(es.Vector2.add(firstCtrlPoint, secondCtrlPoint), 2); - var pt34 = es.Vector2.divideScaler(es.Vector2.add(secondCtrlPoint, end), 2); + var pt12 = es.Vector2.divideScaler(start.add(firstCtrlPoint), 2); + var pt23 = es.Vector2.divideScaler(firstCtrlPoint.add(secondCtrlPoint), 2); + var pt34 = es.Vector2.divideScaler(secondCtrlPoint.add(end), 2); // 计算新半直线的中点 - var pt123 = es.Vector2.divideScaler(es.Vector2.add(pt12, pt23), 2); - var pt234 = es.Vector2.divideScaler(es.Vector2.add(pt23, pt34), 2); + var pt123 = es.Vector2.divideScaler(pt12.add(pt23), 2); + var pt234 = es.Vector2.divideScaler(pt23.add(pt34), 2); // 最后再细分最后两个中点。如果我们满足我们的距离公差,这将是我们使用的最后一点。 - var pt1234 = es.Vector2.divideScaler(es.Vector2.add(pt123, pt234), 2); + var pt1234 = es.Vector2.divideScaler(pt123.add(pt234), 2); // 试着用一条直线来近似整个三次曲线 - var deltaLine = es.Vector2.subtract(end, start); + var deltaLine = end.sub(start); var d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x)); var d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x)); if ((d2 + d3) * (d2 + d3) < distanceTolerance * (deltaLine.x * deltaLine.x + deltaLine.y * deltaLine.y)) { @@ -6594,18 +6553,19 @@ var es; * @param t */ BezierSpline.prototype.pointIndexAtTime = function (t) { - var i = 0; - if (t.value >= 1) { - t.value = 1; - i = this._points.length - 4; + var res = { time: 0, range: 0 }; + if (t >= 1) { + t = 1; + res.range = this._points.length - 4; } else { - t.value = es.MathHelper.clamp01(t.value) * this._curveCount; - i = ~~t; - t.value -= i; - i *= 3; + t = es.MathHelper.clamp01(t) * this._curveCount; + res.range = Math.floor(t); + t -= res.range; + res.range *= 3; } - return i; + res.time = t; + return res; }; /** * 设置一个控制点,考虑到这是否是一个共享点,如果是,则适当调整 @@ -6614,7 +6574,7 @@ var es; */ BezierSpline.prototype.setControlPoint = function (index, point) { if (index % 3 == 0) { - var delta = es.Vector2.subtract(point, this._points[index]); + var delta = point.sub(this._points[index]); if (index > 0) this._points[index - 1].addEqual(delta); if (index + 1 < this._points.length) @@ -6627,7 +6587,8 @@ var es; * @param t */ BezierSpline.prototype.getPointAtTime = function (t) { - var i = this.pointIndexAtTime(new es.Ref(t)); + var res = this.pointIndexAtTime(t); + var i = res.range; return es.Bezier.getPointThree(this._points[i], this._points[i + 1], this._points[i + 2], this._points[i + 3], t); }; /** @@ -6635,7 +6596,8 @@ var es; * @param t */ BezierSpline.prototype.getVelocityAtTime = function (t) { - var i = this.pointIndexAtTime(new es.Ref(t)); + var res = this.pointIndexAtTime(t); + var i = res.range; return es.Bezier.getFirstDerivativeThree(this._points[i], this._points[i + 1], this._points[i + 2], this._points[i + 3], t); }; /** @@ -6643,7 +6605,7 @@ var es; * @param t */ BezierSpline.prototype.getDirectionAtTime = function (t) { - return es.Vector2.normalize(this.getVelocityAtTime(t)); + return this.getVelocityAtTime(t).normalize(); }; /** * 在贝塞尔曲线上添加一条曲线 @@ -7087,8 +7049,8 @@ var es; * @param other */ MathHelper.project = function (self, other) { - var amt = es.Vector2.dot(self, other) / other.lengthSquared(); - var vec = new es.Vector2(amt * other.x, amt * other.y); + var amt = self.dot(other) / other.lengthSquared(); + var vec = other.scale(amt); return vec; }; /** @@ -7287,7 +7249,7 @@ var es; if (Number.isNaN(x)) { return false; } - return !Number.isFinite(x); + return x !== Infinity; }; MathHelper.smoothDamp = function (current, target, currentVelocity, smoothTime, maxSpeed, deltaTime) { smoothTime = Math.max(0.0001, smoothTime); @@ -7331,6 +7293,9 @@ var es; MathHelper.mapMinMax = function (value, leftMin, leftMax, rightMin, rightMax) { return rightMin + ((MathHelper.clamp(value, leftMin, leftMax) - leftMin) * (rightMax - rightMin)) / (leftMax - leftMin); }; + MathHelper.fromAngle = function (angle) { + return new es.Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual(); + }; MathHelper.Epsilon = 0.00001; MathHelper.Rad2Deg = 57.29578; MathHelper.Deg2Rad = 0.0174532924; @@ -7479,39 +7444,36 @@ var es; * 表示右手3 * 3的浮点矩阵,可以存储平移、缩放和旋转信息。 */ var Matrix2D = /** @class */ (function () { - /** - * 构建一个矩阵 - * @param m11 - * @param m12 - * @param m21 - * @param m22 - * @param m31 - * @param m32 - */ - function Matrix2D(m11, m12, m21, m22, m31, m32) { + function Matrix2D() { this.m11 = 0; // x 缩放 this.m12 = 0; this.m21 = 0; this.m22 = 0; this.m31 = 0; this.m32 = 0; - this.m11 = m11; - this.m12 = m12; - this.m21 = m21; - this.m22 = m22; - this.m31 = m31; - this.m32 = m32; } Object.defineProperty(Matrix2D, "identity", { /** * 返回标识矩阵 */ get: function () { - return new Matrix2D(1, 0, 0, 1, 0, 0); + return new Matrix2D().setIdentity(); }, enumerable: true, configurable: true }); + Matrix2D.prototype.setIdentity = function () { + return this.setValues(1, 0, 0, 1, 0, 0); + }; + Matrix2D.prototype.setValues = function (m11, m12, m21, m22, m31, m32) { + this.m11 = m11; + this.m12 = m12; + this.m21 = m21; + this.m22 = m22; + this.m31 = m31; + this.m32 = m32; + return this; + }; Object.defineProperty(Matrix2D.prototype, "translation", { /** * 储存在该矩阵中的位置 @@ -7575,15 +7537,14 @@ var es; * 创建一个新的围绕Z轴的旋转矩阵2D * @param radians */ - Matrix2D.createRotation = function (radians) { - var result = this.identity; + Matrix2D.createRotation = function (radians, result) { + result.setIdentity(); var val1 = Math.cos(radians); var val2 = Math.sin(radians); result.m11 = val1; result.m12 = val2; - result.m21 = -val2; + result.m21 = val2 * -1; result.m22 = val1; - return result; }; Matrix2D.createRotationOut = function (radians, result) { var val1 = Math.cos(radians); @@ -7598,15 +7559,13 @@ var es; * @param xScale * @param yScale */ - Matrix2D.createScale = function (xScale, yScale) { - var result = this.identity; + Matrix2D.createScale = function (xScale, yScale, result) { result.m11 = xScale; result.m12 = 0; result.m21 = 0; result.m22 = yScale; result.m31 = 0; result.m32 = 0; - return result; }; Matrix2D.createScaleOut = function (xScale, yScale, result) { result.m11 = xScale; @@ -7621,8 +7580,7 @@ var es; * @param xPosition * @param yPosition */ - Matrix2D.createTranslation = function (xPosition, yPosition) { - var result = this.identity; + Matrix2D.createTranslation = function (xPosition, yPosition, result) { result.m11 = 1; result.m12 = 0; result.m21 = 0; @@ -7709,7 +7667,6 @@ var es; result.m22 = m22; result.m31 = m31; result.m32 = m32; - return result; }; Matrix2D.prototype.determinant = function () { return this.m11 * this.m22 - this.m12 * this.m21; @@ -7744,7 +7701,8 @@ var es; return ret; }; Matrix2D.prototype.mutiplyTranslation = function (x, y) { - var trans = Matrix2D.createTranslation(x, y); + var trans = new Matrix2D(); + Matrix2D.createTranslation(x, y, trans); return es.MatrixHelper.mutiply(this, trans); }; /** @@ -7897,6 +7855,9 @@ var es; * 该矩形的高度 */ this.height = 0; + // temp 用于计算边界的矩阵 + this._tempMat = new es.Matrix2D(); + this._transformMat = new es.Matrix2D(); this.x = x; this.y = y; this.width = width; @@ -8097,12 +8058,12 @@ var es; value.top < this.bottom && this.top < value.bottom; }; - Rectangle.prototype.rayIntersects = function (ray, distance) { - distance.value = 0; + Rectangle.prototype.rayIntersects = function (ray) { + var res = { intersected: false, distance: 0 }; var maxValue = Number.MAX_VALUE; if (Math.abs(ray.direction.x) < 1E-06) { if ((ray.start.x < this.x) || (ray.start.x > this.x + this.width)) - return false; + return res; } else { var num11 = 1 / ray.direction.x; @@ -8113,14 +8074,14 @@ var es; num8 = num7; num7 = num14; } - distance.value = Math.max(num8, distance.value); + res.distance = Math.max(num8, res.distance); maxValue = Math.min(num7, maxValue); - if (distance.value > maxValue) - return false; + if (res.distance > maxValue) + return res; } - if (Math.abs(ray.direction.y) < 1E-06) { + if (Math.abs(ray.direction.y) < 1e-06) { if ((ray.start.y < this.y) || (ray.start.y > this.y + this.height)) - return false; + return res; } else { var num10 = 1 / ray.direction.y; @@ -8131,12 +8092,13 @@ var es; num6 = num5; num5 = num13; } - distance.value = Math.max(num6, distance.value); + res.distance = Math.max(num6, res.distance); maxValue = Math.max(num5, maxValue); - if (distance.value > maxValue) - return false; + if (res.distance > maxValue) + return res; } - return true; + res.intersected = true; + return res; }; /** * 获取所提供的矩形是否在此矩形的边界内 @@ -8288,12 +8250,12 @@ var es; var worldPosX = parentPosition.x + position.x; var worldPosY = parentPosition.y + position.y; // 考虑到原点,将参考点设置为世界参考 - this._transformMat = es.Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y); - this._tempMat = es.Matrix2D.createScale(scale.x, scale.y); + es.Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y, this._transformMat); + es.Matrix2D.createScale(scale.x, scale.y, this._tempMat); this._transformMat = this._transformMat.multiply(this._tempMat); - this._tempMat = es.Matrix2D.createRotation(rotation); + es.Matrix2D.createRotation(rotation, this._tempMat); this._transformMat = this._transformMat.multiply(this._tempMat); - this._tempMat = es.Matrix2D.createTranslation(worldPosX, worldPosY); + es.Matrix2D.createTranslation(worldPosX, worldPosY, this._tempMat); this._transformMat = this._transformMat.multiply(this._tempMat); // TODO: 我们可以把世界变换留在矩阵中,避免在世界空间中得到所有的四个角 var topLeft = new es.Vector2(worldPosX, worldPosY); @@ -8484,12 +8446,14 @@ var es; * 它将处理任何与Collider重叠的ITriggerListeners。 */ ColliderTriggerHelper.prototype.update = function () { + var e_9, _a; + var lateColliders = []; // 对所有实体.colliders进行重叠检查,这些实体.colliders是触发器,与所有宽相碰撞器,无论是否触发器。 // 任何重叠都会导致触发事件 var colliders = this._entity.getComponents(es.Collider); for (var i = 0; i < colliders.length; i++) { var collider = colliders[i]; - var neighbors = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); + var neighbors = es.Physics.boxcastBroadphaseExcludingSelf(collider.bounds, collider.collidesWithLayers); for (var j = 0; j < neighbors.length; j++) { var neighbor = neighbors[j]; // 我们至少需要一个碰撞器作为触发器 @@ -8500,13 +8464,31 @@ var es; // 如果我们的某一个集合中已经有了这个对子(前一个或当前的触发交叉点),就不要调用输入事件了 var shouldReportTriggerEvent = !this._activeTriggerIntersections.contains(pair) && !this._previousTriggerIntersections.contains(pair); - if (shouldReportTriggerEvent) - this.notifyTriggerListeners(pair, true); + if (shouldReportTriggerEvent) { + if (neighbor.castSortOrder >= es.Collider.lateSortOrder) { + lateColliders.push(pair); + } + else { + this.notifyTriggerListeners(pair, true); + } + } this._activeTriggerIntersections.add(pair); } } } - es.ListPool.free(colliders); + try { + for (var lateColliders_1 = __values(lateColliders), lateColliders_1_1 = lateColliders_1.next(); !lateColliders_1_1.done; lateColliders_1_1 = lateColliders_1.next()) { + var pair = lateColliders_1_1.value; + this.notifyTriggerListeners(pair, true); + } + } + catch (e_9_1) { e_9 = { error: e_9_1 }; } + finally { + try { + if (lateColliders_1_1 && !lateColliders_1_1.done && (_a = lateColliders_1.return)) _a.call(lateColliders_1); + } + finally { if (e_9) throw e_9.error; } + } this.checkForExitedColliders(); }; ColliderTriggerHelper.prototype.checkForExitedColliders = function () { @@ -8567,58 +8549,60 @@ var es; function Collisions() { } Collisions.lineToLine = function (a1, a2, b1, b2) { - var b = es.Vector2.subtract(a2, a1); - var d = es.Vector2.subtract(b2, b1); + var b = a2.sub(a1); + var d = b2.sub(b1); var bDotDPerp = b.x * d.y - b.y * d.x; // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 if (bDotDPerp == 0) return false; - var c = es.Vector2.subtract(b1, a1); + var c = b1.sub(a1); var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) + if (t < 0 || t > 1) { return false; + } var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) + if (u < 0 || u > 1) { return false; + } return true; }; Collisions.lineToLineIntersection = function (a1, a2, b1, b2, intersection) { if (intersection === void 0) { intersection = es.Vector2.zero; } intersection.x = 0; intersection.y = 0; - var b = es.Vector2.subtract(a2, a1); - var d = es.Vector2.subtract(b2, b1); + var b = a2.sub(a1); + var d = b2.sub(b1); var bDotDPerp = b.x * d.y - b.y * d.x; // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 if (bDotDPerp == 0) return false; - var c = es.Vector2.subtract(b1, a1); + var c = b1.sub(a1); var t = (c.x * d.y - c.y * d.x) / bDotDPerp; if (t < 0 || t > 1) return false; var u = (c.x * b.y - c.y * b.x) / bDotDPerp; if (u < 0 || u > 1) return false; - var temp = es.Vector2.add(a1, new es.Vector2(t * b.x, t * b.y)); + var temp = a1.add(b.scale(t)); intersection.x = temp.x; intersection.y = temp.y; return true; }; Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = es.Vector2.subtract(lineB, lineA); - var w = es.Vector2.subtract(closestTo, lineA); - var t = es.Vector2.dot(w, v) / es.Vector2.dot(v, v); + var v = lineB.sub(lineA); + var w = closestTo.sub(lineA); + var t = w.dot(v) / v.dot(v); t = es.MathHelper.clamp(t, 0, 1); - return es.Vector2.add(lineA, new es.Vector2(v.x * t, v.y * t)); + return lineA.add(v.scale(t)); }; Collisions.circleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) { - return es.Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); + return es.Vector2.sqrDistance(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); }; Collisions.circleToLine = function (circleCenter, radius, lineFrom, lineTo) { - return es.Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; + return es.Vector2.sqrDistance(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; }; Collisions.circleToPoint = function (circleCenter, radius, point) { - return es.Vector2.distanceSquared(circleCenter, point) < radius * radius; + return es.Vector2.sqrDistance(circleCenter, point) < radius * radius; }; Collisions.rectToCircle = function (rect, cPosition, cRadius) { // 检查矩形是否包含圆的中心点 @@ -8628,25 +8612,25 @@ var es; var edgeFrom; var edgeTo; var sector = this.getSector(rect.x, rect.y, rect.width, rect.height, cPosition); - if ((sector & PointSectors.top) != 0) { + if ((sector & PointSectors.top) !== 0) { edgeFrom = new es.Vector2(rect.x, rect.y); edgeTo = new es.Vector2(rect.x + rect.width, rect.y); if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo)) return true; } - if ((sector & PointSectors.bottom) != 0) { + if ((sector & PointSectors.bottom) !== 0) { edgeFrom = new es.Vector2(rect.x, rect.y + rect.width); edgeTo = new es.Vector2(rect.x + rect.width, rect.y + rect.height); if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo)) return true; } - if ((sector & PointSectors.left) != 0) { + if ((sector & PointSectors.left) !== 0) { edgeFrom = new es.Vector2(rect.x, rect.y); edgeTo = new es.Vector2(rect.x, rect.y + rect.height); if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo)) return true; } - if ((sector & PointSectors.right) != 0) { + if ((sector & PointSectors.right) !== 0) { edgeFrom = new es.Vector2(rect.x + rect.width, rect.y); edgeTo = new es.Vector2(rect.x + rect.width, rect.y + rect.height); if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo)) @@ -8753,20 +8737,14 @@ var es; this.point = point; this.centroid = es.Vector2.zero; } - RaycastHit.prototype.setValues = function (collider, fraction, distance, point) { + RaycastHit.prototype.setAllValues = function (collider, fraction, distance, point, normal) { this.collider = collider; this.fraction = fraction; this.distance = distance; this.point = point; - }; - RaycastHit.prototype.setValuesNonCollider = function (fraction, distance, point, normal) { - this.fraction = fraction; - this.distance = distance; - this.point = point; this.normal = normal; }; - RaycastHit.prototype.setAllValues = function (collider, fraction, distance, point, normal) { - this.collider = collider; + RaycastHit.prototype.setValues = function (fraction, distance, point, normal) { this.fraction = fraction; this.distance = distance; this.point = point; @@ -8908,17 +8886,13 @@ var es; * @param end * @param layerMask */ - Physics.linecast = function (start, end, layerMask) { - if (layerMask === void 0) { layerMask = Physics.allLayers; } - this._hitArray[0].reset(); - this.linecastAll(start, end, this._hitArray, layerMask); - return this._hitArray[0]; - }; - Physics.linecastIgnoreCollider = function (start, end, layerMask, ignoredColliders) { + Physics.linecast = function (start, end, layerMask, ignoredColliders) { if (layerMask === void 0) { layerMask = this.allLayers; } if (ignoredColliders === void 0) { ignoredColliders = null; } this._hitArray[0].reset(); - Physics.linecastAllIgnoreCollider(start, end, this._hitArray, layerMask, ignoredColliders); + this.linecastAll(start, end, this._hitArray, layerMask); + this._hitArray[0].reset(); + Physics.linecastAll(start, end, this._hitArray, layerMask, ignoredColliders); return this._hitArray[0].clone(); }; /** @@ -8928,18 +8902,10 @@ var es; * @param hits * @param layerMask */ - Physics.linecastAll = function (start, end, hits, layerMask) { - if (layerMask === void 0) { layerMask = Physics.allLayers; } - if (hits.length == 0) { - console.warn("传入了一个空的hits数组。没有点击会被返回"); - return 0; - } - return this._spatialHash.linecast(start, end, hits, layerMask); - }; - Physics.linecastAllIgnoreCollider = function (start, end, hits, layerMask, ignoredColliders) { + Physics.linecastAll = function (start, end, hits, layerMask, ignoredColliders) { if (layerMask === void 0) { layerMask = this.allLayers; } if (ignoredColliders === void 0) { ignoredColliders = null; } - return this._spatialHash.linecastIgnoreCollider(start, end, hits, layerMask, ignoredColliders); + return this._spatialHash.linecast(start, end, hits, layerMask, ignoredColliders); }; /** * 检查是否有对撞机落在一个矩形区域中 @@ -9003,11 +8969,32 @@ var es; * 不是真正的射线(射线只有开始和方向),作为一条线和射线。 */ var Ray2D = /** @class */ (function () { - function Ray2D(position, end) { - this.start = position; - this.end = end; - this.direction = es.Vector2.subtract(this.end, this.start); + function Ray2D(pos, end) { + this._start = pos.clone(); + this._end = end.clone(); + this._direction = this._end.sub(this._start); } + Object.defineProperty(Ray2D.prototype, "start", { + get: function () { + return this._start; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Ray2D.prototype, "direction", { + get: function () { + return this._direction; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Ray2D.prototype, "end", { + get: function () { + return this._end; + }, + enumerable: true, + configurable: true + }); return Ray2D; }()); es.Ray2D = Ray2D; @@ -9142,9 +9129,9 @@ var es; * @param hits * @param layerMask */ - SpatialHash.prototype.linecast = function (start, end, hits, layerMask) { + SpatialHash.prototype.linecast = function (start, end, hits, layerMask, ignoredColliders) { var ray = new es.Ray2D(start, end); - this._raycastParser.start(ray, hits, layerMask); + this._raycastParser.start(ray, hits, layerMask, ignoredColliders); // 获取我们的起始/结束位置,与我们的网格在同一空间内 var currentCell = this.cellCoords(start.x, start.y); var lastCell = this.cellCoords(end.x, end.y); @@ -9194,60 +9181,6 @@ var es; this._raycastParser.reset(); return this._raycastParser.hitCounter; }; - SpatialHash.prototype.linecastIgnoreCollider = function (start, end, hits, layerMask, ignoredColliders) { - start = start.clone(); - var ray = new es.Ray2D(start, end); - this._raycastParser.startIgnoreCollider(ray, hits, layerMask, ignoredColliders); - start.x = start.x * this._inverseCellSize; - start.y = start.y * this._inverseCellSize; - var endCell = this.cellCoords(end.x, end.y); - var intX = Math.floor(start.x); - var intY = Math.floor(start.y); - var stepX = Math.sign(ray.direction.x); - var stepY = Math.sign(ray.direction.y); - if (intX === endCell.x) { - stepX = 0; - } - if (intY === endCell.y) { - stepY = 0; - } - var boundaryX = intX + (stepX > 0 ? 1 : 0); - var boundaryY = intY + (stepY > 0 ? 1 : 0); - var tMaxX = (boundaryX - start.x) / ray.direction.x; - var tMaxY = (boundaryY - start.y) / ray.direction.y; - if (ray.direction.x === 0 || stepX === 0) { - tMaxX = Number.POSITIVE_INFINITY; - } - if (ray.direction.y === 0 || stepY === 0) { - tMaxY = Number.POSITIVE_INFINITY; - } - var tDeltaX = stepX / ray.direction.x; - var tDeltaY = stepY / ray.direction.y; - var cell = this.cellAtPosition(intX, intY); - if (cell && this._raycastParser.checkRayIntersection(intX, intY, cell)) { - this._raycastParser.reset(); - return this._raycastParser.hitCounter; - } - var n = 0; - while ((intX !== endCell.x || intY !== endCell.y) && n < 100) { - if (tMaxX < tMaxY) { - intX = intX + stepX; - tMaxX = tMaxX + tDeltaX; - } - else { - intY = intY + stepY; - tMaxY = tMaxY + tDeltaY; - } - cell = this.cellAtPosition(intX, intY); - if (cell && this._raycastParser.checkRayIntersection(intX, intY, cell)) { - this._raycastParser.reset(); - return this._raycastParser.hitCounter; - } - n++; - } - this._raycastParser.reset(); - return this._raycastParser.hitCounter; - }; /** * 获取所有在指定矩形范围内的碰撞器 * @param rect @@ -9255,7 +9188,7 @@ var es; * @param layerMask */ SpatialHash.prototype.overlapRectangle = function (rect, results, layerMask) { - var e_9, _a; + var e_10, _a; this._overlapTestBox.updateBox(rect.width, rect.height); this._overlapTestBox.position = rect.location.clone(); var resultCounter = 0; @@ -9286,12 +9219,12 @@ var es; return resultCounter; } } - catch (e_9_1) { e_9 = { error: e_9_1 }; } + catch (e_10_1) { e_10 = { error: e_10_1 }; } finally { try { if (potentials_1_1 && !potentials_1_1.done && (_a = potentials_1.return)) _a.call(potentials_1); } - finally { if (e_9) throw e_9.error; } + finally { if (e_10) throw e_10.error; } } return resultCounter; }; @@ -9303,7 +9236,7 @@ var es; * @param layerMask */ SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { - var e_10, _a; + var e_11, _a; var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; this._overlapTestCircle.position = circleCenter.clone(); @@ -9338,12 +9271,12 @@ var es; return resultCounter; } } - catch (e_10_1) { e_10 = { error: e_10_1 }; } + catch (e_11_1) { e_11 = { error: e_11_1 }; } finally { try { if (potentials_2_1 && !potentials_2_1.done && (_a = potentials_2.return)) _a.call(potentials_2); } - finally { if (e_10) throw e_10.error; } + finally { if (e_11) throw e_11.error; } } return resultCounter; }; @@ -9415,13 +9348,7 @@ var es; this._checkedColliders = []; this._cellHits = []; } - RaycastResultParser.prototype.start = function (ray, hits, layerMask) { - this._ray = ray; - this._hits = hits; - this._layerMask = layerMask; - this.hitCounter = 0; - }; - RaycastResultParser.prototype.startIgnoreCollider = function (ray, hits, layerMask, ignoredColliders) { + RaycastResultParser.prototype.start = function (ray, hits, layerMask, ignoredColliders) { this._ray = ray; this._hits = hits; this._layerMask = layerMask; @@ -9435,7 +9362,6 @@ var es; * @param cell */ RaycastResultParser.prototype.checkRayIntersection = function (cellX, cellY, cell) { - var fraction = new es.Ref(0); for (var i = 0; i < cell.length; i++) { var potential = cell[i]; // 管理我们已经处理过的碰撞器 @@ -9448,11 +9374,15 @@ var es; // 确保碰撞器在图层蒙版上 if (!es.Flags.isFlagSet(this._layerMask, potential.physicsLayer.value)) continue; + if (this._ignoredColliders && this._ignoredColliders.has(potential)) { + continue; + } // TODO: rayIntersects的性能够吗?需要测试它。Collisions.rectToLine可能更快 // TODO: 如果边界检查返回更多数据,我们就不需要为BoxCollider检查做任何事情 // 在做形状测试之前先做一个边界检查 - var colliderBounds = potential.bounds.clone(); - if (colliderBounds.rayIntersects(this._ray, fraction) && fraction.value <= 1) { + var colliderBounds = potential.bounds; + var res = colliderBounds.rayIntersects(this._ray); + if (res.intersected && res.distance <= 1) { if (potential.shape.collidesWithLine(this._ray.start, this._ray.end, this._tempHit)) { // 检查一下,我们应该排除这些射线,射线cast是否在碰撞器中开始 if (!es.Physics.raycastsStartInColliders && potential.shape.containsPoint(this._ray.start)) @@ -9463,7 +9393,7 @@ var es; } } } - if (this._cellHits.length == 0) + if (this._cellHits.length === 0) return false; // 所有处理单元完成。对结果进行排序并将命中结果打包到结果数组中 this._cellHits.sort(RaycastResultParser.compareRaycastHits); @@ -9471,7 +9401,7 @@ var es; this._hits[this.hitCounter] = this._cellHits[i]; // 增加命中计数器,如果它已经达到数组大小的限制,我们就完成了 this.hitCounter++; - if (this.hitCounter == this._hits.length) + if (this.hitCounter === this._hits.length) return true; } return false; @@ -9480,9 +9410,15 @@ var es; this._hits = null; this._checkedColliders.length = 0; this._cellHits.length = 0; + this._ignoredColliders = null; }; RaycastResultParser.compareRaycastHits = function (a, b) { - return a.distance - b.distance; + if (a.distance !== b.distance) { + return a.distance - b.distance; + } + else { + return a.collider.castSortOrder - b.collider.castSortOrder; + } }; return RaycastResultParser; }()); @@ -9595,7 +9531,7 @@ var es; Polygon.recenterPolygonVerts = function (points) { var center = this.findPolygonCenter(points); for (var i = 0; i < points.length; i++) - points[i] = es.Vector2.subtract(points[i], center); + points[i] = points[i].sub(center); }; /** * 找到多边形的中心。注意,这对于正则多边形是准确的。不规则多边形没有中心。 @@ -9616,9 +9552,9 @@ var es; */ Polygon.getFarthestPointInDirection = function (points, direction) { var index = 0; - var maxDot = es.Vector2.dot(points[index], direction); + var maxDot = points[index].dot(direction); for (var i = 1; i < points.length; i++) { - var dot = es.Vector2.dot(points[i], direction); + var dot = points[i].dot(direction); if (dot > maxDot) { maxDot = dot; index = i; @@ -9635,29 +9571,30 @@ var es; * @param distanceSquared * @param edgeNormal */ - Polygon.getClosestPointOnPolygonToPoint = function (points, point, distanceSquared, edgeNormal) { - distanceSquared.value = Number.MAX_VALUE; - edgeNormal.x = 0; - edgeNormal.y = 0; - var closestPoint = es.Vector2.zero; + Polygon.getClosestPointOnPolygonToPoint = function (points, point) { + var res = { + distanceSquared: Number.MAX_VALUE, + edgeNormal: es.Vector2.zero, + closestPoint: es.Vector2.zero, + }; var tempDistanceSquared = 0; for (var i = 0; i < points.length; i++) { var j = i + 1; - if (j == points.length) + if (j === points.length) j = 0; var closest = es.ShapeCollisionsCircle.closestPointOnLine(points[i], points[j], point); - tempDistanceSquared = es.Vector2.distanceSquared(point, closest); - if (tempDistanceSquared < distanceSquared.value) { - distanceSquared.value = tempDistanceSquared; - closestPoint = closest; + tempDistanceSquared = es.Vector2.sqrDistance(point, closest); + if (tempDistanceSquared < res.distanceSquared) { + res.distanceSquared = tempDistanceSquared; + res.closestPoint = closest; // 求直线的法线 - var line = es.Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; + var line = points[j].sub(points[i]); + res.edgeNormal.x = line.y; + res.edgeNormal.y = -line.x; } } - es.Vector2Ext.normalize(edgeNormal); - return closestPoint; + res.edgeNormal = res.edgeNormal.normalize(); + return res; }; /** * 旋转原始点并复制旋转的值到旋转的点 @@ -9674,41 +9611,47 @@ var es; } }; Polygon.prototype.recalculateBounds = function (collider) { + var _this = this; // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始 - this.center = collider.localOffset.clone(); + this.center = collider.localOffset; if (collider.shouldColliderScaleAndRotateWithTransform) { var hasUnitScale = true; - var tempMat = void 0; - var combinedMatrix = es.Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); + var tempMat = new es.Matrix2D(); + var combinedMatrix_1 = new es.Matrix2D(); + es.Matrix2D.createTranslation(this._polygonCenter.x * -1, this._polygonCenter.y * -1, combinedMatrix_1); if (!collider.entity.transform.scale.equals(es.Vector2.one)) { - tempMat = es.Matrix2D.createScale(collider.entity.transform.scale.x, collider.entity.transform.scale.y); - combinedMatrix = combinedMatrix.multiply(tempMat); + es.Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y, tempMat); + es.Matrix2D.multiply(combinedMatrix_1, tempMat, combinedMatrix_1); hasUnitScale = false; // 缩放偏移量并将其设置为中心。如果我们有旋转,它会在下面重置 - this.center = es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale); + var scaledOffset = new es.Vector2(collider.localOffset.x * collider.entity.scale.x, collider.localOffset.y * collider.entity.scale.y); + this.center = scaledOffset; } if (collider.entity.transform.rotation != 0) { - tempMat = es.Matrix2D.createRotation(collider.entity.transform.rotation); - combinedMatrix = combinedMatrix.multiply(tempMat); + es.Matrix2D.createRotation(es.MathHelper.Deg2Rad * collider.entity.rotation, tempMat); + es.Matrix2D.multiply(combinedMatrix_1, tempMat, combinedMatrix_1); // 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动 // 我们的偏移使角度为0我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。 var offsetAngle = Math.atan2(collider.localOffset.y * collider.entity.transform.scale.y, collider.localOffset.x * collider.entity.transform.scale.x) * es.MathHelper.Rad2Deg; var offsetLength = hasUnitScale ? collider._localOffsetLength : - es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); + collider.localOffset.multiply(collider.entity.transform.scale).magnitude(); this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); } - tempMat = es.Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); - combinedMatrix = combinedMatrix.multiply(tempMat); + es.Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y, tempMat); + es.Matrix2D.multiply(combinedMatrix_1, tempMat, combinedMatrix_1); // 最后变换原始点 - es.Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); + this.points = []; + this._originalPoints.forEach(function (p) { + _this.points.push(p.transform(combinedMatrix_1)); + }); this.isUnrotated = collider.entity.transform.rotation == 0; // 如果旋转的话,我们只需要重建边的法线 if (collider._isRotationDirty) this._areEdgeNormalsDirty = true; } - this.position = es.Vector2.add(collider.entity.transform.position, this.center); + this.position = collider.transform.position.add(this.center); this.bounds = es.Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = es.Vector2.add(this.bounds.location, this.position); + this.bounds.location = this.bounds.location.add(this.position); }; Polygon.prototype.overlaps = function (other) { var result = new es.CollisionResult(); @@ -9746,10 +9689,10 @@ var es; */ Polygon.prototype.containsPoint = function (point) { // 将点归一化到多边形坐标空间中 - point.sub(this.position); + point = point.sub(this.position); var isInside = false; for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { - if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && + if (((this.points[i].y > point.y) !== (this.points[j].y > point.y)) && (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + this.points[i].x)) { isInside = !isInside; @@ -9863,17 +9806,17 @@ var es; if (collider.shouldColliderScaleAndRotateWithTransform) { // 我们只将直线缩放为一个圆,所以我们将使用最大值 var scale = collider.entity.transform.scale; - var hasUnitScale = scale.x == 1 && scale.y == 1; + var hasUnitScale = scale.x === 1 && scale.y === 1; var maxScale = Math.max(scale.x, scale.y); this.radius = this._originalRadius * maxScale; - if (collider.entity.transform.rotation != 0) { + if (collider.entity.transform.rotation !== 0) { // 为了处理偏移原点的旋转,我们只需要将圆心围绕(0,0)在一个圆上移动,我们的偏移量就是0角 var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); - this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + var offsetLength = hasUnitScale ? collider._localOffsetLength : collider.localOffset.multiply(collider.entity.transform.scale).magnitude(); + this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); } } - this.position = es.Vector2.add(collider.entity.transform.position, this.center); + this.position = collider.transform.position.add(this.center); this.bounds = new es.Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); }; Circle.prototype.overlaps = function (other) { @@ -9901,12 +9844,15 @@ var es; Circle.prototype.collidesWithLine = function (start, end, hit) { return es.ShapeCollisionsLine.lineToCircle(start, end, this, hit); }; + Circle.prototype.getPointAlongEdge = function (angle) { + return new es.Vector2(this.position.x + this.radius * Math.cos(angle), this.position.y + this.radius * Math.sin(angle)); + }; /** * 获取所提供的点是否在此范围内 * @param point */ Circle.prototype.containsPoint = function (point) { - return (es.Vector2.subtract(point, this.position)).lengthSquared() <= this.radius * this.radius; + return (point.sub(this.position)).lengthSquared() <= this.radius * this.radius; }; Circle.prototype.pointCollidesWithShape = function (point, result) { return es.ShapeCollisionsPoint.pointToCircle(point, this, result); @@ -9932,14 +9878,33 @@ var es; */ this.point = es.Vector2.zero; } + CollisionResult.prototype.reset = function () { + this.collider = null; + this.normal.setTo(0, 0); + this.minimumTranslationVector.setTo(0, 0); + if (this.point) { + this.point.setTo(0, 0); + } + }; + CollisionResult.prototype.cloneTo = function (cr) { + cr.collider = this.collider; + cr.normal.setTo(this.normal.x, this.normal.y); + cr.minimumTranslationVector.setTo(this.minimumTranslationVector.x, this.minimumTranslationVector.y); + if (this.point) { + if (!cr.point) { + cr.point = new es.Vector2(0, 0); + } + cr.point.setTo(this.point.x, this.point.y); + } + }; /** * 改变最小平移向量,如果没有相同方向上的运动,它将移除平移的x分量。 * @param deltaMovement */ - CollisionResult.prototype.removeHorizontal = function (deltaMovement) { + CollisionResult.prototype.removeHorizontalTranslation = function (deltaMovement) { // 检查是否需要横向移动,如果需要,移除并固定响应 - if (Math.sign(this.normal.x) != Math.sign(deltaMovement.x) || (deltaMovement.x == 0 && this.normal.x != 0)) { - var responseDistance = this.minimumTranslationVector.length(); + if (Math.sign(this.normal.x) !== Math.sign(deltaMovement.x) || (deltaMovement.x === 0 && this.normal.x !== 0)) { + var responseDistance = this.minimumTranslationVector.magnitude(); var fix = responseDistance / this.normal.y; // 检查一些边界情况。因为我们除以法线 使得x == 1和一个非常小的y这将导致一个巨大的固定值 if (Math.abs(this.normal.x) != 1 && Math.abs(fix) < Math.abs(deltaMovement.y * 3)) { @@ -9948,9 +9913,8 @@ var es; } }; CollisionResult.prototype.invertResult = function () { - this.minimumTranslationVector = es.Vector2.negate(this.minimumTranslationVector); - this.normal = es.Vector2.negate(this.normal); - return this; + this.minimumTranslationVector = this.minimumTranslationVector.negate(); + this.normal = this.normal.negate(); }; CollisionResult.prototype.toString = function () { return "[CollisionResult] normal: " + this.normal + ", minimumTranslationVector: " + this.minimumTranslationVector; @@ -9966,14 +9930,15 @@ var es; } RealtimeCollisions.intersectMovingCircleBox = function (s, b, movement, time) { // 计算将b按球面半径r扩大后的AABB - var e = b.bounds.clone(); + var e = b.bounds; e.inflate(s.radius, s.radius); // 将射线与展开的矩形e相交,如果射线错过了e,则以无交点退出,否则得到交点p和时间t作为结果。 - var ray = new es.Ray2D(es.Vector2.subtract(s.position, movement), s.position); - if (!e.rayIntersects(ray, time) && time.value > 1) + var ray = new es.Ray2D(s.position.sub(movement), s.position); + var res = e.rayIntersects(ray); + if (!res.intersected && res.distance > 1) return false; // 求交点 - var point = es.Vector2.add(ray.start, es.Vector2.multiplyScaler(ray.direction, time.value)); + var point = ray.start.add(ray.direction.scale(time)); // 计算交点p位于b的哪个最小面和最大面之外。注意,u和v不能有相同的位集,它们之间必须至少有一个位集。 var u, v = 0; if (point.x < b.bounds.left) @@ -10020,8 +9985,8 @@ var es; // 找出离球心最近的点 point = box.bounds.getClosestPointOnRectangleToPoint(cirlce.position); // 圆和方块相交,如果圆心到点的距离小于圆的半径,则圆和方块相交 - var v = es.Vector2.subtract(point, cirlce.position); - var dist = es.Vector2.dot(v, v); + var v = point.sub(cirlce.position); + var dist = v.dot(v); return dist <= cirlce.radius * cirlce.radius; }; return RealtimeCollisions; @@ -10040,8 +10005,8 @@ var es; result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); if (result.minimumTranslationVector.equals(es.Vector2.zero)) return false; - result.normal = new es.Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); - result.normal.normalize(); + result.normal = result.minimumTranslationVector.scale(-1); + result.normal = result.normal.normalize(); return true; } return false; @@ -10062,21 +10027,21 @@ var es; if (mtv.equals(es.Vector2.zero)) return false; hit.normal = new es.Vector2(-mtv.x, -mtv.y); - hit.normal.normalize(); + hit.normal = hit.normal.normalize(); hit.distance = 0; hit.fraction = 0; return true; } else { // 射线投射移动矢量 - var ray = new es.Ray2D(es.Vector2.zero, new es.Vector2(-movement.x, -movement.y)); - var fraction = new es.Ref(0); - if (minkowskiDiff.rayIntersects(ray, fraction) && fraction.value <= 1) { - hit.fraction = fraction.value; - hit.distance = movement.length() * fraction.value; - hit.normal = new es.Vector2(-movement.x, -movement.y); - hit.normal.normalize(); - hit.centroid = es.Vector2.add(first.bounds.center, es.Vector2.multiplyScaler(movement, fraction.value)); + var ray = new es.Ray2D(es.Vector2.zero, movement.scale(-1)); + var res = minkowskiDiff.rayIntersects(ray); + if (res.intersected && res.distance <= 1) { + hit.fraction = res.distance; + hit.distance = movement.magnitude() * res.distance; + hit.normal = movement.scale(-1); + hit.normal = hit.normal.normalize(); + hit.centroid = first.bounds.center.add(movement.scale(res.distance)); return true; } } @@ -10085,9 +10050,9 @@ var es; ShapeCollisionsBox.minkowskiDifference = function (first, second) { // 我们需要第一个框的左上角 // 碰撞器只会修改运动的位置所以我们需要用位置来计算出运动是什么。 - var positionOffset = es.Vector2.subtract(first.position, es.Vector2.add(first.bounds.location, new es.Vector2(first.bounds.size.x / 2, first.bounds.size.y / 2))); - var topLeft = es.Vector2.subtract(es.Vector2.add(first.bounds.location, positionOffset), second.bounds.max); - var fullSize = es.Vector2.add(first.bounds.size, second.bounds.size); + var positionOffset = first.position.sub(first.bounds.center); + var topLeft = first.bounds.location.add(positionOffset.sub(second.bounds.max)); + var fullSize = first.bounds.size.add(second.bounds.size); return new es.Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y); }; return ShapeCollisionsBox; @@ -10099,20 +10064,38 @@ var es; var ShapeCollisionsCircle = /** @class */ (function () { function ShapeCollisionsCircle() { } + ShapeCollisionsCircle.circleToCircleCast = function (first, second, deltaMovement, hit) { + var endPointOfCast = first.position.add(deltaMovement); + var d = this.closestPointOnLine(first.position, endPointOfCast, second.position); + var closestDistanceSquared = es.Vector2.sqrDistance(second.position, d); + var sumOfRadiiSquared = (first.radius + second.radius) * (first.radius + second.radius); + if (closestDistanceSquared <= sumOfRadiiSquared) { + var normalizedDeltaMovement = deltaMovement.normalize(); + if (d === endPointOfCast) { + endPointOfCast = first.position.add(deltaMovement.add(normalizedDeltaMovement.scale(second.radius))); + d = this.closestPointOnLine(first.position, endPointOfCast, second.position); + closestDistanceSquared = es.Vector2.sqrDistance(second.position, d); + } + var backDist = Math.sqrt(sumOfRadiiSquared - closestDistanceSquared); + hit.centroid = d.sub(normalizedDeltaMovement.scale(backDist)); + hit.normal = hit.centroid.sub(second.position).normalize(); + hit.fraction = (hit.centroid.x - first.position.x) / deltaMovement.x; + hit.distance = es.Vector2.distance(first.position, hit.centroid); + hit.point = second.position.add(hit.normal.scale(second.radius)); + return true; + } + return false; + }; ShapeCollisionsCircle.circleToCircle = function (first, second, result) { if (result === void 0) { result = new es.CollisionResult(); } - var distanceSquared = es.Vector2.distanceSquared(first.position, second.position); + var distanceSquared = es.Vector2.sqrDistance(first.position, second.position); var sumOfRadii = first.radius + second.radius; var collided = distanceSquared < sumOfRadii * sumOfRadii; if (collided) { - result.normal = es.Vector2.normalize(es.Vector2.subtract(first.position, second.position)); + result.normal = first.position.sub(second.position).normalize(); var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = es.Vector2.multiplyScaler(result.normal, -depth); - result.point = es.Vector2.add(second.position, es.Vector2.multiplyScaler(result.normal, second.radius)); - // 这可以得到实际的碰撞点,可能有用也可能没用,所以我们暂时把它留在这里 - // let collisionPointX = ((first.position.x * second.radius) + (second.position.x * first.radius)) / sumOfRadii; - // let collisionPointY = ((first.position.y * second.radius) + (second.position.y * first.radius)) / sumOfRadii; - // result.point = new Vector2(collisionPointX, collisionPointY); + result.minimumTranslationVector = result.normal.scale(-depth); + result.point = second.position.add(result.normal.scale(second.radius)); return true; } return false; @@ -10128,23 +10111,23 @@ var es; var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); // 先处理中心在盒子里的圆,如果我们是包含的, 它的成本更低, if (box.containsPoint(circle.position)) { - result.point = closestPointOnBounds.clone(); + result.point = closestPointOnBounds; // 计算MTV。找出安全的、非碰撞的位置,并从中得到MTV - var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.multiplyScaler(result.normal, circle.radius)); - result.minimumTranslationVector = es.Vector2.subtract(circle.position, safePlace); + var safePlace = closestPointOnBounds.add(result.normal.scale(circle.radius)); + result.minimumTranslationVector = circle.position.sub(safePlace); return true; } - var sqrDistance = es.Vector2.distanceSquared(closestPointOnBounds, circle.position); + var sqrDistance = es.Vector2.sqrDistance(closestPointOnBounds, circle.position); // 看框上的点距圆的半径是否小于圆的半径 if (sqrDistance == 0) { - result.minimumTranslationVector = es.Vector2.multiplyScaler(result.normal, circle.radius); + result.minimumTranslationVector = result.normal.scale(circle.radius); } else if (sqrDistance <= circle.radius * circle.radius) { - result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds); - var depth = result.normal.length() - circle.radius; + result.normal = circle.position.sub(closestPointOnBounds); + var depth = result.normal.magnitude() - circle.radius; result.point = closestPointOnBounds; - es.Vector2Ext.normalize(result.normal); - result.minimumTranslationVector = es.Vector2.multiplyScaler(result.normal, depth); + result.normal = result.normal.normalize(); + result.minimumTranslationVector = result.normal.scale(depth); return true; } return false; @@ -10152,42 +10135,43 @@ var es; ShapeCollisionsCircle.circleToPolygon = function (circle, polygon, result) { if (result === void 0) { result = new es.CollisionResult(); } // 圆圈在多边形中的位置坐标 - var poly2Circle = es.Vector2.subtract(circle.position, polygon.position); + var poly2Circle = circle.position.sub(polygon.position); // 首先,我们需要找到从圆到多边形的最近距离 - var distanceSquared = new es.Ref(0); - var closestPoint = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle, distanceSquared, result.normal); + var res = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); + result.normal = res.edgeNormal; // 确保距离的平方小于半径的平方,否则我们不会相撞。 // 请注意,如果圆完全包含在多边形中,距离可能大于半径。 // 正因为如此,我们还要确保圆的位置不在多边形内。 var circleCenterInsidePoly = polygon.containsPoint(circle.position); - if (distanceSquared.value > circle.radius * circle.radius && !circleCenterInsidePoly) + if (res.distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) return false; // 算出MTV。我们要注意处理完全包含在多边形中的圆或包含其中心的圆 var mtv; if (circleCenterInsidePoly) { - mtv = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared.value) - circle.radius)); + mtv = result.normal.scale(Math.sqrt(res.distanceSquared) - circle.radius); } else { // 如果我们没有距离,这意味着圆心在多边形的边缘上。只需根据它的半径移动它 - if (distanceSquared.value == 0) { - mtv = new es.Vector2(result.normal.x * circle.radius, result.normal.y * circle.radius); + if (res.distanceSquared === 0) { + mtv = result.normal.scale(circle.radius); } else { - var distance = Math.sqrt(distanceSquared.value); - mtv = es.Vector2.multiplyScaler(es.Vector2.subtract(poly2Circle, closestPoint), -1) - .multiply(new es.Vector2((circle.radius - distance) / distance)); + var distance = Math.sqrt(res.distanceSquared); + mtv = poly2Circle + .sub(res.closestPoint) + .scale(((circle.radius - distance) / distance) * -1); } } result.minimumTranslationVector = mtv; - result.point = es.Vector2.add(closestPoint, polygon.position); + result.point = res.closestPoint.add(polygon.position); return true; }; ShapeCollisionsCircle.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = es.Vector2.subtract(lineB, lineA); - var w = es.Vector2.subtract(closestTo, lineA); - var t = es.Vector2.dot(w, v) / es.Vector2.dot(v, v); + var v = lineB.sub(lineA); + var w = closestTo.sub(lineA); + var t = w.dot(v) / v.dot(v); t = es.MathHelper.clamp(t, 0, 1); - return es.Vector2.add(lineA, es.Vector2.multiplyScaler(v, t)); + return lineA.add(v.scaleEqual(t)); }; return ShapeCollisionsCircle; }()); @@ -10208,7 +10192,7 @@ var es; var edge1 = es.Vector2.add(polygon.position, polygon.points[j]); var edge2 = es.Vector2.add(polygon.position, polygon.points[i]); var intersection = es.Vector2.zero; - if (this.lineToLine(edge1, edge2, start, end, intersection)) { + if (ShapeCollisionsLine.lineToLine(edge1, edge2, start, end, intersection)) { hasIntersection = true; // TODO: 这是得到分数的正确和最有效的方法吗? // 先检查x分数。如果是NaN,就用y代替 @@ -10216,7 +10200,7 @@ var es; if (Number.isNaN(distanceFraction) || Math.abs(distanceFraction) == Infinity) distanceFraction = (intersection.y - start.y) / (end.y - start.y); if (distanceFraction < fraction) { - var edge = es.Vector2.subtract(edge2, edge1); + var edge = edge2.sub(edge1); normal = new es.Vector2(edge.y, -edge.x); fraction = distanceFraction; intersectionPoint = intersection; @@ -10224,28 +10208,28 @@ var es; } } if (hasIntersection) { - normal.normalize(); + normal = normal.normalize(); var distance = es.Vector2.distance(start, intersectionPoint); - hit.setValuesNonCollider(fraction, distance, intersectionPoint, normal); + hit.setValues(fraction, distance, intersectionPoint, normal); return true; } return false; }; ShapeCollisionsLine.lineToLine = function (a1, a2, b1, b2, intersection) { - var b = es.Vector2.subtract(a2, a1); - var d = es.Vector2.subtract(b2, b1); + var b = a2.sub(a1); + var d = b2.sub(b1); var bDotDPerp = b.x * d.y - b.y * d.x; // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 if (bDotDPerp == 0) return false; - var c = es.Vector2.subtract(b1, a1); + var c = b1.sub(a1); var t = (c.x * d.y - c.y * d.x) / bDotDPerp; if (t < 0 || t > 1) return false; var u = (c.x * b.y - c.y * b.x) / bDotDPerp; if (u < 0 || u > 1) return false; - var r = es.Vector2.add(a1, es.Vector2.multiplyScaler(b, t)); + var r = a1.add(b.scale(t)); intersection.x = r.x; intersection.y = r.y; return true; @@ -10253,10 +10237,10 @@ var es; ShapeCollisionsLine.lineToCircle = function (start, end, s, hit) { // 计算这里的长度并分别对d进行标准化,因为如果我们命中了我们需要它来得到分数 var lineLength = es.Vector2.distance(start, end); - var d = es.Vector2.divideScaler(es.Vector2.subtract(end, start), lineLength); - var m = es.Vector2.subtract(start, s.position); - var b = es.Vector2.dot(m, d); - var c = es.Vector2.dot(m, m) - s.radius * s.radius; + var d = es.Vector2.divideScaler(end.sub(start), lineLength); + var m = start.sub(s.position); + var b = m.dot(d); + var c = m.dot(m) - s.radius * s.radius; // 如果r的原点在s之外,(c>0)和r指向s (b>0) 则返回 if (c > 0 && b > 0) return false; @@ -10269,9 +10253,9 @@ var es; // 如果分数为负数,射线从圈内开始, if (hit.fraction < 0) hit.fraction = 0; - hit.point = es.Vector2.add(start, es.Vector2.multiplyScaler(d, hit.fraction)); + hit.point = start.add(d.scale(hit.fraction)); hit.distance = es.Vector2.distance(start, hit.point); - hit.normal = es.Vector2.normalize(es.Vector2.subtract(hit.point, s.position)); + hit.normal = hit.point.sub(s.position).normalize(); hit.fraction = hit.distance / lineLength; return true; }; @@ -10285,14 +10269,15 @@ var es; function ShapeCollisionsPoint() { } ShapeCollisionsPoint.pointToCircle = function (point, circle, result) { - var distanceSquared = es.Vector2.distanceSquared(point, circle.position); + var distanceSquared = es.Vector2.sqrDistance(point, circle.position); var sumOfRadii = 1 + circle.radius; var collided = distanceSquared < sumOfRadii * sumOfRadii; if (collided) { - result.normal = es.Vector2.normalize(es.Vector2.subtract(point, circle.position)); + result.normal = point.sub(circle.position).normalize(); var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = es.Vector2.multiplyScaler(result.normal, -depth); - result.point = es.Vector2.add(circle.position, es.Vector2.multiplyScaler(result.normal, circle.radius)); + result.minimumTranslationVector = result.normal.scale(-depth); + ; + result.point = circle.position.add(result.normal.scale(circle.radius)); return true; } return false; @@ -10302,7 +10287,7 @@ var es; if (box.containsPoint(point)) { // 在方框的空间里找到点 result.point = box.bounds.getClosestPointOnRectangleBorderToPoint(point, result.normal); - result.minimumTranslationVector = es.Vector2.subtract(point, result.point); + result.minimumTranslationVector = point.sub(result.point); return true; } return false; @@ -10310,10 +10295,10 @@ var es; ShapeCollisionsPoint.pointToPoly = function (point, poly, result) { if (result === void 0) { result = new es.CollisionResult(); } if (poly.containsPoint(point)) { - var distanceSquared = new es.Ref(0); - var closestPoint = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, es.Vector2.subtract(point, poly.position), distanceSquared, result.normal); - result.minimumTranslationVector = new es.Vector2(result.normal.x * Math.sqrt(distanceSquared.value), result.normal.y * Math.sqrt(distanceSquared.value)); - result.point = es.Vector2.add(closestPoint, poly.position); + var res = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, point.sub(poly.position)); + result.normal = res.edgeNormal; + result.minimumTranslationVector = result.normal.scale(Math.sqrt(res.distanceSquared)); + result.point = res.closestPoint.sub(poly.position); return true; } return false; @@ -10339,7 +10324,7 @@ var es; var secondEdges = second.edgeNormals; var minIntervalDistance = Number.POSITIVE_INFINITY; var translationAxis = es.Vector2.zero; - var polygonOffset = es.Vector2.subtract(first.position, second.position); + var polygonOffset = first.position.sub(second.position); var axis; // 循环穿过两个多边形的所有边 for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { @@ -10351,7 +10336,7 @@ var es; var _a = this.getInterval(axis, first), minA = _a.min, maxA = _a.max; var _b = this.getInterval(axis, second), minB = _b.min, maxB = _b.max; // 将区间设为第二个多边形的空间。由轴上投影的位置差偏移。 - var relativeIntervalOffset = es.Vector2.dot(polygonOffset, axis); + var relativeIntervalOffset = polygonOffset.dot(axis); minA += relativeIntervalOffset; maxA += relativeIntervalOffset; // 检查多边形投影是否正在相交 @@ -10368,13 +10353,13 @@ var es; if (intervalDist < minIntervalDistance) { minIntervalDistance = intervalDist; translationAxis.setTo(axis.x, axis.y); - if (es.Vector2.dot(translationAxis, polygonOffset) < 0) + if (translationAxis.dot(polygonOffset) < 0) translationAxis = translationAxis.scale(-1); } } // 利用最小平移向量对多边形进行推入。 result.normal = translationAxis; - result.minimumTranslationVector = translationAxis.scale(minIntervalDistance * -1); + result.minimumTranslationVector = translationAxis.scale(-minIntervalDistance); return true; }; /** @@ -10387,11 +10372,11 @@ var es; ShapeCollisionsPolygon.getInterval = function (axis, polygon) { var res = { min: 0, max: 0 }; var dot; - dot = es.Vector2.dot(polygon.points[0], axis); + dot = polygon.points[0].dot(axis); res.max = dot; res.min = dot; for (var i = 1; i < polygon.points.length; i++) { - dot = es.Vector2.dot(polygon.points[i], axis); + dot = polygon.points[i].dot(axis); if (dot < res.min) { res.min = dot; } @@ -10926,13 +10911,13 @@ var es; } Triangulator.testPointTriangle = function (point, a, b, c) { // 如果点在AB的右边,那么外边的三角形是 - if (es.Vector2Ext.cross(es.Vector2.subtract(point, a), es.Vector2.subtract(b, a)) < 0) + if (es.Vector2Ext.cross(point.sub(a), b.sub(a)) < 0) return false; // 如果点在BC的右边,则在三角形的外侧 - if (es.Vector2Ext.cross(es.Vector2.subtract(point, b), es.Vector2.subtract(c, b)) < 0) + if (es.Vector2Ext.cross(point.sub(b), c.sub(b)) < 0) return false; // 如果点在ca的右边,则在三角形的外面 - if (es.Vector2Ext.cross(es.Vector2.subtract(point, c), es.Vector2.subtract(a, c)) < 0) + if (es.Vector2Ext.cross(point.sub(c), a.sub(c)) < 0) return false; // 点在三角形上 return true; @@ -13694,7 +13679,7 @@ var es; * @param c */ Vector2Ext.isTriangleCCW = function (a, center, c) { - return this.cross(es.Vector2.subtract(center, a), es.Vector2.subtract(c, center)) < 0; + return this.cross(center.sub(a), c.sub(center)) < 0; }; Vector2Ext.halfVector = function () { return new es.Vector2(0.5, 0.5); @@ -13730,7 +13715,7 @@ var es; Vector2Ext.angle = function (from, to) { this.normalize(from); this.normalize(to); - return Math.acos(es.MathHelper.clamp(es.Vector2.dot(from, to), -1, 1)) * es.MathHelper.Rad2Deg; + return Math.acos(es.MathHelper.clamp(from.dot(to), -1, 1)) * es.MathHelper.Rad2Deg; }; /** * 返回以自度为中心的左右角度 @@ -13739,8 +13724,8 @@ var es; * @param right */ Vector2Ext.angleBetween = function (self, left, right) { - var one = es.Vector2.subtract(left, self); - var two = es.Vector2.subtract(right, self); + var one = left.sub(self); + var two = right.sub(self); return this.angle(one, two); }; /** @@ -14293,7 +14278,7 @@ var es; * 创建一个Set从一个Enumerable.List< T>。 */ List.prototype.toSet = function () { - var e_11, _a; + var e_12, _a; var result = new Set(); try { for (var _b = __values(this._elements), _c = _b.next(); !_c.done; _c = _b.next()) { @@ -14301,12 +14286,12 @@ var es; result.add(x); } } - catch (e_11_1) { e_11 = { error: e_11_1 }; } + catch (e_12_1) { e_12 = { error: e_12_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_11) throw e_11.error; } + finally { if (e_12) throw e_12.error; } } return result; }; @@ -14482,7 +14467,7 @@ var es; * @param radius */ VisibilityComputer.prototype.addCircleOccluder = function (position, radius) { - var dirToCircle = es.Vector2.subtract(position, this._origin); + var dirToCircle = position.sub(this._origin); var angle = Math.atan2(dirToCircle.y, dirToCircle.x); var stepSize = Math.PI / this.lineCountForCircleApproximation; var startAngle = angle + es.MathHelper.PiOver2; @@ -14555,7 +14540,7 @@ var es; * 计算可见性多边形,并返回三角形扇形的顶点(减去中心顶点)。返回的数组来自ListPool */ VisibilityComputer.prototype.end = function () { - var e_12, _a; + var e_13, _a; var output = es.ListPool.obtain(); this.updateSegments(); this._endPoints.sort(this._radialComparer.compare); @@ -14594,12 +14579,12 @@ var es; } } } - catch (e_12_1) { e_12 = { error: e_12_1 }; } + catch (e_13_1) { e_13 = { error: e_13_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_12) throw e_12.error; } + finally { if (e_13) throw e_13.error; } } } VisibilityComputer._openSegments.clear(); @@ -14715,7 +14700,7 @@ var es; * 处理片段,以便我们稍后对它们进行分类 */ VisibilityComputer.prototype.updateSegments = function () { - var e_13, _a; + var e_14, _a; try { for (var _b = __values(this._segments), _c = _b.next(); !_c.done; _c = _b.next()) { var segment = _c.value; @@ -14733,12 +14718,12 @@ var es; segment.p2.begin = !segment.p1.begin; } } - catch (e_13_1) { e_13 = { error: e_13_1 }; } + catch (e_14_1) { e_14 = { error: e_14_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_13) throw e_13.error; } + finally { if (e_14) throw e_14.error; } } // 如果我们有一个聚光灯,我们需要存储前两个段的角度。 // 这些是光斑的边界,我们将用它们来过滤它们之外的任何顶点。 diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index c7690d1d..3b00976c 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.es={};var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{h(i.next(t))}catch(t){o(t)}}function a(t){try{h(i.throw(t))}catch(t){o(t)}}function h(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}h((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}},transform;!function(t){var e=function(){function e(n,i){void 0===n&&(n=!0),void 0===i&&(i=!0),this._globalManagers=[],this._coroutineManager=new t.CoroutineManager,this._timerManager=new t.TimerManager,this._frameCounterElapsedTime=0,this._frameCounter=0,this._totalMemory=0,e._instance=this,e.emitter=new t.Emitter,e.emitter.addObserver(t.CoreEvents.frameUpdated,this.update,this),e.registerGlobalManager(this._coroutineManager),e.registerGlobalManager(this._timerManager),e.entitySystemsEnabled=i,this.debug=n,this.initialize()}return Object.defineProperty(e,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(e,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(e){t.Insist.isNotNull(e,"场景不能为空"),null==this._instance._scene?(this._instance._scene=e,this._instance.onSceneChanged(),this._instance._scene.begin()):this._instance._nextScene=e},enumerable:!0,configurable:!0}),e.create=function(e){return void 0===e&&(e=!0),null==this._instance&&(this._instance=new t.Core(e)),this._instance},e.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},e.unregisterGlobalManager=function(e){new t.List(this._instance._globalManagers).remove(e),e.enabled=!1},e.getGlobalManager=function(t){for(var n=0,i=e._instance._globalManagers.length;n=1)){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._titleMemory&&this._titleMemory(this._totalMemory,this._frameCounter),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(n){return void 0===n&&(n=-1),__awaiter(this,void 0,void 0,function(){var i;return __generator(this,function(r){if(e.paused)return[2];if(t.Time.update(n),null!=this._scene){for(i=this._globalManagers.length-1;i>=0;i--)this._globalManagers[i].enabled&&this._globalManagers[i].update();this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}return this.startDebugDraw(),[2]})})},e.paused=!1,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){var e;!function(t){t[t.error=0]="error",t[t.warn=1]="warn",t[t.log=2]="log",t[t.info=3]="info",t[t.trace=4]="trace"}(e=t.LogType||(t.LogType={}));var n=function(){function t(){}return t.warnIf=function(t,n){for(var i=[],r=2;r=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t0?new e(t.x/n,t.y/n):new e(0,1)},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.lerpPrecise=function(n,i,r){return new e(t.MathHelper.lerpPrecise(n.x,i.x,r),t.MathHelper.lerpPrecise(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.transformNormal=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.angle=function(n,i){return n=e.normalize(n),i=e.normalize(i),Math.acos(t.MathHelper.clamp(e.dot(n,i),-1,1))*t.MathHelper.Rad2Deg},e.negate=function(t){return t.x=-t.x,t.y=-t.y,t},e.reflect=function(e,n){var i=t.Vector2.zero,r=2*(e.x*n.x+e.y*n.y);return i.x=e.x-n.x*r,i.y=e.y-n.y*r,i},e.smoothStep=function(n,i,r){return new e(t.MathHelper.smoothStep(n.x,i.x,r),t.MathHelper.smoothStep(n.y,i.y,r))},e.prototype.setTo=function(t,e){this.x=t,this.y=e},e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y)},e.prototype.addEqual=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.divideScaler=function(t){return this.x/=t,this.y/=t,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.multiplyScaler=function(t){return this.x*=t,this.y*=t,this},e.prototype.sub=function(t){return new e(this.x-t.x,this.y-t.y)},e.prototype.subEqual=function(t){return this.x-=t.x,this.y-=t.y,this},e.prototype.scale=function(t){return new e(this.x*t,this.y*t)},e.prototype.normalize=function(){var t=this.distance();return t>0?(this.setTo(this.x/t,this.y/t),this):(this.setTo(0,1),this)},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.magnitude=function(){return this.distance()},e.prototype.distance=function(t){return t||(t=e.zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.prototype.angleBetween=function(n,i){var r=e.subtract(n,this),o=e.subtract(i,this);return t.Vector2Ext.angle(r,o)},e.prototype.equals=function(t){return t instanceof e&&(t.x==this.x&&t.y==this.y)},e.prototype.isValid=function(){return t.MathHelper.isValid(this.x)&&t.MathHelper.isValid(this.y)},e.min=function(t,n){return new e(t.xn.x?t.x:n.x,t.y>n.y?t.y:n.y)},e.hermite=function(n,i,r,o,s){return new e(t.MathHelper.hermite(n.x,i.x,r.x,o.x,s),t.MathHelper.hermite(n.y,i.y,r.y,o.y,s))},e.unsignedAngle=function(n,i,r){void 0===r&&(r=!0),n.normalize(),i.normalize();var o=Math.acos(t.MathHelper.clamp(e.dot(n,i),-1,1))*t.MathHelper.Rad2Deg;return r?Math.round(o):o},e.prototype.clone=function(){return new e(this.x,this.y)},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(){this._sceneComponents=[],this._renderers=[],this.entities=new t.EntityList(this),this.renderableComponents=new t.RenderableComponentList,this.entityProcessors=new t.EntityProcessorList,this.identifierPool=new t.IdentifierPool,this.initialize()}return e.prototype.initialize=function(){},e.prototype.onStart=function(){},e.prototype.unload=function(){},e.prototype.begin=function(){0==this._renderers.length&&this.addRenderer(new t.DefaultRenderer),t.Physics.reset(),null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.prototype.end=function(){this._didSceneBegin=!1;for(var e=0;e=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateLists(),this.render()},e.prototype.render=function(){for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,null!=this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(null!=this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.createRotation(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.createScale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),t.Matrix2D.multiply(this._scaleMatrix,this._rotationMatrix,this._localTransform),t.Matrix2D.multiply(this._localTransform,this._translationMatrix,this._localTransform),null==this.parent&&(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),null!=this.parent&&(t.Matrix2D.multiply(this._localTransform,this.parent._worldTransform,this._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}for(var n=0;n1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},n.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},n.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},n.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},n.prototype.setVelocity=function(t){return this.velocity=t,this},n.prototype.addImpulse=function(e){this.isImmovable||(this.velocity=t.Vector2.add(this.velocity,t.Vector2.multiplyScaler(e,1e5).multiplyScaler(this._inverseMass*t.Time.deltaTime*t.Time.deltaTime)))},n.prototype.onAddedToEntity=function(){this._collider=null;for(var e=0;e0&&(s=t.Vector2.zero);var h=this._friction;return a.lengthSquared()0&&this.collisionState.wasGroundedLastFrame&&(t=this.handleVerticalSlope(t)),0!==t.x&&(t=this.moveHorizontally(t)),0!==t.y&&(t=this.moveVertically(t)),this._player.setPosition(this._player.position.x+t.x,this._player.position.y+t.y),e>0&&(this.velocity.x=t.x/e,this.velocity.y=t.y/e),!this.collisionState.wasGroundedLastFrame&&this.collisionState.below&&(this.collisionState.becameGroundedThisFrame=!0),this._isGoingUpSlope&&(this.velocity.y=0),this._isWarpingToGround||this._triggerHelper.update();for(var n=0;n0&&(this.ignoreOneWayPlatformsTime-=e)},i.prototype.warpToGrounded=function(e){void 0===e&&(e=1e3),this.ignoreOneWayPlatformsTime=0,this._isWarpingToGround=!0;var n=0;do{if(n+=1,this.move(new t.Vector2(0,1),.02),n>e)break}while(!this.isGrounded);this._isWarpingToGround=!1},i.prototype.recalculateDistanceBetweenRays=function(){var t=this._collider.height*Math.abs(this._player.scale.y)-2*this._skinWidth;this._verticalDistanceBetweenRays=t/(this.totalHorizontalRays-1);var e=this._collider.width*Math.abs(this._player.scale.x)-2*this._skinWidth;this._horizontalDistanceBetweenRays=e/(this.totalVerticalRays-1)},i.prototype.primeRaycastOrigins=function(){var e=this._collider.bounds;this._raycastOrigins.topLeft=new t.Vector2(e.x+this._skinWidth,e.y+this._skinWidth),this._raycastOrigins.bottomRight=new t.Vector2(e.right-this._skinWidth,e.bottom-this._skinWidth),this._raycastOrigins.bottomLeft=new t.Vector2(e.x+this._skinWidth,e.bottom-this._skinWidth)},i.prototype.moveHorizontally=function(e){for(var n=e.x>0,i=Math.abs(e.x)+this._skinWidth*this.rayOriginSkinMutiplier,r=n?t.Vector2.right:t.Vector2.left,o=this._raycastOrigins.bottomLeft.y,s=n?this._raycastOrigins.bottomRight.x-this._skinWidth*(this.rayOriginSkinMutiplier-1):this._raycastOrigins.bottomLeft.x+this._skinWidth*(this.rayOriginSkinMutiplier-1),a=0;a0)&&(a&=~this.oneWayPlatformMask);for(var h=0;hthis.jumpingThreshold){var i=this.slopeSpeedMultiplier?this.slopeSpeedMultiplier.lerp(n):1;e.x*=i,e.y=Math.abs(Math.tan(n*t.MathHelper.Deg2Rad)*e.x);var r=e.x>0,o=r?this._raycastOrigins.bottomRight:this._raycastOrigins.bottomLeft,s=null;(s=this.supportSlopedOneWayPlatforms&&this.collisionState.wasGroundedLastFrame?t.Physics.linecastIgnoreCollider(o,o.add(e),this.platformMask,this.ignoredColliders):t.Physics.linecastIgnoreCollider(o,o.add(e),this.platformMask&~this.oneWayPlatformMask,this.ignoredColliders)).collider&&(e.x=s.point.x-o.x,e.y=s.point.y-o.y,r?e.x-=this._skinWidth:e.x+=this._skinWidth),this._isGoingUpSlope=!0,this.collisionState.below=!0}}else e.x=0;return!0},i}();t.CharacterController=i}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,n){var i,r;try{for(var o=__values(e.components._components),s=o.next();!s.done;s=o.next()){var a=s.value;t.isITriggerListener(a)&&n.push(a)}}catch(t){i={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}for(var h in e.components._componentsToAdd){a=e.components._componentsToAdd[h];t.isITriggerListener(a)&&n.push(a)}return n},e}();t.TriggerListenerHelper=e,t.isITriggerListener=function(t){return void 0!==t.onTriggerEnter}}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){for(var i,r,o=null,s=0;sn;n++){var i=t[n];this.processDelta(i,this.acc);var r=this.getRemainingDelay(i);r<=0?this.processExpired(i):this.offerDelay(r)}this.acc=0}else this.stop()},n.prototype.checkProcessing=function(){return!!this.running&&(this.acc+=t.Time.deltaTime,this.acc>=this.delay)},n.prototype.offerDelay=function(t){this.running?this.delay=Math.min(this.delay,t):(this.running=!0,this.delay=t)},n.prototype.getInitialTimeDelay=function(){return this.delay},n.prototype.getRemainingTimeUntilProcessing=function(){return this.running?this.delay-this.acc:0},n.prototype.isRunning=function(){return this.running},n.prototype.stop=function(){this.running=!1,this.acc=0},n}(t.EntitySystem);t.DelayedIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.lateProcessEntity=function(t){},e.prototype.process=function(t){if(0!=t.length)for(var e=0,n=t.length;e=this.interval&&(this.acc-=this.interval,this.intervalDelta=this.acc-this.intervalDelta,!0)},n.prototype.getIntervalDelta=function(){return this.interval+this.intervalDelta},n}(t.EntitySystem);t.IntervalSystem=e}(es||(es={})),function(t){var e=function(t){function e(e,n){return t.call(this,e,n)||this}return __extends(e,t),e.prototype.process=function(t){var e=this;t.forEach(function(t){return e.processEntity(t)})},e}(t.IntervalSystem);t.IntervalIteratingSystem=e}(es||(es={})),function(es){var JobSystem=function(_super){function JobSystem(t,e){var n=_super.call(this,t)||this;n._threads=e,n._jobs=new Array(e);for(var i=0;it.length&&(s=t.length);var a=o._jobs[n];if(a.set(t,r,s,o._executeStr,o),r!=s){var h=es.WorkerUtils.makeWorker(o.queueOnThread);es.WorkerUtils.workerMessage(h)(a).then(function(t){var n=t;e.resetJob(n),h.terminate()}).catch(function(t){a.err=t,h.terminate()})}},o=this,s=0;s-1?eval("(function(){return "+v+" })()"):v}),i=job.from;i0)for(var t=0,e=this._components.length;t0)for(var e=0,n=this._components.length;e0)for(var e=0,n=this._components.length;e0){for(var e=function(t,e){var i=n._componentsToRemoveList[t];n.handleRemove(i);var r=n._components.findIndex(function(t){return t.id==i.id});-1!=r&&n._components.splice(r,1),n.removeComponentsByType(i)},n=this,i=0,r=this._componentsToRemoveList.length;i0){for(i=0,r=this._componentsToAddList.length;i0){for(i=0,r=this._tempBufferList.length;i0){var n=this._updatableComponents.findIndex(function(t){return t.id==e.id});-1!=n&&this._updatableComponents.splice(n,1)}this.decreaseBits(e),this._entity.scene.entityProcessors.onComponentRemoved(this._entity),e.onRemovedFromEntity(),e.entity=null},e.prototype.removeComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsByType.set(t.TypeUtils.getType(e),n)},e.prototype.removeComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsToAddByType.set(t.TypeUtils.getType(e),n)},e.prototype.getComponent=function(t,e){var n=this.componentsByType.get(t);if(n&&n.length>0)return n[0];if(!e){var i=this.componentsToAddByType.get(t);if(i&&i.length>0)return i[0]}return null},e.prototype.getComponents=function(t,e){e||(e=[]);var n=this.componentsByType.get(t);n&&(e=e.concat(n));var i=this.componentsToAddByType.get(t);return i&&(e=e.concat(i)),e},e.prototype.update=function(){if(this.updateLists(),this._updatableComponents.length>0)for(var t=0,e=this._updatableComponents.length;t0)for(var e=0,n=this._components.length;e0)for(e=0,n=this._componentsToAddList.length;e0)for(var t=0,e=this._components.length;t0)for(var t=0,e=this._components.length;t0){for(var t=function(t,n){var i=e._entitiesToRemoveList[t];e.removeFromTagList(i);var r=e._entities.findIndex(function(t){return t.id==i.id});-1!=r&&e._entities.splice(r,1),i.onRemovedFromScene(),i.scene=null,e.scene.entityProcessors.onEntityRemoved(i)},e=this,n=0,i=this._entitiesToRemoveList.length;n0){for(n=0,i=this._entitiesToAddedList.length;n0)for(var e=0,n=this._entities.length;e0)for(e=0,n=this._entitiesToAddedList.length;e0)for(var e=0,n=this._entities.length;e0)try{for(var s=__values(r),a=s.next();!a.done;a=s.next()){var h=a.value;o.push(h)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return o},e.prototype.entityWithTag=function(t){var e,n,i=this.getTagList(t);if(i.size>0)try{for(var r=__values(i),o=r.next();!o.done;o=r.next()){return o.value}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return null},e.prototype.findComponentOfType=function(t){if(this._entities.length>0)for(var e=0,n=this._entities.length;e0)for(e=0;e0)for(var i=0,r=this._entities.length;i0)for(i=0,r=this._entitiesToAddedList.length;i0)for(var i=0,r=this._entities.length;i0)for(var s=0,a=t.length;s0)for(i=0,r=this._entitiesToAddedList.length;i0)for(s=0,a=t.length;s=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i0?this.ids.removeLast():this.nextAvailableId_++},e.prototype.checkIn=function(t){this.ids.add(t)},e}();t.IdentifierPool=e}(es||(es={})),function(t){var e=function(){function e(){this.allSet=[],this.exclusionSet=[],this.oneSet=[]}return e.empty=function(){return new e},e.prototype.getAllSet=function(){return this.allSet},e.prototype.getExclusionSet=function(){return this.exclusionSet},e.prototype.getOneSet=function(){return this.oneSet},e.prototype.isInterestedEntity=function(t){return this.isInterested(t.componentBits)},e.prototype.isInterested=function(e){if(0!=this.allSet.length)for(var n=0,i=this.allSet.length;n0)for(var t=0,e=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function t(){}return t.update=function(t){-1==t&&(t=Date.now()),-1==this._lastTime&&(this._lastTime=t);var e=0;(e=-1==t?(t-this._lastTime)/1e3:t)>this.maxDeltaTime&&(e=this.maxDeltaTime),this.totalTime+=e,this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return this.timeSinceSceneLoad/t>(this.timeSinceSceneLoad-this.deltaTime)/t},t.totalTime=0,t.unscaledDeltaTime=0,t.deltaTime=0,t.timeScale=1,t.maxDeltaTime=Number.MAX_VALUE,t.frameCount=0,t.timeSinceSceneLoad=0,t._lastTime=-1,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,h=Math.floor(a)+1;if(53==h){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var c=n.getDay();if(0==c&&(c=7),e&&(!o||c<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(h>9?"":"0")+h)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),h=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(h="0"+h),n?s+e+a+e+h:a+e+h},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t},t.fromRGBA=function(e,n,i,r){e/=255,n/=255,i/=255;var o=Math.max(e,n,i),s=Math.min(e,n,i),a=(o+s)/2,h=a,c=a;if(o===s)a=h=0;else{var u=o-s;switch(h=c>.5?u/(2-o-s):u/(o+s),o){case e:a=(n-i)/u+(n=1?(e.value=1,n=this._points.length-4):(e.value=t.MathHelper.clamp01(e.value)*this._curveCount,n=~~e,e.value-=n,n*=3),n},e.prototype.setControlPoint=function(e,n){if(e%3==0){var i=t.Vector2.subtract(n,this._points[e]);e>0&&this._points[e-1].addEqual(i),e+1-Math.PI&&t<=Math.PI?t:(t%=2*Math.PI)<=-Math.PI?t+2*Math.PI:t>Math.PI?t-2*Math.PI:t},e.isPowerOfTwo=function(t){return t>0&&t%(t-1)==0},e.lerp=function(t,e,n){return t+(e-t)*this.clamp01(n)},e.betterLerp=function(t,n,i,r){return Math.abs(t-n)180&&(i-=360),t+i*this.clamp01(n)},e.lerpAngleRadians=function(t,e,n){var i=this.repeat(e-t,2*Math.PI);return i>Math.PI&&(i-=2*Math.PI),t+i*this.clamp01(n)},e.pingPong=function(t,e){return t=this.repeat(t,2*e),e-Math.abs(t-e)},e.signThreshold=function(t,e){return Math.abs(t)>=e?Math.sign(t):0},e.inverseLerp=function(t,e,n){if(te)return 1}else{if(nt)return 0}return(n-t)/(e-t)},e.lerpPrecise=function(t,e,n){return(1-n)*t+e*n},e.clamp=function(t,e,n){return tn?n:t},e.snap=function(t,e){return Math.round(t/e)*e},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.isOdd=function(t){return t%2!=0},e.roundWithRoundedAmount=function(t,e){var n=Math.round(t);return e.value=t-n*Math.round(t/n),n},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.angleToVector=function(e,n){return new t.Vector2(Math.cos(e)*n,Math.sin(e)*n)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.decrementWithWrap=function(t,e){return--t<0?e-1:t},e.hypotenuse=function(t,e){return Math.sqrt(t*t+e*e)},e.closestPowerOfTwoGreaterThan=function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,(t|=t>>16)+1},e.roundToNearest=function(t,e){return Math.round(t/e)*e},e.withinEpsilon=function(t,e){return void 0===e&&(e=this.Epsilon),Math.abs(t)180&&(n-=360),n},e.between=function(t,e,n){return t>=e&&t<=n},e.deltaAngleRadians=function(t,e){var n=this.repeat(e-t,2*Math.PI);return n>Math.PI&&(n-=2*Math.PI),n},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.floorToInt=function(t){return Math.trunc(Math.floor(t))},e.rotateAround=function(e,n){var i=t.Time.totalTime*n,r=Math.cos(i),o=Math.sin(i);return new t.Vector2(e.x+r,e.y+o)},e.rotateAround2=function(e,n,i){i=this.toRadians(i);var r=Math.cos(i),o=Math.sin(i),s=r*(e.x-n.x)-o*(e.y-n.y)+n.x,a=o*(e.x-n.x)+r*(e.y-n.y)+n.y;return new t.Vector2(s,a)},e.pointOnCircle=function(e,n,i){var r=this.toRadians(i);return new t.Vector2(Math.cos(r)*n+e.x,Math.sin(r)*n+e.y)},e.pointOnCircleRadians=function(e,n,i){return new t.Vector2(Math.cos(i)*n+e.x,Math.sin(i)*n+e.y)},e.lissajou=function(e,n,i,r,o){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=0);var s=Math.sin(t.Time.totalTime*e+o)*i,a=Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(s,a)},e.lissajouDamped=function(e,n,i,r,o,s,a){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=.5),void 0===s&&(s=0),void 0===a&&(a=5);var h=this.pingPong(t.Time.totalTime,a),c=Math.pow(Math.E,-s*h),u=c*Math.sin(t.Time.totalTime*e+o)*i,l=c*Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(u,l)},e.hermite=function(t,e,n,i,r){return 0==r?t:1==r?n:(2*t-2*n+i+e)*(r*r*r)+(3*n-3*t-2*e-i)*(r*r)+e*r+t},e.isValid=function(t){return!Number.isNaN(t)&&!Number.isFinite(t)},e.smoothDamp=function(t,e,n,i,r,o){var s=2/(i=Math.max(1e-4,i)),a=s*o,h=1/(1+(a+(a*a*.48+a*(a*a)*.235))),c=t-e,u=e,l=r*i,p=(n+s*(c=this.clamp(c,-1*l,l)))*o;n=(n-s*p)*h;var f=(e=t-c)+(c+p)*h;return u-t>0==f>u&&(n=((f=u)-u)/o),{value:f,currentVelocity:n}},e.smoothDampVector=function(e,n,i,r,o,s){var a=t.Vector2.zero,h=this.smoothDamp(e.x,n.x,i.x,r,o,s);a.x=h.value,i.x=h.currentVelocity;var c=this.smoothDamp(e.y,n.y,i.y,r,o,s);return a.y=c.value,i.y=c.currentVelocity,a},e.mapMinMax=function(t,n,i,r,o){return r+(e.clamp(t,n,i)-n)*(o-r)/(i-n)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e.PiOver2=Math.PI/2,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function t(t,e,n,i,r,o,s,a,h,c,u,l,p,f,d,y){this.m11=t,this.m12=e,this.m13=n,this.m14=i,this.m21=r,this.m22=o,this.m23=s,this.m24=a,this.m31=h,this.m32=c,this.m33=u,this.m34=l,this.m41=p,this.m42=f,this.m43=d,this.m44=y}return Object.defineProperty(t,"Identity",{get:function(){return this.identity},enumerable:!0,configurable:!0}),t.createOrthographicOffCenter=function(e,n,i,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(n-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-i),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+n)/(e-n),a.m42=(r+i)/(i-r),a.m43=o/(o-s),a.m44=1},t.createTranslation=function(t,e){e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=t.x,e.m42=t.y,e.m43=0,e.m44=1},t.createRotationZ=function(e,n){n=t.Identity;var i=Math.cos(e),r=Math.sin(e);n.m11=i,n.m12=r,n.m21=-r,n.m22=i},t.multiply=function(e,n,i){void 0===i&&(i=new t);var r=e.m11*n.m11+e.m12*n.m21+e.m13*n.m31+e.m14*n.m41,o=e.m11*n.m12+e.m12*n.m22+e.m13*n.m32+e.m14*n.m42,s=e.m11*n.m13+e.m12*n.m23+e.m13*n.m33+e.m14*n.m43,a=e.m11*n.m14+e.m12*n.m24+e.m13*n.m34+e.m14*n.m44,h=e.m21*n.m11+e.m22*n.m21+e.m23*n.m31+e.m24*n.m41,c=e.m21*n.m12+e.m22*n.m22+e.m23*n.m32+e.m24*n.m42,u=e.m21*n.m13+e.m22*n.m23+e.m23*n.m33+e.m24*n.m43,l=e.m21*n.m14+e.m22*n.m24+e.m23*n.m34+e.m24*n.m44,p=e.m31*n.m11+e.m32*n.m21+e.m33*n.m31+e.m34*n.m41,f=e.m31*n.m12+e.m32*n.m22+e.m33*n.m32+e.m34*n.m42,d=e.m31*n.m13+e.m32*n.m23+e.m33*n.m33+e.m34*n.m43,y=e.m31*n.m14+e.m32*n.m24+e.m33*n.m34+e.m34*n.m44,m=e.m41*n.m11+e.m42*n.m21+e.m43*n.m31+e.m44*n.m41,g=e.m41*n.m12+e.m42*n.m22+e.m43*n.m32+e.m44*n.m42,_=e.m41*n.m13+e.m42*n.m23+e.m43*n.m33+e.m44*n.m43,v=e.m41*n.m14+e.m42*n.m24+e.m43*n.m34+e.m44*n.m44;i.m11=r,i.m12=o,i.m13=s,i.m14=a,i.m21=h,i.m22=c,i.m23=u,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=y,i.m41=m,i.m42=g,i.m43=_,i.m44=v},t.identity=new t(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t}();t.Matrix=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i,r,o){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=n,this.m22=i,this.m31=r,this.m32=o}return Object.defineProperty(e,"identity",{get:function(){return new e(1,0,0,1,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m22=t.y},enumerable:!0,configurable:!0}),e.createRotation=function(t){var e=this.identity,n=Math.cos(t),i=Math.sin(t);return e.m11=n,e.m12=i,e.m21=-i,e.m22=n,e},e.createRotationOut=function(t,e){var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-i,e.m22=n},e.createScale=function(t,e){var n=this.identity;return n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0,n},e.createScaleOut=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createTranslation=function(t,e){var n=this.identity;return n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=t,n.m32=e,n},e.createTranslationOut=function(t,e){e.m11=1,e.m12=0,e.m21=0,e.m22=1,e.m31=t.x,e.m32=t.y},e.invert=function(t){var e=1/t.determinant(),n=this.identity;return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.multiply=function(t,e,n){var i=t.m11*e.m11+t.m12*e.m21,r=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,s=t.m21*e.m12+t.m22*e.m22,a=t.m31*e.m11+t.m32*e.m21+e.m31,h=t.m31*e.m12+t.m32*e.m22+e.m32;return n.m11=i,n.m12=r,n.m21=o,n.m22=s,n.m31=a,n.m32=h,n},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,n){return t.m11=t.m11+(e.m11-t.m11)*n,t.m12=t.m12+(e.m12-t.m12)*n,t.m21=t.m21+(e.m21-t.m21)*n,t.m22=t.m22+(e.m22-t.m22)*n,t.m31=t.m31+(e.m31-t.m31)*n,t.m32=t.m32+(e.m32-t.m32)*n,t},e.transpose=function(t){var e=this.identity;return e.m11=t.m11,e.m12=t.m21,e.m21=t.m12,e.m22=t.m22,e.m31=0,e.m32=0,e},e.prototype.mutiplyTranslation=function(n,i){var r=e.createTranslation(n,i);return t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var n=new t.Matrix;return n.m11=e.m11,n.m12=e.m12,n.m13=0,n.m14=0,n.m21=e.m21,n.m22=e.m22,n.m23=0,n.m24=0,n.m31=0,n.m32=0,n.m33=1,n.m34=0,n.m41=e.m31,n.m42=e.m32,n.m43=0,n.m44=1,n},e.prototype.toString=function(){return"{m11:"+this.m11+" m12:"+this.m12+" m21:"+this.m21+" m22:"+this.m22+" m31:"+this.m31+" m32:"+this.m32+"}"},e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(){function e(){}return e.add=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11+n.m11,i.m12=e.m12+n.m12,i.m21=e.m21+n.m21,i.m22=e.m22+n.m22,i.m31=e.m31+n.m31,i.m32=e.m32+n.m32,i},e.divide=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11/n.m11,i.m12=e.m12/n.m12,i.m21=e.m21/n.m21,i.m22=e.m22/n.m22,i.m31=e.m31/n.m31,i.m32=e.m32/n.m32,i},e.mutiply=function(e,n){var i=t.Matrix2D.identity;if(n instanceof t.Matrix2D){var r=e.m11*n.m11+e.m12*n.m21,o=n.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,h=e.m31*n.m11+e.m32*n.m21+n.m31,c=e.m31*n.m12+e.m32*n.m22+n.m32;i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=h,i.m32=c}else"number"==typeof n&&(i.m11=e.m11*n,i.m12=e.m12*n,i.m21=e.m21*n,i.m22=e.m22*n,i.m31=e.m31*n,i.m32=e.m32*n);return i},e.subtract=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11-n.m11,i.m12=e.m12-n.m12,i.m21=e.m21-n.m21,i.m22=e.m22-n.m22,i.m31=e.m31-n.m31,i.m32=e.m32-n.m32,i},e}();t.MatrixHelper=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.x=0,this.y=0,this.width=0,this.height=0,this.x=t,this.y=e,this.width=n,this.height=i}return Object.defineProperty(e,"empty",{get:function(){return new e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"maxRect",{get:function(){return new e(Number.MIN_VALUE/2,Number.MIN_VALUE/2,Number.MAX_VALUE,Number.MAX_VALUE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.isEmpty=function(){return 0==this.width&&0==this.height&&0==this.x&&0==this.y},Object.defineProperty(e.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),e.fromMinMax=function(t,n,i,r){return new e(t,n,i-t,r-n)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;oi&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return!1}else{var i=1/t.direction.x,r=(this.x-t.start.x)*i,o=(this.x+this.width-t.start.x)*i;if(r>o){var s=r;r=o,o=s}if(e.value=Math.max(r,e.value),n=Math.min(o,n),e.value>n)return!1}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return!1}else{var a=1/t.direction.y,h=(this.y-t.start.y)*a,c=(this.y+this.height-t.start.y)*a;if(h>c){var u=h;h=c,c=u}if(e.value=Math.max(h,e.value),n=Math.max(c,n),e.value>n)return!1}return!0},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,i.y=n>0?this.y:this.y+n,i.width=t>0?t+this.width:this.width-t,i.height=n>0?n+this.height:this.height-n,i},e.prototype.collisionCheck=function(t,e,n){e.value=n.value=0;var i=t.x-(this.x+this.width),r=t.x+t.width-this.x,o=t.y-(this.y+this.height),s=t.y+t.height-this.y;return!(i>0||r<0||o>0||s<0)&&(e.value=Math.abs(i)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return Math.trunc(this.x)^Math.trunc(this.y)^Math.trunc(this.width)^Math.trunc(this.height)},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.HashSet,this._previousTriggerIntersections=new t.HashSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(h.x*o.y-h.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r,o){void 0===o&&(o=t.Vector2.zero),o.x=0,o.y=0;var s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),h=s.x*a.y-s.y*a.x;if(0==h)return!1;var c=t.Vector2.subtract(i,e),u=(c.x*a.y-c.y*a.x)/h;if(u<0||u>1)return!1;var l=(c.x*s.y-c.y*s.x)/h;if(l<0||l>1)return!1;var p=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y));return o.x=p.x,o.y=p.y,!0},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.circleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setValues=function(t,e,n,i){this.collider=t,this.fraction=e,this.distance=n,this.point=i},e.prototype.setValuesNonCollider=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.setAllValues=function(t,e,n,i,r){this.collider=t,this.fraction=e,this.distance=n,this.point=i,this.normal=r},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.clone=function(){var t=new e;return t.setAllValues(this.collider,this.fraction,this.distance,this.point,this.normal),t},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset(),this._colliderArray[0]=null},e.clear=function(){this._spatialHash.clear()},e.debugDraw=function(t){this.debugRender&&this._spatialHash.debugDraw(t)},e.overlapCircle=function(t,n,i){return void 0===i&&(i=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapCircle(t,n,this._colliderArray,i),this._colliderArray[0]},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.warn("传入了一个空的结果数组。不会返回任何结果")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var n=t.bounds;return this._spatialHash.aabbBroadphase(n,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,n,i,r){void 0===r&&(r=e.allLayers);var o=t.bounds.getSweptBroadphaseBounds(n,i);return this._spatialHash.aabbBroadphase(o,t,r)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.linecast=function(t,n,i){return void 0===i&&(i=e.allLayers),this._hitArray[0].reset(),this.linecastAll(t,n,this._hitArray,i),this._hitArray[0]},e.linecastIgnoreCollider=function(t,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._hitArray[0].reset(),e.linecastAllIgnoreCollider(t,n,this._hitArray,i,r),this._hitArray[0].clone()},e.linecastAll=function(t,n,i,r){return void 0===r&&(r=e.allLayers),0==i.length?(console.warn("传入了一个空的hits数组。没有点击会被返回"),0):this._spatialHash.linecast(t,n,i,r)},e.linecastAllIgnoreCollider=function(t,e,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._spatialHash.linecastIgnoreCollider(t,e,n,i,r)},e.overlapRectangle=function(t,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,n),this._colliderArray[0]},e.overlapRectangleAll=function(t,n,i){return void 0===i&&(i=e.allLayers),0==n.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,n,i)},e.gravity=new t.Vector2(0,-300),e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e.debugRender=!1,e._hitArray=[new t.RaycastHit],e._colliderArray=[null],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(e,n){this.start=e,this.end=n,this.direction=t.Vector2.subtract(this.end,this.start)}}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestBox=new t.Box(0,0),this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds.clone();e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(e){for(var n=e.registeredPhysicsBounds.clone(),i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom),o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){var a=this.cellAtPosition(o,s);t.Insist.isNotNull(a,"从不存在碰撞器的单元格中移除碰撞器: ["+e+"]"),null!=a&&new t.List(a).remove(e)}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.debugDraw=function(t){for(var e=this.gridBounds.x;e<=this.gridBounds.right;e++)for(var n=this.gridBounds.y;n<=this.gridBounds.bottom;n++){var i=this.cellAtPosition(e,n);null!=i&&i.length>0&&this.debugDrawCellDetails(e,n,t)}},e.prototype.debugDrawCellDetails=function(e,n,i){void 0===i&&(i=.5),t.Graphics.instance.batcher.drawHollowRect(e*this._cellSize,n*this._cellSize,this._cellSize,this._cellSize,new t.Color(255,0,0),i),t.Graphics.instance.batcher.end()},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.clear();for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var h=this.cellAtPosition(s,a);if(h)for(var c=0;c0?1:0),f=(h+(u>0?1:0)-e.x)/s.direction.x,d=(p-e.y)/s.direction.y;0!==s.direction.x&&0!==u||(f=Number.POSITIVE_INFINITY),0!==s.direction.y&&0!==l||(d=Number.POSITIVE_INFINITY);var y=u/s.direction.x,m=l/s.direction.y,g=this.cellAtPosition(h,c);if(g&&this._raycastParser.checkRayIntersection(h,c,g))return this._raycastParser.reset(),this._raycastParser.hitCounter;for(var _=0;(h!==a.x||c!==a.y)&&_<100;){if(f=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;rr&&(r=s,i=o)}return e[i]},n.getClosestPointOnPolygonToPoint=function(e,n,i,r){i.value=Number.MAX_VALUE,r.x=0,r.y=0;for(var o=t.Vector2.zero,s=0,a=0;at.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o1)return!1;var a,h=t.Vector2.add(s.start,t.Vector2.multiplyScaler(s.direction,r.value)),c=0;h.xn.bounds.right&&(c|=1),h.yn.bounds.bottom&&(c|=2);var u=a+c;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,n){var i=t.Vector2.zero;return i.x=0==(1&n)?e.right:e.left,i.y=0==(1&n)?e.bottom:e.top,i},e.testCircleBox=function(e,n,i){i=n.bounds.getClosestPointOnRectangleToPoint(e.position);var r=t.Vector2.subtract(i,e.position);return t.Vector2.dot(r,r)<=e.radius*e.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.boxToBox=function(e,n,i){var r=this.minkowskiDifference(e,n);return!!r.contains(0,0)&&(i.minimumTranslationVector=r.getClosestPointOnBoundsToOrigin(),!i.minimumTranslationVector.equals(t.Vector2.zero)&&(i.normal=new t.Vector2(-i.minimumTranslationVector.x,-i.minimumTranslationVector.y),i.normal.normalize(),!0))},e.boxToBoxCast=function(e,n,i,r){var o=this.minkowskiDifference(e,n);if(o.contains(0,0)){var s=o.getClosestPointOnBoundsToOrigin();return!s.equals(t.Vector2.zero)&&(r.normal=new t.Vector2(-s.x,-s.y),r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,new t.Vector2(-i.x,-i.y)),h=new t.Ref(0);return!!(o.rayIntersects(a,h)&&h.value<=1)&&(r.fraction=h.value,r.distance=i.length()*h.value,r.normal=new t.Vector2(-i.x,-i.y),r.normal.normalize(),r.centroid=t.Vector2.add(e.bounds.center,t.Vector2.multiplyScaler(i,h.value)),!0)},e.minkowskiDifference=function(e,n){var i=t.Vector2.subtract(e.position,t.Vector2.add(e.bounds.location,new t.Vector2(e.bounds.size.x/2,e.bounds.size.y/2))),r=t.Vector2.subtract(t.Vector2.add(e.bounds.location,i),n.bounds.max),o=t.Vector2.add(e.bounds.size,n.bounds.size);return new t.Rectangle(r.x,r.y,o.x,o.y)},e}();t.ShapeCollisionsBox=e}(es||(es={})),function(t){var e=function(){function e(){}return e.circleToCircle=function(e,n,i){void 0===i&&(i=new t.CollisionResult);var r=t.Vector2.distanceSquared(e.position,n.position),o=e.radius+n.radius;if(re.radius*e.radius&&!h)return!1;if(h)r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(s.value)-e.radius));else if(0==s.value)r=new t.Vector2(i.normal.x*e.radius,i.normal.y*e.radius);else{var c=Math.sqrt(s.value);r=t.Vector2.multiplyScaler(t.Vector2.subtract(o,a),-1).multiply(new t.Vector2((e.radius-c)/c))}return i.minimumTranslationVector=r,i.point=t.Vector2.add(a,n.position),!0},e.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,t.Vector2.multiplyScaler(r,s))},e}();t.ShapeCollisionsCircle=e}(es||(es={})),function(t){var e=function(){function e(){}return e.lineToPoly=function(e,n,i,r){void 0===r&&(r=new t.RaycastHit);for(var o=t.Vector2.zero,s=t.Vector2.zero,a=Number.MAX_VALUE,h=!1,c=i.points.length-1,u=0;u1)return!1;var l=(c.x*s.y-c.y*s.x)/h;if(l<0||l>1)return!1;var p=t.Vector2.add(e,t.Vector2.multiplyScaler(s,u));return o.x=p.x,o.y=p.y,!0},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divideScaler(t.Vector2.subtract(n,e),o),a=t.Vector2.subtract(e,i.position),h=t.Vector2.dot(a,s),c=t.Vector2.dot(a,a)-i.radius*i.radius;if(c>0&&h>0)return!1;var u=h*h-c;return!(u<0)&&(r.fraction=-h-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=t.Vector2.add(e,t.Vector2.multiplyScaler(s,r.fraction)),r.distance=t.Vector2.distance(e,r.point),r.normal=t.Vector2.normalize(t.Vector2.subtract(r.point,i.position)),r.fraction=r.distance/o,!0)},e}();t.ShapeCollisionsLine=e}(es||(es={})),function(t){var e=function(){function e(){}return e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&(o=!1),!o)return!1;(p=Math.abs(p))r.max&&(r.max=i);return r},e.intervalDistance=function(t,e,n,i){return t= 2");if(t.sort(function(t,e){return t.t-e.t}),0!==t[0].t)throw new Error("curve must start with 0");if(1!==t[t.length-1].t)throw new Error("curve must end with 1");this._points=t}return Object.defineProperty(e.prototype,"points",{get:function(){return this._points},enumerable:!0,configurable:!0}),e.prototype.lerp=function(e){for(var n=1;n=0;o--)(e=r[o].func).call.apply(e,__spread([r[o].context],n))},n}();t.Emitter=n}(es||(es={})),function(t){!function(t){t[t.top=0]="top",t[t.bottom=1]="bottom",t[t.left=2]="left",t[t.right=3]="right"}(t.Edge||(t.Edge={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.default=function(){return new t},t.prototype.equals=function(t,e){return"function"==typeof t.equals?t.equals(e):t===e},t.prototype.getHashCode=function(t){var e=this;if("number"==typeof t)return this._getHashCodeForNumber(t);if("string"==typeof t)return this._getHashCodeForString(t);var n=385229220;return this.forOwn(t,function(t){"number"==typeof t?n+=e._getHashCodeForNumber(t):"string"==typeof t?n+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){n+=e.getHashCode(t)})}),n},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,n=0;n>7,n+=n<<3,n^=n>>17,n+=n<<5},t}();t.Hash=e}(es||(es={})),function(t){var e=function(){function t(){this._listeners=[]}return t.prototype.addListener=function(t,e){-1===this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t})&&this._listeners.push({caller:t,callback:e})},t.prototype.removeListener=function(t,e){var n=this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t});n>=0&&this._listeners.splice(n,1)},t.prototype.clearListener=function(){this._listeners=[]},t.prototype.clearListenerWithCaller=function(t){for(var e=this._listeners.length-1;e>=0;e--){this._listeners[e].caller===t&&this._listeners.splice(e,1)}},t.prototype.notify=function(){for(var t,e=[],n=0;n=0;i--){var r=this._listeners[i];r.caller?(t=r.callback).call.apply(t,__spread([r.caller],e)):r.callback.apply(r,__spread(e))}},t}();t.Observable=e;var n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e){t.prototype.notify.call(this,e)},e}(e);t.ObservableT=n;var i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e,n){t.prototype.notify.call(this,e,n)},e}(e);t.ObservableTT=i;var r=function(){function t(t,n){this.bindAction(t,n),this._onExec=new e}return t.prototype.bindAction=function(t,e){this._caller=t,this._action=e},t.prototype.dispatch=function(){for(var t,e=[],n=0;n3&&o<500;){o++;var a=!0,h=n[this._triPrev[s]],c=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(h,c,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],h,c,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.length>8&255]+e[t>>16&255]+e[t>>24&255]+"-"+e[255&n]+e[n>>8&255]+"-"+e[n>>16&15|64]+e[n>>24&255]+"-"+e[63&i|128]+e[i>>8&255]+"-"+e[i>>16&255]+e[i>>24&255]+e[255&r]+e[r>>8&255]+e[r>>16&255]+e[r>>24&255]},t}();t.UUID=n}(es||(es={})),function(t){t.getClassName=function(t){return t.className||t.name}}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return __spread(this._completeSlices,[this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(es||(es={})),function(t){var e=function(){function t(t){void 0===t&&(t=64),this.size_=0,this.length=0,this.array=[],this.length=t}return t.prototype.removeAt=function(t){var e=this.array[t];return this.array[t]=this.array[--this.size_],this.array[this.size_]=null,e},t.prototype.remove=function(t){var e,n=this.size_;for(e=0;e0){var t=this.array[--this.size_];return this.array[this.size_]=null,t}return null},t.prototype.contains=function(t){var e,n;for(e=0,n=this.size_;n>e;e++)if(t===this.array[e])return!0;return!1},t.prototype.removeAll=function(t){var e,n,i,r,o=!1;for(e=0,i=t.size();e=this.length)throw new Error("ArrayIndexOutOfBoundsException");return this.array[t]},t.prototype.safeGet=function(t){return t>=this.length&&this.grow(7*t/4+1),this.array[t]},t.prototype.size=function(){return this.size_},t.prototype.getCapacity=function(){return this.length},t.prototype.isIndexWithinBounds=function(t){return t=this.length&&this.grow(2*t),this.size_=t+1,this.array[t]=e},t.prototype.grow=function(t){void 0===t&&(t=1+~~(3*this.length/2)),this.length=~~t},t.prototype.ensureCapacity=function(t){t>=this.length&&this.grow(2*t)},t.prototype.clear=function(){var t,e;for(t=0,e=this.size_;te;e++)this.add(t.get(e))},t}();t.Bag=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=1),this._freeValueCellIndex=0,this._collisions=0,this._valuesInfo=new Array(e),this._values=new Array(e),this._buckets=new Array(t.HashHelpers.getPrime(e))}return e.prototype.getValuesArray=function(t){return t.value=this._freeValueCellIndex,this._values},Object.defineProperty(e.prototype,"valuesArray",{get:function(){return this._values},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"count",{get:function(){return this._freeValueCellIndex},enumerable:!0,configurable:!0}),e.prototype.add=function(t,e){if(!this.addValue(t,e,{value:0}))throw new Error("key 已经存在")},e.prototype.addValue=function(i,r,o){var s=t.HashHelpers.getHashCode(i),a=e.reduce(s,this._buckets.length);if(this._freeValueCellIndex==this._values.length){var h=t.HashHelpers.expandPrime(this._freeValueCellIndex);this._values.length=h,this._valuesInfo.length=h}var c=t.NumberExtension.toNumber(this._buckets[a])-1;if(-1==c)this._valuesInfo[this._freeValueCellIndex]=new n(i,s);else{var u=c;do{if(this._valuesInfo[u].hashcode==s&&this._valuesInfo[u].key==i)return this._values[u]=r,o.value=u,!1;u=this._valuesInfo[u].previous}while(-1!=u);this._collisions++,this._valuesInfo[this._freeValueCellIndex]=new n(i,s,c),this._valuesInfo[c].next=this._freeValueCellIndex}if(this._buckets[a]=this._freeValueCellIndex+1,this._values[this._freeValueCellIndex]=r,o.value=this._freeValueCellIndex,this._freeValueCellIndex++,this._collisions>this._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){return function(t,e){this.element=t,this.next=e}}();function n(t,e){return t===e}t.Node=e,t.defaultEquals=n;var i=function(){function t(t){void 0===t&&(t=n),this.count=0,this.next=void 0,this.equalsFn=t,this.head=null}return t.prototype.push=function(t){var n,i=new e(t);if(null==this.head)this.head=i;else{for(n=this.head;null!=n.next;)n=n.next;n.next=i}this.count++},t.prototype.removeAt=function(t){if(t>=0&&t=0&&t<=this.count){for(var e=this.head,n=0;n=0&&n<=this.count){var i=new e(t);if(0===n)i.next=this.head,this.head=i;else{var r=this.getElementAt(n-1);i.next=r.next,r.next=i}return this.count++,!0}return!1},t.prototype.indexOf=function(t){for(var e=this.head,n=0;n0)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}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.first=t,this.second=e}return e.prototype.clear=function(){this.first=this.second=null},e.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},e.prototype.getHashCode=function(){return 37*t.EqualityComparer.default().getHashCode(this.first)+t.EqualityComparer.default().getHashCode(this.second)},e}();t.Pair=e}(es||(es={})),function(t){var e=function(){function e(){}return e.warmCache=function(t,e){if((e-=this._objectQueue.length)>0)for(var n=0;nthis._objectQueue.length;)this._objectQueue.shift()},e.clearCache=function(){this._objectQueue.length=0},e.obtain=function(t){return this._objectQueue.length>0?this._objectQueue.shift():new t},e.free=function(e){this._objectQueue.unshift(e),t.isIPoolable(e)&&e.reset()},e._objectQueue=[],e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.getHashCode=function(t){return t.getHashCode()},e.prototype.areEqual=function(t,e){return t.equals(e)},e}(function(){function t(t){var e=this;this.clear(),t&&t.forEach(function(t){e.add(t)})}return t.prototype.add=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i){var r=new Array;return r.push(t),this.buckets[n]=r,this.count=this.count+1,!0}return!i.some(function(n){return e.areEqual(n,t)})&&(i.push(t),this.count=this.count+1,!0)},t.prototype.remove=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i)return!1;var r=!1,o=new Array;return i.forEach(function(n){e.areEqual(n,t)?r=!0:o.push(t)}),this.buckets[n]=o,r&&(this.count=this.count-1),r},t.prototype.contains=function(t){return this.bucketsContains(this.buckets,t)},t.prototype.getCount=function(){return this.count},t.prototype.clear=function(){this.buckets=new Array,this.count=0},t.prototype.toArray=function(){var t=new Array;return this.buckets.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},t.prototype.exceptWith=function(t){var e=this;t&&t.forEach(function(t){e.remove(t)})},t.prototype.intersectWith=function(t){var e=this;if(t){var n=this.buildInternalBuckets(t);this.toArray().forEach(function(t){e.bucketsContains(n.Buckets,t)||e.remove(t)})}else this.clear()},t.prototype.unionWith=function(t){var e=this;t.forEach(function(t){e.add(t)})},t.prototype.isSubsetOf=function(t){var e=this,n=this.buildInternalBuckets(t);return this.toArray().every(function(t){return e.bucketsContains(n.Buckets,t)})},t.prototype.isSupersetOf=function(t){var e=this;return t.every(function(t){return e.contains(t)})},t.prototype.overlaps=function(t){var e=this;return t.some(function(t){return e.contains(t)})},t.prototype.setEquals=function(t){var e=this;return this.buildInternalBuckets(t).Count===this.count&&t.every(function(t){return e.contains(t)})},t.prototype.buildInternalBuckets=function(t){var e=this,n=new Array,i=0;return t.forEach(function(t){var r=e.getHashCode(t),o=n[r];if(void 0===o){var s=new Array;s.push(t),n[r]=s,i+=1}else o.some(function(n){return e.areEqual(n,t)})||(o.push(t),i+=1)}),{Buckets:n,Count:i}},t.prototype.bucketsContains=function(t,e){var n=this,i=t[this.getHashCode(e)];return void 0!==i&&i.some(function(t){return n.areEqual(t,e)})},t}());t.HashSet=e}(es||(es={})),function(t){var e=function(){function t(){}return t.waitForSeconds=function(t){return n.waiter.wait(t)},t}();t.Coroutine=e;var n=function(){function t(){this.waitTime=0}return t.prototype.wait=function(e){return t.waiter.waitTime=e,t.waiter},t.waiter=new t,t}();t.WaitForSeconds=n}(es||(es={})),function(t){var e=function(){function t(){this.waitTimer=0,this.useUnscaledDeltaTime=!1}return t.prototype.stop=function(){this.isDone=!0},t.prototype.setUseUnscaledDeltaTime=function(t){return this.useUnscaledDeltaTime=t,this},t.prototype.prepareForUse=function(){this.isDone=!1},t.prototype.reset=function(){this.isDone=!0,this.waitTimer=0,this.waitForCoroutine=null,this.enumerator=null,this.useUnscaledDeltaTime=!1},t}();t.CoroutineImpl=e;var n=function(n){function i(){var t=null!==n&&n.apply(this,arguments)||this;return t._unblockedCoroutines=[],t._shouldRunNextFrame=[],t}return __extends(i,n),i.prototype.startCoroutine=function(n){var i=t.Pool.obtain(e);return i.prepareForUse(),i.enumerator=n,this.tickCoroutine(i)?(this._isInUpdate?this._shouldRunNextFrame.push(i):this._unblockedCoroutines.push(i),i):null},i.prototype.update=function(){this._isInUpdate=!0;for(var e=0;e0?(n.waitTimer-=n.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime,this._shouldRunNextFrame.push(n)):this.tickCoroutine(n)&&this._shouldRunNextFrame.push(n)}}var i=new t.List(this._unblockedCoroutines);i.clear(),i.addRange(this._shouldRunNextFrame),this._shouldRunNextFrame.length=0,this._isInUpdate=!1},i.prototype.tickCoroutine=function(n){var i=n.enumerator.next();return i.done||n.isDone?(t.Pool.free(n),!1):null==i.value||(i.value instanceof t.WaitForSeconds?(n.waitTimer=i.value.waitTime,!0):"number"==typeof i.value?(n.waitTimer=i.value,!0):"string"==typeof i.value?"break"!=i.value||(t.Pool.free(n),!1):!(i.value instanceof e)||(n.waitForCoroutine=i.value,!0))},i}(t.GlobalManager);t.CoroutineManager=n}(es||(es={})),function(t){var e=function(){function e(t,e,n){void 0===n&&(n=!0),this.binWidth=0,this.binHeight=0,this.usedRectangles=[],this.freeRectangles=[],this.init(t,e,n)}return e.prototype.init=function(e,n,i){void 0===i&&(i=!0),this.binWidth=e,this.binHeight=n,this.allowRotations=i;var r=new t.Rectangle;r.x=0,r.y=0,r.width=e,r.height=n,this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(r)},e.prototype.insert=function(e,n){var i=new t.Rectangle,r=new t.Ref(0),o=new t.Ref(0);if(0==(i=this.findPositionForNewNodeBestAreaFit(e,n,r,o)).height)return i;for(var s=this.freeRectangles.length,a=0;a=e&&this.freeRectangles[s].height>=n){var h=Math.abs(this.freeRectangles[s].width-e),c=Math.abs(this.freeRectangles[s].height-n),u=Math.min(h,c);(a=n&&this.freeRectangles[s].height>=e){h=Math.abs(this.freeRectangles[s].width-n),c=Math.abs(this.freeRectangles[s].height-e),u=Math.min(h,c);(a=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y)return!1;if(e.xt.x){if(e.y>t.y&&e.yt.y){var n;if(e.x>t.x&&e.x=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height},e}();t.MaxRectsBinPack=e}(es||(es={})),function(t){var e=function(){function e(){}return e.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},e.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},e.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},e.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},e.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},e.cloneList=function(t){return t?t.slice(0,t.length):null},e.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},e.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},e.shuffle=function(e){for(var n=e.length;n>1;){n--;var i=t.RandomUtils.randint(0,n+1),r=e[i];e[i]=e[n],e[n]=r}},e.addIfNotPresent=function(e,n){return!new t.List(e).contains(n)&&(e.push(n),!0)},e.lastItem=function(t){return t[t.length-1]},e.randomItem=function(e){return e[t.RandomUtils.randint(0,e.length-1)]},e.randomItems=function(e,n){for(var i=new Set;i.size!=n;){var r=this.randomItem(e);i.has(r)||i.add(r)}var o=t.ListPool.obtain();return i.forEach(function(t){return o.push(t)}),o},e}();t.ArrayUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],h=0;h>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(h++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(h++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(n)),64!==s&&a.push(String.fromCharCode(i));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,n,i,r,o,s,a,h=[],c=0;c>2,o=(3&e)<<4|(n=t.charCodeAt(c++))>>4,s=(15&n)<<2|(i=t.charCodeAt(c++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),h.push(this._keyStr.charAt(r)),h.push(this._keyStr.charAt(o)),h.push(this._keyStr.charAt(s)),h.push(this._keyStr.charAt(a));return h=h.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random().5?1:-1},t}();t.RandomUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,i.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e.boundsFromPolygonVector=function(e){for(var n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,s=0;sr&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(n,i),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,n){return new t.Rectangle(e.x,e.y,n.x-e.x,n.y-e.y)},e.getSweptBroadphaseBounds=function(e,n,i){var r=t.Rectangle.empty;return r.x=n>0?e.x:e.x+n,r.y=i>0?e.y:e.y+i,r.width=n>0?n+e.width:e.width-n,r.height=i>0?i+e.height:e.height-i,r},e.prototype.collisionCheck=function(t,e,n,i){n.value=i.value=0;var r=e.x-(t.x+t.width),o=e.x+e.width-t.x,s=e.y-(t.y+t.height),a=e.y+e.height-t.y;return!(r>0||o<0||s>0||a<0)&&(n.value=Math.abs(r)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e.getClosestPointOnBoundsToOrigin=function(e){var n=this.getMax(e),i=Math.abs(e.location.x),r=new t.Vector2(e.location.x,0);return Math.abs(n.x)r&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(Math.trunc(n),Math.trunc(i)),new t.Vector2(Math.trunc(r),Math.trunc(o)))},e.calculateBounds=function(e,n,i,r,o,s,a,h){if(0==s)e.x=Math.trunc(n.x+i.x-r.x*o.x),e.y=Math.trunc(n.y+i.y-r.y*o.y),e.width=Math.trunc(a*o.x),e.height=Math.trunc(h*o.y);else{var c=n.x+i.x,u=n.y+i.y,l=void 0,p=t.Matrix2D.createTranslation(-c-r.x,-u-r.y);l=t.Matrix2D.createScale(o.x,o.y),p=p.multiply(l),l=t.Matrix2D.createRotation(s),p=p.multiply(l),l=t.Matrix2D.createTranslation(c,u),p=p.multiply(l);var f=new t.Vector2(c,u),d=new t.Vector2(c+a,u),y=new t.Vector2(c,u+h),m=new t.Vector2(c+a,u+h);t.Vector2Ext.transformR(f,p,f),t.Vector2Ext.transformR(d,p,d),t.Vector2Ext.transformR(y,p,y),t.Vector2Ext.transformR(m,p,m);var g=Math.trunc(Math.min(f.x,m.x,d.x,y.x)),_=Math.trunc(Math.max(f.x,m.x,d.x,y.x)),v=Math.trunc(Math.min(f.y,m.y,d.y,y.y)),b=Math.trunc(Math.max(f.y,m.y,d.y,y.y));e.location=new t.Vector2(g,v),e.width=Math.trunc(_-g),e.height=Math.trunc(b-v)}},e.scale=function(t,e){t.x=Math.trunc(t.x*e.x),t.y=Math.trunc(t.y*e.y),t.width=Math.trunc(t.width*e.x),t.height=Math.trunc(t.height*e.y)},e.translate=function(t,e){t.location.addEqual(e)},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function t(){}return t.premultiplyAlpha=function(t){for(var e=t[0],n=0;nt.MathHelper.Epsilon?e.divideScaler(n):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){return this.sum(t)/this.count(t)},e.prototype.cast=function(){return new e(this._elements)},e.prototype.clear=function(){this._elements.length=0},e.prototype.concat=function(t){return new e(this._elements.concat(t.toArray()))},e.prototype.contains=function(t){return this.any(function(e){return e===t})},e.prototype.count=function(t){return t?this.where(t).count():this._elements.length},e.prototype.defaultIfEmpty=function(t){return this.count()?this:new e([t])},e.prototype.distinctBy=function(t){var n=this.groupBy(t);return Object.keys(n).reduce(function(t,e){return t.add(n[e][0]),t},new e)},e.prototype.elementAt=function(t){if(t=0)return this._elements[t];throw new Error("ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.")},e.prototype.elementAtOrDefault=function(t){return t=0?this._elements[t]:void 0},e.prototype.except=function(t){return this.where(function(e){return!t.contains(e)})},e.prototype.first=function(t){if(this.count())return t?this.where(t).first():this._elements[0];throw new Error("InvalidOperationException: The source sequence is empty.")},e.prototype.firstOrDefault=function(t){return this.count(t)?this.first(t):void 0},e.prototype.forEach=function(t){return this._elements.forEach(t)},e.prototype.groupBy=function(t,e){void 0===e&&(e=function(t){return t});return this.aggregate(function(n,i){var r=t(i),o=n[r],s=e(i);return o?o.push(s):n[r]=[s],n},{})},e.prototype.groupJoin=function(t,e,n,i){return this.select(function(r){return i(r,t.where(function(t){return e(r)===n(t)}))})},e.prototype.indexOf=function(t){return this._elements.indexOf(t)},e.prototype.insert=function(t,e){if(t<0||t>this._elements.length)throw new Error("Index is out of range.");this._elements.splice(t,0,e)},e.prototype.intersect=function(t){return this.where(function(e){return t.contains(e)})},e.prototype.join=function(t,e,n,i){return this.selectMany(function(r){return t.where(function(t){return n(t)===e(r)}).select(function(t){return i(r,t)})})},e.prototype.last=function(t){if(this.count())return t?this.where(t).last():this._elements[this.count()-1];throw Error("InvalidOperationException: The source sequence is empty.")},e.prototype.lastOrDefault=function(t){return this.count(t)?this.last(t):void 0},e.prototype.max=function(t){return Math.max.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.min=function(t){return Math.min.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.ofType=function(t){var e;switch(t){case Number:e="number";break;case String:e="string";break;case Boolean:e=typeof!0;break;case Function:e="function";break;default:e=null}return null===e?this.where(function(e){return e instanceof t}).cast():this.where(function(t){return typeof t===e}).cast()},e.prototype.orderBy=function(e,i){return void 0===i&&(i=t.keyComparer(e,!1)),new n(this._elements,i)},e.prototype.orderByDescending=function(e,i){return void 0===i&&(i=t.keyComparer(e,!0)),new n(this._elements,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){return-1!==this.indexOf(t)&&(this.removeAt(this.indexOf(t)),!0)},e.prototype.removeAll=function(e){return this.where(t.negate(e))},e.prototype.removeAt=function(t){this._elements.splice(t,1)},e.prototype.reverse=function(){return new e(this._elements.reverse())},e.prototype.select=function(t){return new e(this._elements.map(t))},e.prototype.selectMany=function(t){var n=this;return this.aggregate(function(e,i,r){return e.addRange(n.select(t).elementAt(r).toArray()),e},new e)},e.prototype.sequenceEqual=function(t){return this.all(function(e){return t.contains(e)})},e.prototype.single=function(t){if(1!==this.count(t))throw new Error("The collection does not contain exactly one element.");return this.first(t)},e.prototype.singleOrDefault=function(t){return this.count(t)?this.single(t):void 0},e.prototype.skip=function(t){return new e(this._elements.slice(Math.max(0,t)))},e.prototype.skipLast=function(t){return new e(this._elements.slice(0,-Math.max(0,t)))},e.prototype.skipWhile=function(t){var e=this;return this.skip(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.sum=function(t){return t?this.select(t).sum():this.aggregate(function(t,e){return t+ +e},0)},e.prototype.take=function(t){return new e(this._elements.slice(0,Math.max(0,t)))},e.prototype.takeLast=function(t){return new e(this._elements.slice(-Math.max(0,t)))},e.prototype.takeWhile=function(t){var e=this;return this.take(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.toArray=function(){return this._elements},e.prototype.toDictionary=function(t,n){var i=this;return this.aggregate(function(e,r,o){return e[i.select(t).elementAt(o).toString()]=n?i.select(n).elementAt(o):r,e.add({Key:i.select(t).elementAt(o),Value:n?i.select(n).elementAt(o):r}),e},new e)},e.prototype.toSet=function(){var t,e,n=new Set;try{for(var i=__values(this._elements),r=i.next();!r.done;r=i.next()){var o=r.value;n.add(o)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return n},e.prototype.toList=function(){return this},e.prototype.toLookup=function(t,e){return this.groupBy(t,e)},e.prototype.where=function(t){return new e(this._elements.filter(t))},e.prototype.zip=function(t,e){var n=this;return t.count()e.angle?1:t.angleMath.PI&&(o-=2*Math.PI),r.p1.begin=o>0,r.p2.begin=!r.p1.begin}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}this._isSpotLight&&(this._spotStartAngle=this._segments[0].p2.angle,this._spotEndAngle=this._segments[1].p2.angle)},e._cornerCache=[],e._openSegments=new t.LinkedList,e}();t.VisibilityComputer=e}(es||(es={})),function(t){var e=function(){function e(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}return e.prototype.getContext=function(){return this.context},e.prototype.reset=function(){this._elapsedTime=0},e.prototype.stop=function(){this._isDone=!0},e.prototype.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=t.Time.deltaTime,this._isDone},e.prototype.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var e=this._timers.length-1;e>=0;e--)this._timers[e].tick()&&(this._timers[e].unload(),new t.List(this._timers).removeAt(e))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file +window.es={};var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{h(i.next(t))}catch(t){o(t)}}function a(t){try{h(i.throw(t))}catch(t){o(t)}}function h(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}h((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}},transform;!function(t){var e=function(){function e(n,i){void 0===n&&(n=!0),void 0===i&&(i=!0),this._globalManagers=[],this._coroutineManager=new t.CoroutineManager,this._timerManager=new t.TimerManager,this._frameCounterElapsedTime=0,this._frameCounter=0,this._totalMemory=0,e._instance=this,e.emitter=new t.Emitter,e.emitter.addObserver(t.CoreEvents.frameUpdated,this.update,this),e.registerGlobalManager(this._coroutineManager),e.registerGlobalManager(this._timerManager),e.entitySystemsEnabled=i,this.debug=n,this.initialize()}return Object.defineProperty(e,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(e,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(e){t.Insist.isNotNull(e,"场景不能为空"),null==this._instance._scene?(this._instance._scene=e,this._instance.onSceneChanged(),this._instance._scene.begin()):this._instance._nextScene=e},enumerable:!0,configurable:!0}),e.create=function(e){return void 0===e&&(e=!0),null==this._instance&&(this._instance=new t.Core(e)),this._instance},e.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},e.unregisterGlobalManager=function(e){new t.List(this._instance._globalManagers).remove(e),e.enabled=!1},e.getGlobalManager=function(t){for(var n=0,i=e._instance._globalManagers.length;n=1)){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._titleMemory&&this._titleMemory(this._totalMemory,this._frameCounter),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(n){return void 0===n&&(n=-1),__awaiter(this,void 0,void 0,function(){var i;return __generator(this,function(r){if(e.paused)return[2];if(t.Time.update(n),null!=this._scene){for(i=this._globalManagers.length-1;i>=0;i--)this._globalManagers[i].enabled&&this._globalManagers[i].update();this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}return this.startDebugDraw(),[2]})})},e.paused=!1,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){var e;!function(t){t[t.error=0]="error",t[t.warn=1]="warn",t[t.log=2]="log",t[t.info=3]="info",t[t.trace=4]="trace"}(e=t.LogType||(t.LogType={}));var n=function(){function t(){}return t.warnIf=function(t,n){for(var i=[],r=2;r=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t0?new e(this.x/t,this.y/t):new e(0,1)},e.prototype.normalizeEqual=function(){var t=this.distance();return t>0?(this.setTo(this.x/t,this.y/t),this):(this.setTo(0,1),this)},e.prototype.magnitude=function(){return this.distance()},e.prototype.distance=function(t){return t||(t=e.zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.prototype.angleBetween=function(e,n){var i=e.sub(this),r=n.sub(this);return t.Vector2Ext.angle(i,r)},e.prototype.equals=function(t,e){return void 0===e&&(e=.001),Math.abs(this.x-t.x)<=e&&Math.abs(this.y-t.y)<=e},e.prototype.isValid=function(){return t.MathHelper.isValid(this.x)&&t.MathHelper.isValid(this.y)},e.min=function(t,n){return new e(t.xn.x?t.x:n.x,t.y>n.y?t.y:n.y)},e.hermite=function(n,i,r,o,s){return new e(t.MathHelper.hermite(n.x,i.x,r.x,o.x,s),t.MathHelper.hermite(n.y,i.y,r.y,o.y,s))},e.unsignedAngle=function(e,n,i){void 0===i&&(i=!0),e.normalizeEqual(),n.normalizeEqual();var r=Math.acos(t.MathHelper.clamp(e.dot(n),-1,1))*t.MathHelper.Rad2Deg;return i?Math.round(r):r},e.prototype.clone=function(){return new e(this.x,this.y)},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(){this._sceneComponents=[],this._renderers=[],this.entities=new t.EntityList(this),this.renderableComponents=new t.RenderableComponentList,this.entityProcessors=new t.EntityProcessorList,this.identifierPool=new t.IdentifierPool,this.initialize()}return e.prototype.initialize=function(){},e.prototype.onStart=function(){},e.prototype.unload=function(){},e.prototype.begin=function(){0==this._renderers.length&&this.addRenderer(new t.DefaultRenderer),t.Physics.reset(),null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.prototype.end=function(){this._didSceneBegin=!1;for(var e=0;e=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateLists(),this.render()},e.prototype.render=function(){for(var t=0;te.x?-1:1,i=this.position.sub(e).normalize();this.rotation=n*Math.acos(i.dot(t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,null!=this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(null!=this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y,this._translationMatrix),this._localPositionDirty=!1),this._localRotationDirty&&(t.Matrix2D.createRotation(this._localRotation,this._rotationMatrix),this._localRotationDirty=!1),this._localScaleDirty&&(t.Matrix2D.createScale(this._localScale.x,this._localScale.y,this._scaleMatrix),this._localScaleDirty=!1),t.Matrix2D.multiply(this._scaleMatrix,this._rotationMatrix,this._localTransform),t.Matrix2D.multiply(this._localTransform,this._translationMatrix,this._localTransform),null==this.parent&&(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),null!=this.parent&&(t.Matrix2D.multiply(this._localTransform,this.parent._worldTransform,this._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=this.parent._scale.multiply(this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(t){if(0==(this.hierarchyDirty&t)){switch(this.hierarchyDirty|=t,t){case e.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case e.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case e.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}for(var n=0;n1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},n.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},n.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},n.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},n.prototype.setVelocity=function(t){return this.velocity=t,this},n.prototype.addImpulse=function(e){this.isImmovable||this.velocity.addEqual(e.scale(this._inverseMass*(t.Time.deltaTime*t.Time.deltaTime)*1e5))},n.prototype.onAddedToEntity=function(){this._collider=null;for(var e=0;e0&&(o=t.Vector2.zero);var a=this._friction;return s.lengthSquared()0&&this.collisionState.wasGroundedLastFrame&&(t=this.handleVerticalSlope(t)),0!==t.x&&(t=this.moveHorizontally(t)),0!==t.y&&(t=this.moveVertically(t)),this._player.setPosition(this._player.position.x+t.x,this._player.position.y+t.y),e>0&&(this.velocity.x=t.x/e,this.velocity.y=t.y/e),!this.collisionState.wasGroundedLastFrame&&this.collisionState.below&&(this.collisionState.becameGroundedThisFrame=!0),this._isGoingUpSlope&&(this.velocity.y=0),this._isWarpingToGround||this._triggerHelper.update();for(var n=0;n0&&(this.ignoreOneWayPlatformsTime-=e)},i.prototype.warpToGrounded=function(e){void 0===e&&(e=1e3),this.ignoreOneWayPlatformsTime=0,this._isWarpingToGround=!0;var n=0;do{if(n+=1,this.move(new t.Vector2(0,1),.02),n>e)break}while(!this.isGrounded);this._isWarpingToGround=!1},i.prototype.recalculateDistanceBetweenRays=function(){var t=this._collider.height*Math.abs(this._player.scale.y)-2*this._skinWidth;this._verticalDistanceBetweenRays=t/(this.totalHorizontalRays-1);var e=this._collider.width*Math.abs(this._player.scale.x)-2*this._skinWidth;this._horizontalDistanceBetweenRays=e/(this.totalVerticalRays-1)},i.prototype.primeRaycastOrigins=function(){var e=this._collider.bounds;this._raycastOrigins.topLeft=new t.Vector2(e.x+this._skinWidth,e.y+this._skinWidth),this._raycastOrigins.bottomRight=new t.Vector2(e.right-this._skinWidth,e.bottom-this._skinWidth),this._raycastOrigins.bottomLeft=new t.Vector2(e.x+this._skinWidth,e.bottom-this._skinWidth)},i.prototype.moveHorizontally=function(e){for(var n=e.x>0,i=Math.abs(e.x)+this._skinWidth*this.rayOriginSkinMutiplier,r=n?t.Vector2.right:t.Vector2.left,o=this._raycastOrigins.bottomLeft.y,s=n?this._raycastOrigins.bottomRight.x-this._skinWidth*(this.rayOriginSkinMutiplier-1):this._raycastOrigins.bottomLeft.x+this._skinWidth*(this.rayOriginSkinMutiplier-1),a=0;a0)&&(a&=~this.oneWayPlatformMask);for(var h=0;hthis.jumpingThreshold){var i=this.slopeSpeedMultiplier?this.slopeSpeedMultiplier.lerp(n):1;e.x*=i,e.y=Math.abs(Math.tan(n*t.MathHelper.Deg2Rad)*e.x);var r=e.x>0,o=r?this._raycastOrigins.bottomRight:this._raycastOrigins.bottomLeft,s=null;(s=this.supportSlopedOneWayPlatforms&&this.collisionState.wasGroundedLastFrame?t.Physics.linecast(o,o.add(e),this.platformMask,this.ignoredColliders):t.Physics.linecast(o,o.add(e),this.platformMask&~this.oneWayPlatformMask,this.ignoredColliders)).collider&&(e.x=s.point.x-o.x,e.y=s.point.y-o.y,r?e.x-=this._skinWidth:e.x+=this._skinWidth),this._isGoingUpSlope=!0,this.collisionState.below=!0}}else e.x=0;return!0},i}();t.CharacterController=i}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,n){var i,r;try{for(var o=__values(e.components._components),s=o.next();!s.done;s=o.next()){var a=s.value;t.isITriggerListener(a)&&n.push(a)}}catch(t){i={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}for(var h in e.components._componentsToAdd){a=e.components._componentsToAdd[h];t.isITriggerListener(a)&&n.push(a)}return n},e}();t.TriggerListenerHelper=e,t.isITriggerListener=function(t){return void 0!==t.onTriggerEnter}}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){for(var i,r,o=null,s=0;sn;n++){var i=t[n];this.processDelta(i,this.acc);var r=this.getRemainingDelay(i);r<=0?this.processExpired(i):this.offerDelay(r)}this.acc=0}else this.stop()},n.prototype.checkProcessing=function(){return!!this.running&&(this.acc+=t.Time.deltaTime,this.acc>=this.delay)},n.prototype.offerDelay=function(t){this.running?this.delay=Math.min(this.delay,t):(this.running=!0,this.delay=t)},n.prototype.getInitialTimeDelay=function(){return this.delay},n.prototype.getRemainingTimeUntilProcessing=function(){return this.running?this.delay-this.acc:0},n.prototype.isRunning=function(){return this.running},n.prototype.stop=function(){this.running=!1,this.acc=0},n}(t.EntitySystem);t.DelayedIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.lateProcessEntity=function(t){},e.prototype.process=function(t){if(0!=t.length)for(var e=0,n=t.length;e=this.interval&&(this.acc-=this.interval,this.intervalDelta=this.acc-this.intervalDelta,!0)},n.prototype.getIntervalDelta=function(){return this.interval+this.intervalDelta},n}(t.EntitySystem);t.IntervalSystem=e}(es||(es={})),function(t){var e=function(t){function e(e,n){return t.call(this,e,n)||this}return __extends(e,t),e.prototype.process=function(t){var e=this;t.forEach(function(t){return e.processEntity(t)})},e}(t.IntervalSystem);t.IntervalIteratingSystem=e}(es||(es={})),function(es){var JobSystem=function(_super){function JobSystem(t,e){var n=_super.call(this,t)||this;n._threads=e,n._jobs=new Array(e);for(var i=0;it.length&&(s=t.length);var a=o._jobs[n];if(a.set(t,r,s,o._executeStr,o),r!=s){var h=es.WorkerUtils.makeWorker(o.queueOnThread);es.WorkerUtils.workerMessage(h)(a).then(function(t){var n=t;e.resetJob(n),h.terminate()}).catch(function(t){a.err=t,h.terminate()})}},o=this,s=0;s-1?eval("(function(){return "+v+" })()"):v}),i=job.from;i0)for(var t=0,e=this._components.length;t0)for(var e=0,n=this._components.length;e0)for(var e=0,n=this._components.length;e0){for(var e=function(t,e){var i=n._componentsToRemoveList[t];n.handleRemove(i);var r=n._components.findIndex(function(t){return t.id==i.id});-1!=r&&n._components.splice(r,1),n.removeComponentsByType(i)},n=this,i=0,r=this._componentsToRemoveList.length;i0){for(i=0,r=this._componentsToAddList.length;i0){for(i=0,r=this._tempBufferList.length;i0){var n=this._updatableComponents.findIndex(function(t){return t.id==e.id});-1!=n&&this._updatableComponents.splice(n,1)}this.decreaseBits(e),this._entity.scene.entityProcessors.onComponentRemoved(this._entity),e.onRemovedFromEntity(),e.entity=null},e.prototype.removeComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsByType.set(t.TypeUtils.getType(e),n)},e.prototype.removeComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsToAddByType.set(t.TypeUtils.getType(e),n)},e.prototype.getComponent=function(t,e){var n=this.componentsByType.get(t);if(n&&n.length>0)return n[0];if(!e){var i=this.componentsToAddByType.get(t);if(i&&i.length>0)return i[0]}return null},e.prototype.getComponents=function(t,e){e||(e=[]);var n=this.componentsByType.get(t);n&&(e=e.concat(n));var i=this.componentsToAddByType.get(t);return i&&(e=e.concat(i)),e},e.prototype.update=function(){if(this.updateLists(),this._updatableComponents.length>0)for(var t=0,e=this._updatableComponents.length;t0)for(var e=0,n=this._components.length;e0)for(e=0,n=this._componentsToAddList.length;e0)for(var t=0,e=this._components.length;t0)for(var t=0,e=this._components.length;t0){for(var t=function(t,n){var i=e._entitiesToRemoveList[t];e.removeFromTagList(i);var r=e._entities.findIndex(function(t){return t.id==i.id});-1!=r&&e._entities.splice(r,1),i.onRemovedFromScene(),i.scene=null,e.scene.entityProcessors.onEntityRemoved(i)},e=this,n=0,i=this._entitiesToRemoveList.length;n0){for(n=0,i=this._entitiesToAddedList.length;n0)for(var e=0,n=this._entities.length;e0)for(e=0,n=this._entitiesToAddedList.length;e0)for(var e=0,n=this._entities.length;e0)try{for(var s=__values(r),a=s.next();!a.done;a=s.next()){var h=a.value;o.push(h)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return o},e.prototype.entityWithTag=function(t){var e,n,i=this.getTagList(t);if(i.size>0)try{for(var r=__values(i),o=r.next();!o.done;o=r.next()){return o.value}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return null},e.prototype.findComponentOfType=function(t){if(this._entities.length>0)for(var e=0,n=this._entities.length;e0)for(e=0;e0)for(var i=0,r=this._entities.length;i0)for(i=0,r=this._entitiesToAddedList.length;i0)for(var i=0,r=this._entities.length;i0)for(var s=0,a=t.length;s0)for(i=0,r=this._entitiesToAddedList.length;i0)for(s=0,a=t.length;s=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i0?this.ids.removeLast():this.nextAvailableId_++},e.prototype.checkIn=function(t){this.ids.add(t)},e}();t.IdentifierPool=e}(es||(es={})),function(t){var e=function(){function e(){this.allSet=[],this.exclusionSet=[],this.oneSet=[]}return e.empty=function(){return new e},e.prototype.getAllSet=function(){return this.allSet},e.prototype.getExclusionSet=function(){return this.exclusionSet},e.prototype.getOneSet=function(){return this.oneSet},e.prototype.isInterestedEntity=function(t){return this.isInterested(t.componentBits)},e.prototype.isInterested=function(e){if(0!=this.allSet.length)for(var n=0,i=this.allSet.length;n0)for(var t=0,e=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function t(){}return t.update=function(t){-1==t&&(t=Date.now()),-1==this._lastTime&&(this._lastTime=t);var e=0;(e=-1==t?(t-this._lastTime)/1e3:t)>this.maxDeltaTime&&(e=this.maxDeltaTime),this.totalTime+=e,this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return this.timeSinceSceneLoad/t>(this.timeSinceSceneLoad-this.deltaTime)/t},t.totalTime=0,t.unscaledDeltaTime=0,t.deltaTime=0,t.timeScale=1,t.maxDeltaTime=Number.MAX_VALUE,t.frameCount=0,t.timeSinceSceneLoad=0,t._lastTime=-1,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,h=Math.floor(a)+1;if(53==h){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var c=n.getDay();if(0==c&&(c=7),e&&(!o||c<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(h>9?"":"0")+h)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),h=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(h="0"+h),n?s+e+a+e+h:a+e+h},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t},t.fromRGBA=function(e,n,i,r){e/=255,n/=255,i/=255;var o=Math.max(e,n,i),s=Math.min(e,n,i),a=(o+s)/2,h=a,c=a;if(o===s)a=h=0;else{var u=o-s;switch(h=c>.5?u/(2-o-s):u/(o+s),o){case e:a=(n-i)/u+(n=1?(e=1,n.range=this._points.length-4):(e=t.MathHelper.clamp01(e)*this._curveCount,n.range=Math.floor(e),e-=n.range,n.range*=3),n.time=e,n},e.prototype.setControlPoint=function(t,e){if(t%3==0){var n=e.sub(this._points[t]);t>0&&this._points[t-1].addEqual(n),t+1-Math.PI&&t<=Math.PI?t:(t%=2*Math.PI)<=-Math.PI?t+2*Math.PI:t>Math.PI?t-2*Math.PI:t},e.isPowerOfTwo=function(t){return t>0&&t%(t-1)==0},e.lerp=function(t,e,n){return t+(e-t)*this.clamp01(n)},e.betterLerp=function(t,n,i,r){return Math.abs(t-n)180&&(i-=360),t+i*this.clamp01(n)},e.lerpAngleRadians=function(t,e,n){var i=this.repeat(e-t,2*Math.PI);return i>Math.PI&&(i-=2*Math.PI),t+i*this.clamp01(n)},e.pingPong=function(t,e){return t=this.repeat(t,2*e),e-Math.abs(t-e)},e.signThreshold=function(t,e){return Math.abs(t)>=e?Math.sign(t):0},e.inverseLerp=function(t,e,n){if(te)return 1}else{if(nt)return 0}return(n-t)/(e-t)},e.lerpPrecise=function(t,e,n){return(1-n)*t+e*n},e.clamp=function(t,e,n){return tn?n:t},e.snap=function(t,e){return Math.round(t/e)*e},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.isOdd=function(t){return t%2!=0},e.roundWithRoundedAmount=function(t,e){var n=Math.round(t);return e.value=t-n*Math.round(t/n),n},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.angleToVector=function(e,n){return new t.Vector2(Math.cos(e)*n,Math.sin(e)*n)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.decrementWithWrap=function(t,e){return--t<0?e-1:t},e.hypotenuse=function(t,e){return Math.sqrt(t*t+e*e)},e.closestPowerOfTwoGreaterThan=function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,(t|=t>>16)+1},e.roundToNearest=function(t,e){return Math.round(t/e)*e},e.withinEpsilon=function(t,e){return void 0===e&&(e=this.Epsilon),Math.abs(t)180&&(n-=360),n},e.between=function(t,e,n){return t>=e&&t<=n},e.deltaAngleRadians=function(t,e){var n=this.repeat(e-t,2*Math.PI);return n>Math.PI&&(n-=2*Math.PI),n},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.floorToInt=function(t){return Math.trunc(Math.floor(t))},e.rotateAround=function(e,n){var i=t.Time.totalTime*n,r=Math.cos(i),o=Math.sin(i);return new t.Vector2(e.x+r,e.y+o)},e.rotateAround2=function(e,n,i){i=this.toRadians(i);var r=Math.cos(i),o=Math.sin(i),s=r*(e.x-n.x)-o*(e.y-n.y)+n.x,a=o*(e.x-n.x)+r*(e.y-n.y)+n.y;return new t.Vector2(s,a)},e.pointOnCircle=function(e,n,i){var r=this.toRadians(i);return new t.Vector2(Math.cos(r)*n+e.x,Math.sin(r)*n+e.y)},e.pointOnCircleRadians=function(e,n,i){return new t.Vector2(Math.cos(i)*n+e.x,Math.sin(i)*n+e.y)},e.lissajou=function(e,n,i,r,o){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=0);var s=Math.sin(t.Time.totalTime*e+o)*i,a=Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(s,a)},e.lissajouDamped=function(e,n,i,r,o,s,a){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=.5),void 0===s&&(s=0),void 0===a&&(a=5);var h=this.pingPong(t.Time.totalTime,a),c=Math.pow(Math.E,-s*h),u=c*Math.sin(t.Time.totalTime*e+o)*i,l=c*Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(u,l)},e.hermite=function(t,e,n,i,r){return 0==r?t:1==r?n:(2*t-2*n+i+e)*(r*r*r)+(3*n-3*t-2*e-i)*(r*r)+e*r+t},e.isValid=function(t){return!Number.isNaN(t)&&t!==1/0},e.smoothDamp=function(t,e,n,i,r,o){var s=2/(i=Math.max(1e-4,i)),a=s*o,h=1/(1+(a+(a*a*.48+a*(a*a)*.235))),c=t-e,u=e,l=r*i,p=(n+s*(c=this.clamp(c,-1*l,l)))*o;n=(n-s*p)*h;var f=(e=t-c)+(c+p)*h;return u-t>0==f>u&&(n=((f=u)-u)/o),{value:f,currentVelocity:n}},e.smoothDampVector=function(e,n,i,r,o,s){var a=t.Vector2.zero,h=this.smoothDamp(e.x,n.x,i.x,r,o,s);a.x=h.value,i.x=h.currentVelocity;var c=this.smoothDamp(e.y,n.y,i.y,r,o,s);return a.y=c.value,i.y=c.currentVelocity,a},e.mapMinMax=function(t,n,i,r,o){return r+(e.clamp(t,n,i)-n)*(o-r)/(i-n)},e.fromAngle=function(e){return new t.Vector2(Math.cos(e),Math.sin(e)).normalizeEqual()},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e.PiOver2=Math.PI/2,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function t(t,e,n,i,r,o,s,a,h,c,u,l,p,f,d,m){this.m11=t,this.m12=e,this.m13=n,this.m14=i,this.m21=r,this.m22=o,this.m23=s,this.m24=a,this.m31=h,this.m32=c,this.m33=u,this.m34=l,this.m41=p,this.m42=f,this.m43=d,this.m44=m}return Object.defineProperty(t,"Identity",{get:function(){return this.identity},enumerable:!0,configurable:!0}),t.createOrthographicOffCenter=function(e,n,i,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(n-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-i),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+n)/(e-n),a.m42=(r+i)/(i-r),a.m43=o/(o-s),a.m44=1},t.createTranslation=function(t,e){e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=t.x,e.m42=t.y,e.m43=0,e.m44=1},t.createRotationZ=function(e,n){n=t.Identity;var i=Math.cos(e),r=Math.sin(e);n.m11=i,n.m12=r,n.m21=-r,n.m22=i},t.multiply=function(e,n,i){void 0===i&&(i=new t);var r=e.m11*n.m11+e.m12*n.m21+e.m13*n.m31+e.m14*n.m41,o=e.m11*n.m12+e.m12*n.m22+e.m13*n.m32+e.m14*n.m42,s=e.m11*n.m13+e.m12*n.m23+e.m13*n.m33+e.m14*n.m43,a=e.m11*n.m14+e.m12*n.m24+e.m13*n.m34+e.m14*n.m44,h=e.m21*n.m11+e.m22*n.m21+e.m23*n.m31+e.m24*n.m41,c=e.m21*n.m12+e.m22*n.m22+e.m23*n.m32+e.m24*n.m42,u=e.m21*n.m13+e.m22*n.m23+e.m23*n.m33+e.m24*n.m43,l=e.m21*n.m14+e.m22*n.m24+e.m23*n.m34+e.m24*n.m44,p=e.m31*n.m11+e.m32*n.m21+e.m33*n.m31+e.m34*n.m41,f=e.m31*n.m12+e.m32*n.m22+e.m33*n.m32+e.m34*n.m42,d=e.m31*n.m13+e.m32*n.m23+e.m33*n.m33+e.m34*n.m43,m=e.m31*n.m14+e.m32*n.m24+e.m33*n.m34+e.m34*n.m44,y=e.m41*n.m11+e.m42*n.m21+e.m43*n.m31+e.m44*n.m41,g=e.m41*n.m12+e.m42*n.m22+e.m43*n.m32+e.m44*n.m42,_=e.m41*n.m13+e.m42*n.m23+e.m43*n.m33+e.m44*n.m43,v=e.m41*n.m14+e.m42*n.m24+e.m43*n.m34+e.m44*n.m44;i.m11=r,i.m12=o,i.m13=s,i.m14=a,i.m21=h,i.m22=c,i.m23=u,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=m,i.m41=y,i.m42=g,i.m43=_,i.m44=v},t.identity=new t(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t}();t.Matrix=e}(es||(es={})),function(t){var e=function(){function e(){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0}return Object.defineProperty(e,"identity",{get:function(){return(new e).setIdentity()},enumerable:!0,configurable:!0}),e.prototype.setIdentity=function(){return this.setValues(1,0,0,1,0,0)},e.prototype.setValues=function(t,e,n,i,r,o){return this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=r,this.m32=o,this},Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m22=t.y},enumerable:!0,configurable:!0}),e.createRotation=function(t,e){e.setIdentity();var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-1*i,e.m22=n},e.createRotationOut=function(t,e){var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-i,e.m22=n},e.createScale=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createScaleOut=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createTranslation=function(t,e,n){return n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=t,n.m32=e,n},e.createTranslationOut=function(t,e){e.m11=1,e.m12=0,e.m21=0,e.m22=1,e.m31=t.x,e.m32=t.y},e.invert=function(t){var e=1/t.determinant(),n=this.identity;return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.multiply=function(t,e,n){var i=t.m11*e.m11+t.m12*e.m21,r=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,s=t.m21*e.m12+t.m22*e.m22,a=t.m31*e.m11+t.m32*e.m21+e.m31,h=t.m31*e.m12+t.m32*e.m22+e.m32;n.m11=i,n.m12=r,n.m21=o,n.m22=s,n.m31=a,n.m32=h},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,n){return t.m11=t.m11+(e.m11-t.m11)*n,t.m12=t.m12+(e.m12-t.m12)*n,t.m21=t.m21+(e.m21-t.m21)*n,t.m22=t.m22+(e.m22-t.m22)*n,t.m31=t.m31+(e.m31-t.m31)*n,t.m32=t.m32+(e.m32-t.m32)*n,t},e.transpose=function(t){var e=this.identity;return e.m11=t.m11,e.m12=t.m21,e.m21=t.m12,e.m22=t.m22,e.m31=0,e.m32=0,e},e.prototype.mutiplyTranslation=function(n,i){var r=new e;return e.createTranslation(n,i,r),t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var n=new t.Matrix;return n.m11=e.m11,n.m12=e.m12,n.m13=0,n.m14=0,n.m21=e.m21,n.m22=e.m22,n.m23=0,n.m24=0,n.m31=0,n.m32=0,n.m33=1,n.m34=0,n.m41=e.m31,n.m42=e.m32,n.m43=0,n.m44=1,n},e.prototype.toString=function(){return"{m11:"+this.m11+" m12:"+this.m12+" m21:"+this.m21+" m22:"+this.m22+" m31:"+this.m31+" m32:"+this.m32+"}"},e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(){function e(){}return e.add=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11+n.m11,i.m12=e.m12+n.m12,i.m21=e.m21+n.m21,i.m22=e.m22+n.m22,i.m31=e.m31+n.m31,i.m32=e.m32+n.m32,i},e.divide=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11/n.m11,i.m12=e.m12/n.m12,i.m21=e.m21/n.m21,i.m22=e.m22/n.m22,i.m31=e.m31/n.m31,i.m32=e.m32/n.m32,i},e.mutiply=function(e,n){var i=t.Matrix2D.identity;if(n instanceof t.Matrix2D){var r=e.m11*n.m11+e.m12*n.m21,o=n.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,h=e.m31*n.m11+e.m32*n.m21+n.m31,c=e.m31*n.m12+e.m32*n.m22+n.m32;i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=h,i.m32=c}else"number"==typeof n&&(i.m11=e.m11*n,i.m12=e.m12*n,i.m21=e.m21*n,i.m22=e.m22*n,i.m31=e.m31*n,i.m32=e.m32*n);return i},e.subtract=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11-n.m11,i.m12=e.m12-n.m12,i.m21=e.m21-n.m21,i.m22=e.m22-n.m22,i.m31=e.m31-n.m31,i.m32=e.m32-n.m32,i},e}();t.MatrixHelper=e}(es||(es={})),function(t){var e=function(){function e(e,n,i,r){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),void 0===r&&(r=0),this.x=0,this.y=0,this.width=0,this.height=0,this._tempMat=new t.Matrix2D,this._transformMat=new t.Matrix2D,this.x=e,this.y=n,this.width=i,this.height=r}return Object.defineProperty(e,"empty",{get:function(){return new e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"maxRect",{get:function(){return new e(Number.MIN_VALUE/2,Number.MIN_VALUE/2,Number.MAX_VALUE,Number.MAX_VALUE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.isEmpty=function(){return 0==this.width&&0==this.height&&0==this.x&&0==this.y},Object.defineProperty(e.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),e.fromMinMax=function(t,n,i,r){return new e(t,n,i-t,r-n)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;oi&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return e}else{var i=1/t.direction.x,r=(this.x-t.start.x)*i,o=(this.x+this.width-t.start.x)*i;if(r>o){var s=r;r=o,o=s}if(e.distance=Math.max(r,e.distance),n=Math.min(o,n),e.distance>n)return e}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return e}else{var a=1/t.direction.y,h=(this.y-t.start.y)*a,c=(this.y+this.height-t.start.y)*a;if(h>c){var u=h;h=c,c=u}if(e.distance=Math.max(h,e.distance),n=Math.max(c,n),e.distance>n)return e}return e.intersected=!0,e},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,i.y=n>0?this.y:this.y+n,i.width=t>0?t+this.width:this.width-t,i.height=n>0?n+this.height:this.height-n,i},e.prototype.collisionCheck=function(t,e,n){e.value=n.value=0;var i=t.x-(this.x+this.width),r=t.x+t.width-this.x,o=t.y-(this.y+this.height),s=t.y+t.height-this.y;return!(i>0||r<0||o>0||s<0)&&(e.value=Math.abs(i)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return Math.trunc(this.x)^Math.trunc(this.y)^Math.trunc(this.width)^Math.trunc(this.height)},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.HashSet,this._previousTriggerIntersections=new t.HashSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){for(var e,n,i=[],r=this._entity.getComponents(t.Collider),o=0;o=t.Collider.lateSortOrder?i.push(u):this.notifyTriggerListeners(u,!0)),this._activeTriggerIntersections.add(u)}}try{for(var l=__values(i),p=l.next();!p.done;p=l.next()){u=p.value;this.notifyTriggerListeners(u,!0)}}catch(t){e={error:t}}finally{try{p&&!p.done&&(n=l.return)&&n.call(l)}finally{if(e)throw e.error}}this.checkForExitedColliders()},e.prototype.checkForExitedColliders=function(){this._previousTriggerIntersections.exceptWith(this._activeTriggerIntersections.toArray());for(var t=0;t1)return!1;var c=(a.x*r.y-a.y*r.x)/s;return!(c<0||c>1)},n.lineToLineIntersection=function(e,n,i,r,o){void 0===o&&(o=t.Vector2.zero),o.x=0,o.y=0;var s=n.sub(e),a=r.sub(i),h=s.x*a.y-s.y*a.x;if(0==h)return!1;var c=i.sub(e),u=(c.x*a.y-c.y*a.x)/h;if(u<0||u>1)return!1;var l=(c.x*s.y-c.y*s.x)/h;if(l<0||l>1)return!1;var p=e.add(s.scale(u));return o.x=p.x,o.y=p.y,!0},n.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scale(o))},n.circleToCircle=function(e,n,i,r){return t.Vector2.sqrDistance(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.sqrDistance(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setAllValues=function(t,e,n,i,r){this.collider=t,this.fraction=e,this.distance=n,this.point=i,this.normal=r},e.prototype.setValues=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.clone=function(){var t=new e;return t.setAllValues(this.collider,this.fraction,this.distance,this.point,this.normal),t},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset(),this._colliderArray[0]=null},e.clear=function(){this._spatialHash.clear()},e.debugDraw=function(t){this.debugRender&&this._spatialHash.debugDraw(t)},e.overlapCircle=function(t,n,i){return void 0===i&&(i=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapCircle(t,n,this._colliderArray,i),this._colliderArray[0]},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.warn("传入了一个空的结果数组。不会返回任何结果")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var n=t.bounds;return this._spatialHash.aabbBroadphase(n,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,n,i,r){void 0===r&&(r=e.allLayers);var o=t.bounds.getSweptBroadphaseBounds(n,i);return this._spatialHash.aabbBroadphase(o,t,r)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.linecast=function(t,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._hitArray[0].reset(),this.linecastAll(t,n,this._hitArray,i),this._hitArray[0].reset(),e.linecastAll(t,n,this._hitArray,i,r),this._hitArray[0].clone()},e.linecastAll=function(t,e,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._spatialHash.linecast(t,e,n,i,r)},e.overlapRectangle=function(t,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,n),this._colliderArray[0]},e.overlapRectangleAll=function(t,n,i){return void 0===i&&(i=e.allLayers),0==n.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,n,i)},e.gravity=new t.Vector2(0,-300),e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e.debugRender=!1,e._hitArray=[new t.RaycastHit],e._colliderArray=[null],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(t,e){this._start=t.clone(),this._end=e.clone(),this._direction=this._end.sub(this._start)}return Object.defineProperty(t.prototype,"start",{get:function(){return this._start},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"end",{get:function(){return this._end},enumerable:!0,configurable:!0}),t}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestBox=new t.Box(0,0),this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds.clone();e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(e){for(var n=e.registeredPhysicsBounds.clone(),i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom),o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){var a=this.cellAtPosition(o,s);t.Insist.isNotNull(a,"从不存在碰撞器的单元格中移除碰撞器: ["+e+"]"),null!=a&&new t.List(a).remove(e)}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.debugDraw=function(t){for(var e=this.gridBounds.x;e<=this.gridBounds.right;e++)for(var n=this.gridBounds.y;n<=this.gridBounds.bottom;n++){var i=this.cellAtPosition(e,n);null!=i&&i.length>0&&this.debugDrawCellDetails(e,n,t)}},e.prototype.debugDrawCellDetails=function(e,n,i){void 0===i&&(i=.5),t.Graphics.instance.batcher.drawHollowRect(e*this._cellSize,n*this._cellSize,this._cellSize,this._cellSize,new t.Color(255,0,0),i),t.Graphics.instance.batcher.end()},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.clear();for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var h=this.cellAtPosition(s,a);if(h)for(var c=0;c=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;ri&&(i=o,n=r)}return t[n]},n.getClosestPointOnPolygonToPoint=function(e,n){for(var i={distanceSquared:Number.MAX_VALUE,edgeNormal:t.Vector2.zero,closestPoint:t.Vector2.zero},r=0,o=0;ot.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o1)return!1;var h,c=s.start.add(s.direction.scale(r)),u=0;c.xn.bounds.right&&(u|=1),c.yn.bounds.bottom&&(u|=2);var l=h+u;return 3==l&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,n){var i=t.Vector2.zero;return i.x=0==(1&n)?e.right:e.left,i.y=0==(1&n)?e.bottom:e.top,i},e.testCircleBox=function(t,e,n){var i=e.bounds.getClosestPointOnRectangleToPoint(t.position).sub(t.position);return i.dot(i)<=t.radius*t.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.boxToBox=function(e,n,i){var r=this.minkowskiDifference(e,n);return!!r.contains(0,0)&&(i.minimumTranslationVector=r.getClosestPointOnBoundsToOrigin(),!i.minimumTranslationVector.equals(t.Vector2.zero)&&(i.normal=i.minimumTranslationVector.scale(-1),i.normal=i.normal.normalize(),!0))},e.boxToBoxCast=function(e,n,i,r){var o=this.minkowskiDifference(e,n);if(o.contains(0,0)){var s=o.getClosestPointOnBoundsToOrigin();return!s.equals(t.Vector2.zero)&&(r.normal=new t.Vector2(-s.x,-s.y),r.normal=r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,i.scale(-1)),h=o.rayIntersects(a);return!!(h.intersected&&h.distance<=1)&&(r.fraction=h.distance,r.distance=i.magnitude()*h.distance,r.normal=i.scale(-1),r.normal=r.normal.normalize(),r.centroid=e.bounds.center.add(i.scale(h.distance)),!0)},e.minkowskiDifference=function(e,n){var i=e.position.sub(e.bounds.center),r=e.bounds.location.add(i.sub(n.bounds.max)),o=e.bounds.size.add(n.bounds.size);return new t.Rectangle(r.x,r.y,o.x,o.y)},e}();t.ShapeCollisionsBox=e}(es||(es={})),function(t){var e=function(){function e(){}return e.circleToCircleCast=function(e,n,i,r){var o=e.position.add(i),s=this.closestPointOnLine(e.position,o,n.position),a=t.Vector2.sqrDistance(n.position,s),h=(e.radius+n.radius)*(e.radius+n.radius);if(a<=h){var c=i.normalize();s===o&&(o=e.position.add(i.add(c.scale(n.radius))),s=this.closestPointOnLine(e.position,o,n.position),a=t.Vector2.sqrDistance(n.position,s));var u=Math.sqrt(h-a);return r.centroid=s.sub(c.scale(u)),r.normal=r.centroid.sub(n.position).normalize(),r.fraction=(r.centroid.x-e.position.x)/i.x,r.distance=t.Vector2.distance(e.position,r.centroid),r.point=n.position.add(r.normal.scale(n.radius)),!0}return!1},e.circleToCircle=function(e,n,i){void 0===i&&(i=new t.CollisionResult);var r=t.Vector2.sqrDistance(e.position,n.position),o=e.radius+n.radius;if(re.radius*e.radius&&!a)return!1;if(a)s=i.normal.scale(Math.sqrt(o.distanceSquared)-e.radius);else if(0===o.distanceSquared)s=i.normal.scale(e.radius);else{var h=Math.sqrt(o.distanceSquared);s=r.sub(o.closestPoint).scale((e.radius-h)/h*-1)}return i.minimumTranslationVector=s,i.point=o.closestPoint.add(n.position),!0},e.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scaleEqual(o))},e}();t.ShapeCollisionsCircle=e}(es||(es={})),function(t){var e=function(){function e(){}return e.lineToPoly=function(n,i,r,o){void 0===o&&(o=new t.RaycastHit);for(var s=t.Vector2.zero,a=t.Vector2.zero,h=Number.MAX_VALUE,c=!1,u=r.points.length-1,l=0;l1)return!1;var u=(h.x*o.y-h.y*o.x)/a;if(u<0||u>1)return!1;var l=t.add(o.scale(c));return r.x=l.x,r.y=l.y,!0},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divideScaler(n.sub(e),o),a=e.sub(i.position),h=a.dot(s),c=a.dot(a)-i.radius*i.radius;if(c>0&&h>0)return!1;var u=h*h-c;return!(u<0)&&(r.fraction=-h-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=e.add(s.scale(r.fraction)),r.distance=t.Vector2.distance(e,r.point),r.normal=r.point.sub(i.position).normalize(),r.fraction=r.distance/o,!0)},e}();t.ShapeCollisionsLine=e}(es||(es={})),function(t){var e=function(){function e(){}return e.pointToCircle=function(e,n,i){var r=t.Vector2.sqrDistance(e,n.position),o=1+n.radius;if(r0&&(o=!1),!o)return!1;(p=Math.abs(p))i.max&&(i.max=n);return i},e.intervalDistance=function(t,e,n,i){return t= 2");if(t.sort(function(t,e){return t.t-e.t}),0!==t[0].t)throw new Error("curve must start with 0");if(1!==t[t.length-1].t)throw new Error("curve must end with 1");this._points=t}return Object.defineProperty(e.prototype,"points",{get:function(){return this._points},enumerable:!0,configurable:!0}),e.prototype.lerp=function(e){for(var n=1;n=0;o--)(e=r[o].func).call.apply(e,__spread([r[o].context],n))},n}();t.Emitter=n}(es||(es={})),function(t){!function(t){t[t.top=0]="top",t[t.bottom=1]="bottom",t[t.left=2]="left",t[t.right=3]="right"}(t.Edge||(t.Edge={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.default=function(){return new t},t.prototype.equals=function(t,e){return"function"==typeof t.equals?t.equals(e):t===e},t.prototype.getHashCode=function(t){var e=this;if("number"==typeof t)return this._getHashCodeForNumber(t);if("string"==typeof t)return this._getHashCodeForString(t);var n=385229220;return this.forOwn(t,function(t){"number"==typeof t?n+=e._getHashCodeForNumber(t):"string"==typeof t?n+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){n+=e.getHashCode(t)})}),n},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,n=0;n>7,n+=n<<3,n^=n>>17,n+=n<<5},t}();t.Hash=e}(es||(es={})),function(t){var e=function(){function t(){this._listeners=[]}return t.prototype.addListener=function(t,e){-1===this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t})&&this._listeners.push({caller:t,callback:e})},t.prototype.removeListener=function(t,e){var n=this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t});n>=0&&this._listeners.splice(n,1)},t.prototype.clearListener=function(){this._listeners=[]},t.prototype.clearListenerWithCaller=function(t){for(var e=this._listeners.length-1;e>=0;e--){this._listeners[e].caller===t&&this._listeners.splice(e,1)}},t.prototype.notify=function(){for(var t,e=[],n=0;n=0;i--){var r=this._listeners[i];r.caller?(t=r.callback).call.apply(t,__spread([r.caller],e)):r.callback.apply(r,__spread(e))}},t}();t.Observable=e;var n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e){t.prototype.notify.call(this,e)},e}(e);t.ObservableT=n;var i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e,n){t.prototype.notify.call(this,e,n)},e}(e);t.ObservableTT=i;var r=function(){function t(t,n){this.bindAction(t,n),this._onExec=new e}return t.prototype.bindAction=function(t,e){this._caller=t,this._action=e},t.prototype.dispatch=function(){for(var t,e=[],n=0;n3&&o<500;){o++;var a=!0,h=n[this._triPrev[s]],c=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(h,c,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],h,c,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.length>8&255]+e[t>>16&255]+e[t>>24&255]+"-"+e[255&n]+e[n>>8&255]+"-"+e[n>>16&15|64]+e[n>>24&255]+"-"+e[63&i|128]+e[i>>8&255]+"-"+e[i>>16&255]+e[i>>24&255]+e[255&r]+e[r>>8&255]+e[r>>16&255]+e[r>>24&255]},t}();t.UUID=n}(es||(es={})),function(t){t.getClassName=function(t){return t.className||t.name}}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return __spread(this._completeSlices,[this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(es||(es={})),function(t){var e=function(){function t(t){void 0===t&&(t=64),this.size_=0,this.length=0,this.array=[],this.length=t}return t.prototype.removeAt=function(t){var e=this.array[t];return this.array[t]=this.array[--this.size_],this.array[this.size_]=null,e},t.prototype.remove=function(t){var e,n=this.size_;for(e=0;e0){var t=this.array[--this.size_];return this.array[this.size_]=null,t}return null},t.prototype.contains=function(t){var e,n;for(e=0,n=this.size_;n>e;e++)if(t===this.array[e])return!0;return!1},t.prototype.removeAll=function(t){var e,n,i,r,o=!1;for(e=0,i=t.size();e=this.length)throw new Error("ArrayIndexOutOfBoundsException");return this.array[t]},t.prototype.safeGet=function(t){return t>=this.length&&this.grow(7*t/4+1),this.array[t]},t.prototype.size=function(){return this.size_},t.prototype.getCapacity=function(){return this.length},t.prototype.isIndexWithinBounds=function(t){return t=this.length&&this.grow(2*t),this.size_=t+1,this.array[t]=e},t.prototype.grow=function(t){void 0===t&&(t=1+~~(3*this.length/2)),this.length=~~t},t.prototype.ensureCapacity=function(t){t>=this.length&&this.grow(2*t)},t.prototype.clear=function(){var t,e;for(t=0,e=this.size_;te;e++)this.add(t.get(e))},t}();t.Bag=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=1),this._freeValueCellIndex=0,this._collisions=0,this._valuesInfo=new Array(e),this._values=new Array(e),this._buckets=new Array(t.HashHelpers.getPrime(e))}return e.prototype.getValuesArray=function(t){return t.value=this._freeValueCellIndex,this._values},Object.defineProperty(e.prototype,"valuesArray",{get:function(){return this._values},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"count",{get:function(){return this._freeValueCellIndex},enumerable:!0,configurable:!0}),e.prototype.add=function(t,e){if(!this.addValue(t,e,{value:0}))throw new Error("key 已经存在")},e.prototype.addValue=function(i,r,o){var s=t.HashHelpers.getHashCode(i),a=e.reduce(s,this._buckets.length);if(this._freeValueCellIndex==this._values.length){var h=t.HashHelpers.expandPrime(this._freeValueCellIndex);this._values.length=h,this._valuesInfo.length=h}var c=t.NumberExtension.toNumber(this._buckets[a])-1;if(-1==c)this._valuesInfo[this._freeValueCellIndex]=new n(i,s);else{var u=c;do{if(this._valuesInfo[u].hashcode==s&&this._valuesInfo[u].key==i)return this._values[u]=r,o.value=u,!1;u=this._valuesInfo[u].previous}while(-1!=u);this._collisions++,this._valuesInfo[this._freeValueCellIndex]=new n(i,s,c),this._valuesInfo[c].next=this._freeValueCellIndex}if(this._buckets[a]=this._freeValueCellIndex+1,this._values[this._freeValueCellIndex]=r,o.value=this._freeValueCellIndex,this._freeValueCellIndex++,this._collisions>this._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){return function(t,e){this.element=t,this.next=e}}();function n(t,e){return t===e}t.Node=e,t.defaultEquals=n;var i=function(){function t(t){void 0===t&&(t=n),this.count=0,this.next=void 0,this.equalsFn=t,this.head=null}return t.prototype.push=function(t){var n,i=new e(t);if(null==this.head)this.head=i;else{for(n=this.head;null!=n.next;)n=n.next;n.next=i}this.count++},t.prototype.removeAt=function(t){if(t>=0&&t=0&&t<=this.count){for(var e=this.head,n=0;n=0&&n<=this.count){var i=new e(t);if(0===n)i.next=this.head,this.head=i;else{var r=this.getElementAt(n-1);i.next=r.next,r.next=i}return this.count++,!0}return!1},t.prototype.indexOf=function(t){for(var e=this.head,n=0;n0)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}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.first=t,this.second=e}return e.prototype.clear=function(){this.first=this.second=null},e.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},e.prototype.getHashCode=function(){return 37*t.EqualityComparer.default().getHashCode(this.first)+t.EqualityComparer.default().getHashCode(this.second)},e}();t.Pair=e}(es||(es={})),function(t){var e=function(){function e(){}return e.warmCache=function(t,e){if((e-=this._objectQueue.length)>0)for(var n=0;nthis._objectQueue.length;)this._objectQueue.shift()},e.clearCache=function(){this._objectQueue.length=0},e.obtain=function(t){return this._objectQueue.length>0?this._objectQueue.shift():new t},e.free=function(e){this._objectQueue.unshift(e),t.isIPoolable(e)&&e.reset()},e._objectQueue=[],e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.getHashCode=function(t){return t.getHashCode()},e.prototype.areEqual=function(t,e){return t.equals(e)},e}(function(){function t(t){var e=this;this.clear(),t&&t.forEach(function(t){e.add(t)})}return t.prototype.add=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i){var r=new Array;return r.push(t),this.buckets[n]=r,this.count=this.count+1,!0}return!i.some(function(n){return e.areEqual(n,t)})&&(i.push(t),this.count=this.count+1,!0)},t.prototype.remove=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i)return!1;var r=!1,o=new Array;return i.forEach(function(n){e.areEqual(n,t)?r=!0:o.push(t)}),this.buckets[n]=o,r&&(this.count=this.count-1),r},t.prototype.contains=function(t){return this.bucketsContains(this.buckets,t)},t.prototype.getCount=function(){return this.count},t.prototype.clear=function(){this.buckets=new Array,this.count=0},t.prototype.toArray=function(){var t=new Array;return this.buckets.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},t.prototype.exceptWith=function(t){var e=this;t&&t.forEach(function(t){e.remove(t)})},t.prototype.intersectWith=function(t){var e=this;if(t){var n=this.buildInternalBuckets(t);this.toArray().forEach(function(t){e.bucketsContains(n.Buckets,t)||e.remove(t)})}else this.clear()},t.prototype.unionWith=function(t){var e=this;t.forEach(function(t){e.add(t)})},t.prototype.isSubsetOf=function(t){var e=this,n=this.buildInternalBuckets(t);return this.toArray().every(function(t){return e.bucketsContains(n.Buckets,t)})},t.prototype.isSupersetOf=function(t){var e=this;return t.every(function(t){return e.contains(t)})},t.prototype.overlaps=function(t){var e=this;return t.some(function(t){return e.contains(t)})},t.prototype.setEquals=function(t){var e=this;return this.buildInternalBuckets(t).Count===this.count&&t.every(function(t){return e.contains(t)})},t.prototype.buildInternalBuckets=function(t){var e=this,n=new Array,i=0;return t.forEach(function(t){var r=e.getHashCode(t),o=n[r];if(void 0===o){var s=new Array;s.push(t),n[r]=s,i+=1}else o.some(function(n){return e.areEqual(n,t)})||(o.push(t),i+=1)}),{Buckets:n,Count:i}},t.prototype.bucketsContains=function(t,e){var n=this,i=t[this.getHashCode(e)];return void 0!==i&&i.some(function(t){return n.areEqual(t,e)})},t}());t.HashSet=e}(es||(es={})),function(t){var e=function(){function t(){}return t.waitForSeconds=function(t){return n.waiter.wait(t)},t}();t.Coroutine=e;var n=function(){function t(){this.waitTime=0}return t.prototype.wait=function(e){return t.waiter.waitTime=e,t.waiter},t.waiter=new t,t}();t.WaitForSeconds=n}(es||(es={})),function(t){var e=function(){function t(){this.waitTimer=0,this.useUnscaledDeltaTime=!1}return t.prototype.stop=function(){this.isDone=!0},t.prototype.setUseUnscaledDeltaTime=function(t){return this.useUnscaledDeltaTime=t,this},t.prototype.prepareForUse=function(){this.isDone=!1},t.prototype.reset=function(){this.isDone=!0,this.waitTimer=0,this.waitForCoroutine=null,this.enumerator=null,this.useUnscaledDeltaTime=!1},t}();t.CoroutineImpl=e;var n=function(n){function i(){var t=null!==n&&n.apply(this,arguments)||this;return t._unblockedCoroutines=[],t._shouldRunNextFrame=[],t}return __extends(i,n),i.prototype.startCoroutine=function(n){var i=t.Pool.obtain(e);return i.prepareForUse(),i.enumerator=n,this.tickCoroutine(i)?(this._isInUpdate?this._shouldRunNextFrame.push(i):this._unblockedCoroutines.push(i),i):null},i.prototype.update=function(){this._isInUpdate=!0;for(var e=0;e0?(n.waitTimer-=n.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime,this._shouldRunNextFrame.push(n)):this.tickCoroutine(n)&&this._shouldRunNextFrame.push(n)}}var i=new t.List(this._unblockedCoroutines);i.clear(),i.addRange(this._shouldRunNextFrame),this._shouldRunNextFrame.length=0,this._isInUpdate=!1},i.prototype.tickCoroutine=function(n){var i=n.enumerator.next();return i.done||n.isDone?(t.Pool.free(n),!1):null==i.value||(i.value instanceof t.WaitForSeconds?(n.waitTimer=i.value.waitTime,!0):"number"==typeof i.value?(n.waitTimer=i.value,!0):"string"==typeof i.value?"break"!=i.value||(t.Pool.free(n),!1):!(i.value instanceof e)||(n.waitForCoroutine=i.value,!0))},i}(t.GlobalManager);t.CoroutineManager=n}(es||(es={})),function(t){var e=function(){function e(t,e,n){void 0===n&&(n=!0),this.binWidth=0,this.binHeight=0,this.usedRectangles=[],this.freeRectangles=[],this.init(t,e,n)}return e.prototype.init=function(e,n,i){void 0===i&&(i=!0),this.binWidth=e,this.binHeight=n,this.allowRotations=i;var r=new t.Rectangle;r.x=0,r.y=0,r.width=e,r.height=n,this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(r)},e.prototype.insert=function(e,n){var i=new t.Rectangle,r=new t.Ref(0),o=new t.Ref(0);if(0==(i=this.findPositionForNewNodeBestAreaFit(e,n,r,o)).height)return i;for(var s=this.freeRectangles.length,a=0;a=e&&this.freeRectangles[s].height>=n){var h=Math.abs(this.freeRectangles[s].width-e),c=Math.abs(this.freeRectangles[s].height-n),u=Math.min(h,c);(a=n&&this.freeRectangles[s].height>=e){h=Math.abs(this.freeRectangles[s].width-n),c=Math.abs(this.freeRectangles[s].height-e),u=Math.min(h,c);(a=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y)return!1;if(e.xt.x){if(e.y>t.y&&e.yt.y){var n;if(e.x>t.x&&e.x=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height},e}();t.MaxRectsBinPack=e}(es||(es={})),function(t){var e=function(){function e(){}return e.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},e.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},e.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},e.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},e.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},e.cloneList=function(t){return t?t.slice(0,t.length):null},e.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},e.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},e.shuffle=function(e){for(var n=e.length;n>1;){n--;var i=t.RandomUtils.randint(0,n+1),r=e[i];e[i]=e[n],e[n]=r}},e.addIfNotPresent=function(e,n){return!new t.List(e).contains(n)&&(e.push(n),!0)},e.lastItem=function(t){return t[t.length-1]},e.randomItem=function(e){return e[t.RandomUtils.randint(0,e.length-1)]},e.randomItems=function(e,n){for(var i=new Set;i.size!=n;){var r=this.randomItem(e);i.has(r)||i.add(r)}var o=t.ListPool.obtain();return i.forEach(function(t){return o.push(t)}),o},e}();t.ArrayUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],h=0;h>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(h++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(h++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(n)),64!==s&&a.push(String.fromCharCode(i));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,n,i,r,o,s,a,h=[],c=0;c>2,o=(3&e)<<4|(n=t.charCodeAt(c++))>>4,s=(15&n)<<2|(i=t.charCodeAt(c++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),h.push(this._keyStr.charAt(r)),h.push(this._keyStr.charAt(o)),h.push(this._keyStr.charAt(s)),h.push(this._keyStr.charAt(a));return h=h.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random().5?1:-1},t}();t.RandomUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,i.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e.boundsFromPolygonVector=function(e){for(var n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,s=0;sr&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(n,i),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,n){return new t.Rectangle(e.x,e.y,n.x-e.x,n.y-e.y)},e.getSweptBroadphaseBounds=function(e,n,i){var r=t.Rectangle.empty;return r.x=n>0?e.x:e.x+n,r.y=i>0?e.y:e.y+i,r.width=n>0?n+e.width:e.width-n,r.height=i>0?i+e.height:e.height-i,r},e.prototype.collisionCheck=function(t,e,n,i){n.value=i.value=0;var r=e.x-(t.x+t.width),o=e.x+e.width-t.x,s=e.y-(t.y+t.height),a=e.y+e.height-t.y;return!(r>0||o<0||s>0||a<0)&&(n.value=Math.abs(r)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e.getClosestPointOnBoundsToOrigin=function(e){var n=this.getMax(e),i=Math.abs(e.location.x),r=new t.Vector2(e.location.x,0);return Math.abs(n.x)r&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(Math.trunc(n),Math.trunc(i)),new t.Vector2(Math.trunc(r),Math.trunc(o)))},e.calculateBounds=function(e,n,i,r,o,s,a,h){if(0==s)e.x=Math.trunc(n.x+i.x-r.x*o.x),e.y=Math.trunc(n.y+i.y-r.y*o.y),e.width=Math.trunc(a*o.x),e.height=Math.trunc(h*o.y);else{var c=n.x+i.x,u=n.y+i.y,l=void 0,p=t.Matrix2D.createTranslation(-c-r.x,-u-r.y);l=t.Matrix2D.createScale(o.x,o.y),p=p.multiply(l),l=t.Matrix2D.createRotation(s),p=p.multiply(l),l=t.Matrix2D.createTranslation(c,u),p=p.multiply(l);var f=new t.Vector2(c,u),d=new t.Vector2(c+a,u),m=new t.Vector2(c,u+h),y=new t.Vector2(c+a,u+h);t.Vector2Ext.transformR(f,p,f),t.Vector2Ext.transformR(d,p,d),t.Vector2Ext.transformR(m,p,m),t.Vector2Ext.transformR(y,p,y);var g=Math.trunc(Math.min(f.x,y.x,d.x,m.x)),_=Math.trunc(Math.max(f.x,y.x,d.x,m.x)),v=Math.trunc(Math.min(f.y,y.y,d.y,m.y)),b=Math.trunc(Math.max(f.y,y.y,d.y,m.y));e.location=new t.Vector2(g,v),e.width=Math.trunc(_-g),e.height=Math.trunc(b-v)}},e.scale=function(t,e){t.x=Math.trunc(t.x*e.x),t.y=Math.trunc(t.y*e.y),t.width=Math.trunc(t.width*e.x),t.height=Math.trunc(t.height*e.y)},e.translate=function(t,e){t.location.addEqual(e)},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function t(){}return t.premultiplyAlpha=function(t){for(var e=t[0],n=0;nt.MathHelper.Epsilon?e.divideScaler(n):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){return this.sum(t)/this.count(t)},e.prototype.cast=function(){return new e(this._elements)},e.prototype.clear=function(){this._elements.length=0},e.prototype.concat=function(t){return new e(this._elements.concat(t.toArray()))},e.prototype.contains=function(t){return this.any(function(e){return e===t})},e.prototype.count=function(t){return t?this.where(t).count():this._elements.length},e.prototype.defaultIfEmpty=function(t){return this.count()?this:new e([t])},e.prototype.distinctBy=function(t){var n=this.groupBy(t);return Object.keys(n).reduce(function(t,e){return t.add(n[e][0]),t},new e)},e.prototype.elementAt=function(t){if(t=0)return this._elements[t];throw new Error("ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.")},e.prototype.elementAtOrDefault=function(t){return t=0?this._elements[t]:void 0},e.prototype.except=function(t){return this.where(function(e){return!t.contains(e)})},e.prototype.first=function(t){if(this.count())return t?this.where(t).first():this._elements[0];throw new Error("InvalidOperationException: The source sequence is empty.")},e.prototype.firstOrDefault=function(t){return this.count(t)?this.first(t):void 0},e.prototype.forEach=function(t){return this._elements.forEach(t)},e.prototype.groupBy=function(t,e){void 0===e&&(e=function(t){return t});return this.aggregate(function(n,i){var r=t(i),o=n[r],s=e(i);return o?o.push(s):n[r]=[s],n},{})},e.prototype.groupJoin=function(t,e,n,i){return this.select(function(r){return i(r,t.where(function(t){return e(r)===n(t)}))})},e.prototype.indexOf=function(t){return this._elements.indexOf(t)},e.prototype.insert=function(t,e){if(t<0||t>this._elements.length)throw new Error("Index is out of range.");this._elements.splice(t,0,e)},e.prototype.intersect=function(t){return this.where(function(e){return t.contains(e)})},e.prototype.join=function(t,e,n,i){return this.selectMany(function(r){return t.where(function(t){return n(t)===e(r)}).select(function(t){return i(r,t)})})},e.prototype.last=function(t){if(this.count())return t?this.where(t).last():this._elements[this.count()-1];throw Error("InvalidOperationException: The source sequence is empty.")},e.prototype.lastOrDefault=function(t){return this.count(t)?this.last(t):void 0},e.prototype.max=function(t){return Math.max.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.min=function(t){return Math.min.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.ofType=function(t){var e;switch(t){case Number:e="number";break;case String:e="string";break;case Boolean:e=typeof!0;break;case Function:e="function";break;default:e=null}return null===e?this.where(function(e){return e instanceof t}).cast():this.where(function(t){return typeof t===e}).cast()},e.prototype.orderBy=function(e,i){return void 0===i&&(i=t.keyComparer(e,!1)),new n(this._elements,i)},e.prototype.orderByDescending=function(e,i){return void 0===i&&(i=t.keyComparer(e,!0)),new n(this._elements,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){return-1!==this.indexOf(t)&&(this.removeAt(this.indexOf(t)),!0)},e.prototype.removeAll=function(e){return this.where(t.negate(e))},e.prototype.removeAt=function(t){this._elements.splice(t,1)},e.prototype.reverse=function(){return new e(this._elements.reverse())},e.prototype.select=function(t){return new e(this._elements.map(t))},e.prototype.selectMany=function(t){var n=this;return this.aggregate(function(e,i,r){return e.addRange(n.select(t).elementAt(r).toArray()),e},new e)},e.prototype.sequenceEqual=function(t){return this.all(function(e){return t.contains(e)})},e.prototype.single=function(t){if(1!==this.count(t))throw new Error("The collection does not contain exactly one element.");return this.first(t)},e.prototype.singleOrDefault=function(t){return this.count(t)?this.single(t):void 0},e.prototype.skip=function(t){return new e(this._elements.slice(Math.max(0,t)))},e.prototype.skipLast=function(t){return new e(this._elements.slice(0,-Math.max(0,t)))},e.prototype.skipWhile=function(t){var e=this;return this.skip(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.sum=function(t){return t?this.select(t).sum():this.aggregate(function(t,e){return t+ +e},0)},e.prototype.take=function(t){return new e(this._elements.slice(0,Math.max(0,t)))},e.prototype.takeLast=function(t){return new e(this._elements.slice(-Math.max(0,t)))},e.prototype.takeWhile=function(t){var e=this;return this.take(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.toArray=function(){return this._elements},e.prototype.toDictionary=function(t,n){var i=this;return this.aggregate(function(e,r,o){return e[i.select(t).elementAt(o).toString()]=n?i.select(n).elementAt(o):r,e.add({Key:i.select(t).elementAt(o),Value:n?i.select(n).elementAt(o):r}),e},new e)},e.prototype.toSet=function(){var t,e,n=new Set;try{for(var i=__values(this._elements),r=i.next();!r.done;r=i.next()){var o=r.value;n.add(o)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return n},e.prototype.toList=function(){return this},e.prototype.toLookup=function(t,e){return this.groupBy(t,e)},e.prototype.where=function(t){return new e(this._elements.filter(t))},e.prototype.zip=function(t,e){var n=this;return t.count()e.angle?1:t.angleMath.PI&&(o-=2*Math.PI),r.p1.begin=o>0,r.p2.begin=!r.p1.begin}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}this._isSpotLight&&(this._spotStartAngle=this._segments[0].p2.angle,this._spotEndAngle=this._segments[1].p2.angle)},e._cornerCache=[],e._openSegments=new t.LinkedList,e}();t.VisibilityComputer=e}(es||(es={})),function(t){var e=function(){function e(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}return e.prototype.getContext=function(){return this.context},e.prototype.reset=function(){this._elapsedTime=0},e.prototype.stop=function(){this._isDone=!0},e.prototype.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=t.Time.deltaTime,this._isDone},e.prototype.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var e=this._timers.length-1;e>=0;e--)this._timers[e].tick()&&(this._timers[e].unload(),new t.List(this._timers).removeAt(e))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Components/Physics/ArcadeRigidbody.ts b/source/src/ECS/Components/Physics/ArcadeRigidbody.ts index 68c147a2..fe107568 100644 --- a/source/src/ECS/Components/Physics/ArcadeRigidbody.ts +++ b/source/src/ECS/Components/Physics/ArcadeRigidbody.ts @@ -127,8 +127,7 @@ module es { */ public addImpulse(force: Vector2) { if (!this.isImmovable) { - this.velocity = Vector2.add(this.velocity, Vector2.multiplyScaler(force, 100000) - .multiplyScaler(this._inverseMass * Time.deltaTime * Time.deltaTime)); + this.velocity.addEqual(force.scale(100000 * (this._inverseMass * (Time.deltaTime * Time.deltaTime)))); } } @@ -152,7 +151,7 @@ module es { if (this.shouldUseGravity) this.velocity.addEqual(Physics.gravity.scale(Time.deltaTime)); - this.entity.position = Vector2.add(this.entity.position, Vector2.multiplyScaler(this.velocity, Time.deltaTime)); + this.entity.position = this.entity.position.add(this.velocity.scale(Time.deltaTime)); let collisionResult = new CollisionResult(); @@ -175,7 +174,7 @@ module es { this.processCollision(neighborRigidbody, collisionResult.minimumTranslationVector); } else { // 没有ArcadeRigidbody,所以我们假设它是不动的,只移动我们自己的 - this.entity.position = Vector2.subtract(this.entity.position, collisionResult.minimumTranslationVector); + this.entity.position = this.entity.position.sub(collisionResult.minimumTranslationVector); const relativeVelocity = this.calculateResponseVelocity(this.velocity, collisionResult.minimumTranslationVector); this.velocity.addEqual(relativeVelocity); } @@ -208,7 +207,7 @@ module es { // 我们计算两个相撞物体的响应。 // 计算的基础是沿碰撞表面法线反射的物体的相对速度。 // 然后,响应的一部分会根据质量加到每个物体上 - let relativeVelocity = Vector2.subtract(this.velocity, other.velocity); + let relativeVelocity = this.velocity.sub(other.velocity); relativeVelocity = this.calculateResponseVelocity(relativeVelocity, minimumTranslationVector); @@ -218,8 +217,8 @@ module es { const otherResponseFraction = other._inverseMass / totalinverseMass; - this.velocity = Vector2.add(this.velocity, relativeVelocity.scale(ourResponseFraction)); - other.velocity = Vector2.subtract(other.velocity, relativeVelocity.scale(otherResponseFraction)); + this.velocity = this.velocity.add(relativeVelocity.scale(ourResponseFraction)); + other.velocity = other.velocity.sub(relativeVelocity.scale(otherResponseFraction)); } /** @@ -230,14 +229,14 @@ module es { */ public calculateResponseVelocity(relativeVelocity: Vector2, minimumTranslationVector: Vector2) { // 首先,我们得到反方向的归一化MTV:表面法线 - let inverseMTV = Vector2.multiplyScaler(minimumTranslationVector, -1); - let normal = Vector2.normalize(inverseMTV); + let inverseMTV = minimumTranslationVector.scale(-1); + let normal = inverseMTV.normalize(); // 速度是沿碰撞法线和碰撞平面分解的。 // 弹性将影响沿法线的响应(法线速度分量),摩擦力将影响速度的切向分量(切向速度分量) - let n = Vector2.dot(relativeVelocity, normal); + let n = relativeVelocity.dot(normal); - let normalVelocityComponent = Vector2.multiplyScaler(normal, n); - let tangentialVelocityComponent = Vector2.subtract(relativeVelocity, normalVelocityComponent); + let normalVelocityComponent = normal.scale(n); + let tangentialVelocityComponent = relativeVelocity.sub(normalVelocityComponent); if (n > 0) normalVelocityComponent = Vector2.zero; diff --git a/source/src/ECS/Components/Physics/CharacterController.ts b/source/src/ECS/Components/Physics/CharacterController.ts index 3b1d5fe0..c59def39 100644 --- a/source/src/ECS/Components/Physics/CharacterController.ts +++ b/source/src/ECS/Components/Physics/CharacterController.ts @@ -301,16 +301,16 @@ module es { this.supportSlopedOneWayPlatforms && this.collisionState.wasGroundedLastFrame ) { - this._raycastHit = Physics.linecastIgnoreCollider( + this._raycastHit = Physics.linecast( ray, - ray.add(rayDirection.multiplyScaler(rayDistance)), + ray.add(rayDirection.scaleEqual(rayDistance)), this.platformMask, this.ignoredColliders ); } else { - this._raycastHit = Physics.linecastIgnoreCollider( + this._raycastHit = Physics.linecast( ray, - ray.add(rayDirection.multiplyScaler(rayDistance)), + ray.add(rayDirection.scaleEqual(rayDistance)), this.platformMask & ~this.oneWayPlatformMask, this.ignoredColliders ); @@ -380,9 +380,9 @@ module es { initialRayOriginX + i * this._horizontalDistanceBetweenRays, initialRayOriginY ); - this._raycastHit = Physics.linecastIgnoreCollider( + this._raycastHit = Physics.linecast( rayStart, - rayStart.add(rayDirection.multiplyScaler(rayDistance)), + rayStart.add(rayDirection.scaleEqual(rayDistance)), mask, this.ignoredColliders ); @@ -439,9 +439,9 @@ module es { this._raycastOrigins.bottomLeft.y ); - this._raycastHit = Physics.linecastIgnoreCollider( + this._raycastHit = Physics.linecast( slopeRay, - slopeRay.add(rayDirection.multiplyScaler(slopeCheckRayDistance)), + slopeRay.add(rayDirection.scaleEqual(slopeCheckRayDistance)), this.platformMask, this.ignoredColliders ); @@ -502,14 +502,14 @@ module es { this.supportSlopedOneWayPlatforms && this.collisionState.wasGroundedLastFrame ) { - raycastHit = Physics.linecastIgnoreCollider( + raycastHit = Physics.linecast( ray, ray.add(deltaMovement), this.platformMask, this.ignoredColliders ); } else { - raycastHit = Physics.linecastIgnoreCollider( + raycastHit = Physics.linecast( ray, ray.add(deltaMovement), this.platformMask & ~this.oneWayPlatformMask, diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index ed82e9f2..d01ff7d4 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -1,5 +1,7 @@ module es { export abstract class Collider extends Component { + public static readonly lateSortOrder = 999; + public castSortOrder: number = 0; /** * 对撞机的基本形状 */ @@ -132,12 +134,12 @@ module es { if (this instanceof CircleCollider) { this.radius = Math.max(width, height) * 0.5; - this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position); + this.localOffset = renderableBounds.center.sub(this.entity.transform.position); } else if (this instanceof BoxCollider) { this.width = width; this.height = height; - this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position); + this.localOffset = renderableBounds.center.sub(this.entity.transform.position); } } } @@ -264,8 +266,8 @@ module es { continue; if (this.collidesWithNonMotion(neighbor, result)) { - motion = Vector2.subtract(motion, result.minimumTranslationVector); - this.shape.position = Vector2.subtract(this.shape.position, result.minimumTranslationVector); + motion = motion.sub(result.minimumTranslationVector); + this.shape.position = this.shape.position.sub(result.minimumTranslationVector); didCollide = true; } } diff --git a/source/src/ECS/Transform.ts b/source/src/ECS/Transform.ts index d43c2969..911f23b6 100644 --- a/source/src/ECS/Transform.ts +++ b/source/src/ECS/Transform.ts @@ -347,9 +347,9 @@ module es { * @param pos */ public lookAt(pos: Vector2) { - let sign = this.position.x > pos.x ? -1 : 1; - let vectorToAlignTo = Vector2.normalize(Vector2.subtract(this.position, pos)); - this.rotation = sign * Math.acos(Vector2.dot(vectorToAlignTo, Vector2.unitY)); + const sign = this.position.x > pos.x ? -1 : 1; + const vectorToAlignTo = this.position.sub(pos).normalize(); + this.rotation = sign * Math.acos(vectorToAlignTo.dot(Vector2.unitY)); } /** @@ -412,22 +412,22 @@ module es { if (this._localDirty) { if (this._localPositionDirty) { - this._translationMatrix = Matrix2D.createTranslation(this._localPosition.x, this._localPosition.y); + Matrix2D.createTranslation(this._localPosition.x, this._localPosition.y, this._translationMatrix); this._localPositionDirty = false; } if (this._localRotationDirty) { - this._rotationMatrix = Matrix2D.createRotation(this._localRotation); + Matrix2D.createRotation(this._localRotation, this._rotationMatrix); this._localRotationDirty = false; } if (this._localScaleDirty) { - this._scaleMatrix = Matrix2D.createScale(this._localScale.x, this._localScale.y); + Matrix2D.createScale(this._localScale.x, this._localScale.y, this._scaleMatrix); this._localScaleDirty = false; } - es.Matrix2D.multiply(this._scaleMatrix, this._rotationMatrix, this._localTransform); - es.Matrix2D.multiply(this._localTransform, this._translationMatrix, this._localTransform); + Matrix2D.multiply(this._scaleMatrix, this._rotationMatrix, this._localTransform); + Matrix2D.multiply(this._localTransform, this._translationMatrix, this._localTransform); if (this.parent == null) { this._worldTransform = this._localTransform; @@ -440,9 +440,9 @@ module es { } if (this.parent != null) { - es.Matrix2D.multiply(this._localTransform, this.parent._worldTransform, this._worldTransform); + Matrix2D.multiply(this._localTransform, this.parent._worldTransform, this._worldTransform); this._rotation = this._localRotation + this.parent._rotation; - this._scale = Vector2.multiply(this.parent._scale, this._localScale); + this._scale = this.parent._scale.multiply(this._localScale);; this._worldInverseDirty = true; } @@ -457,13 +457,13 @@ module es { this.hierarchyDirty |= dirtyFlagType; switch (dirtyFlagType) { - case es.DirtyType.positionDirty: + case DirtyType.positionDirty: this.entity.onTransformChanged(transform.Component.position); break; - case es.DirtyType.rotationDirty: + case DirtyType.rotationDirty: this.entity.onTransformChanged(transform.Component.rotation); break; - case es.DirtyType.scaleDirty: + case DirtyType.scaleDirty: this.entity.onTransformChanged(transform.Component.scale); break; } diff --git a/source/src/Math/Bezier.ts b/source/src/Math/Bezier.ts index 70ccc7d6..0906e922 100644 --- a/source/src/Math/Bezier.ts +++ b/source/src/Math/Bezier.ts @@ -44,8 +44,8 @@ module es { * @param t */ public static getFirstDerivative(p0: Vector2, p1: Vector2, p2: Vector2, t: number) { - return new Vector2(2 * (1 - t)).multiply(Vector2.subtract(p1, p0)) - .addEqual(new Vector2(2 * t).multiply(Vector2.subtract(p2, p1))); + return p1.sub(p0).scale(2 * (1 - t)) + .addEqual(p2.sub(p1).scale(2 * t)); } /** @@ -60,9 +60,9 @@ module es { end: Vector2, t: number) { t = MathHelper.clamp01(t); let oneMunusT = 1 - t; - return new Vector2(3 * oneMunusT * oneMunusT).multiply(Vector2.subtract(firstControlPoint, start)) - .addEqual(new Vector2(6 * oneMunusT * t).multiply(Vector2.subtract(secondControlPoint, firstControlPoint))) - .addEqual(new Vector2(3 * t * t).multiply(Vector2.subtract(end, secondControlPoint))); + return firstControlPoint.sub(start).scale(3 * oneMunusT * oneMunusT) + .addEqual(secondControlPoint.sub(firstControlPoint).scale(6 * oneMunusT * t)) + .addEqual(end.sub(secondControlPoint).scale(3 * t * t)); } /** @@ -96,19 +96,19 @@ module es { private static recursiveGetOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, end: Vector2, points: Vector2[], distanceTolerance: number) { // 计算线段的所有中点 - let pt12 = Vector2.divideScaler(Vector2.add(start, firstCtrlPoint), 2); - let pt23 = Vector2.divideScaler(Vector2.add(firstCtrlPoint, secondCtrlPoint), 2); - let pt34 = Vector2.divideScaler(Vector2.add(secondCtrlPoint, end), 2); + let pt12 = Vector2.divideScaler(start.add(firstCtrlPoint), 2); + let pt23 = Vector2.divideScaler(firstCtrlPoint.add(secondCtrlPoint), 2); + let pt34 = Vector2.divideScaler(secondCtrlPoint.add(end), 2); // 计算新半直线的中点 - let pt123 = Vector2.divideScaler(Vector2.add(pt12, pt23), 2); - let pt234 = Vector2.divideScaler(Vector2.add(pt23, pt34), 2); + let pt123 = Vector2.divideScaler(pt12.add(pt23), 2); + let pt234 = Vector2.divideScaler(pt23.add(pt34), 2); // 最后再细分最后两个中点。如果我们满足我们的距离公差,这将是我们使用的最后一点。 - let pt1234 = Vector2.divideScaler(Vector2.add(pt123, pt234), 2); + let pt1234 = Vector2.divideScaler(pt123.add(pt234), 2); // 试着用一条直线来近似整个三次曲线 - let deltaLine = Vector2.subtract(end, start); + let deltaLine = end.sub(start); let d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x)); let d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x)); diff --git a/source/src/Math/BezierSpline.ts b/source/src/Math/BezierSpline.ts index 9acc0c4d..c81300be 100644 --- a/source/src/Math/BezierSpline.ts +++ b/source/src/Math/BezierSpline.ts @@ -10,19 +10,20 @@ module es { * 在这个过程中,t被修改为在曲线段的范围内。 * @param t */ - public pointIndexAtTime(t: Ref): number { - let i = 0; - if (t.value >= 1) { - t.value = 1; - i = this._points.length - 4; + public pointIndexAtTime(t: number): {time: number, range: number} { + const res = {time: 0, range: 0}; + if (t >= 1) { + t = 1; + res.range = this._points.length - 4; } else { - t.value = MathHelper.clamp01(t.value) * this._curveCount; - i = ~~t; - t.value -= i; - i *= 3; + t = MathHelper.clamp01(t) * this._curveCount; + res.range = Math.floor(t); + t -= res.range; + res.range *= 3; } - return i; + res.time = t; + return res; } /** @@ -32,7 +33,7 @@ module es { */ public setControlPoint(index: number, point: Vector2) { if (index % 3 == 0) { - let delta = Vector2.subtract(point, this._points[index]); + const delta = point.sub(this._points[index]); if (index > 0) this._points[index - 1].addEqual(delta); @@ -48,7 +49,8 @@ module es { * @param t */ public getPointAtTime(t: number): Vector2{ - let i = this.pointIndexAtTime(new Ref(t)); + const res = this.pointIndexAtTime(t); + const i = res.range; return Bezier.getPointThree(this._points[i], this._points[i + 1], this._points[i + 2], this._points[i + 3], t); } @@ -58,7 +60,8 @@ module es { * @param t */ public getVelocityAtTime(t: number): Vector2 { - let i = this.pointIndexAtTime(new Ref(t)); + const res = this.pointIndexAtTime(t); + const i = res.range; return Bezier.getFirstDerivativeThree(this._points[i], this._points[i + 1], this._points[i + 2], this._points[i + 3], t); } @@ -68,7 +71,7 @@ module es { * @param t */ public getDirectionAtTime(t: number) { - return Vector2.normalize(this.getVelocityAtTime(t)); + return this.getVelocityAtTime(t).normalize(); } /** diff --git a/source/src/Math/MathHelper.ts b/source/src/Math/MathHelper.ts index d8683261..38034608 100644 --- a/source/src/Math/MathHelper.ts +++ b/source/src/Math/MathHelper.ts @@ -390,8 +390,8 @@ module es { * @param other */ public static project(self: Vector2, other: Vector2) { - let amt = Vector2.dot(self, other) / other.lengthSquared(); - let vec = new Vector2(amt * other.x, amt * other.y); + let amt = self.dot(other) / other.lengthSquared(); + let vec = other.scale(amt); return vec; } @@ -606,7 +606,7 @@ module es { return false; } - return !Number.isFinite(x); + return x !== Infinity; } public static smoothDamp(current: number, target: number, currentVelocity: number, smoothTime: number, maxSpeed: number, deltaTime: number): { value: number; currentVelocity: number } { @@ -671,5 +671,9 @@ module es { public static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax): number { return rightMin + ((MathHelper.clamp(value, leftMin, leftMax) - leftMin) * (rightMax - rightMin)) / (leftMax - leftMin); } + + public static fromAngle(angle: number) { + return new Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual(); + } } } diff --git a/source/src/Math/Matrix2D.ts b/source/src/Math/Matrix2D.ts index 407491e9..487b3707 100644 --- a/source/src/Math/Matrix2D.ts +++ b/source/src/Math/Matrix2D.ts @@ -16,7 +16,28 @@ module es { * 返回标识矩阵 */ public static get identity(): Matrix2D { - return new Matrix2D(1, 0, 0, 1, 0, 0); + return new Matrix2D().setIdentity(); + } + + public setIdentity(): Matrix2D { + return this.setValues(1, 0, 0, 1, 0, 0); + } + + public setValues( + m11: number, + m12: number, + m21: number, + m22: number, + m31: number, + m32: number + ): Matrix2D { + this.m11 = m11; + this.m12 = m12; + this.m21 = m21; + this.m22 = m22; + this.m31 = m31; + this.m32 = m32; + return this; } /** @@ -38,7 +59,7 @@ module es { return Math.atan2(this.m21, this.m11); } - public set rotation(value: number){ + public set rotation(value: number) { let val1 = Math.cos(value); let val2 = Math.sin(value); @@ -71,42 +92,18 @@ module es { this.m22 = value.y; } - /** - * 构建一个矩阵 - * @param m11 - * @param m12 - * @param m21 - * @param m22 - * @param m31 - * @param m32 - */ - constructor(m11: number, m12: number, m21: number, m22: number, m31: number, m32: number){ - this.m11 = m11; - this.m12 = m12; - - this.m21 = m21; - this.m22 = m22; - - this.m31 = m31; - this.m32 = m32; - } - /** * 创建一个新的围绕Z轴的旋转矩阵2D * @param radians */ - public static createRotation(radians: number){ - let result: Matrix2D = this.identity; - - let val1 = Math.cos(radians); - let val2 = Math.sin(radians); - + public static createRotation(radians: number, result: Matrix2D) { + result.setIdentity(); + const val1 = Math.cos(radians); + const val2 = Math.sin(radians); result.m11 = val1; result.m12 = val2; - result.m21 = -val2; + result.m21 = val2 * -1; result.m22 = val1; - - return result; } public static createRotationOut(radians: number, result: Matrix2D) { @@ -124,18 +121,13 @@ module es { * @param xScale * @param yScale */ - public static createScale(xScale: number, yScale: number){ - let result: Matrix2D = this.identity; + public static createScale(xScale: number, yScale: number, result: Matrix2D) { result.m11 = xScale; result.m12 = 0; - result.m21 = 0; result.m22 = yScale; - result.m31 = 0; result.m32 = 0; - - return result; } public static createScaleOut(xScale: number, yScale: number, result: Matrix2D) { @@ -154,14 +146,11 @@ module es { * @param xPosition * @param yPosition */ - public static createTranslation(xPosition: number, yPosition: number) { - let result: Matrix2D = this.identity; + public static createTranslation(xPosition: number, yPosition: number, result: Matrix2D) { result.m11 = 1; result.m12 = 0; - result.m21 = 0; result.m22 = 1; - result.m31 = xPosition; result.m32 = yPosition; @@ -261,14 +250,14 @@ module es { } public static multiply(matrix1: Matrix2D, matrix2: Matrix2D, result: Matrix2D) { - let m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); - let m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); + const m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); + const m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); - let m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); - let m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); + const m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); + const m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); - let m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; - let m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; + const m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; + const m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; result.m11 = m11; result.m12 = m12; @@ -278,8 +267,6 @@ module es { result.m31 = m31; result.m32 = m32; - - return result; } public determinant() { @@ -292,10 +279,10 @@ module es { * @param matrix2 * @param amount */ - public static lerp(matrix1: Matrix2D, matrix2: Matrix2D, amount: number){ + public static lerp(matrix1: Matrix2D, matrix2: Matrix2D, amount: number) { matrix1.m11 = matrix1.m11 + ((matrix2.m11 - matrix1.m11) * amount); matrix1.m12 = matrix1.m12 + ((matrix2.m12 - matrix1.m12) * amount); - + matrix1.m21 = matrix1.m21 + ((matrix2.m21 - matrix1.m21) * amount); matrix1.m22 = matrix1.m22 + ((matrix2.m22 - matrix1.m22) * amount); @@ -321,8 +308,9 @@ module es { return ret; } - public mutiplyTranslation(x: number, y: number){ - let trans = Matrix2D.createTranslation(x, y); + public mutiplyTranslation(x: number, y: number) { + let trans = new Matrix2D(); + Matrix2D.createTranslation(x, y, trans); return MatrixHelper.mutiply(this, trans); } @@ -330,7 +318,7 @@ module es { * 比较当前实例是否等于指定的Matrix2D * @param other */ - public equals(other: Matrix2D){ + public equals(other: Matrix2D) { return this == other; } diff --git a/source/src/Math/Rectangle.ts b/source/src/Math/Rectangle.ts index 6f73b177..d18f9c02 100644 --- a/source/src/Math/Rectangle.ts +++ b/source/src/Math/Rectangle.ts @@ -107,8 +107,8 @@ module es { } // temp 用于计算边界的矩阵 - public _tempMat: Matrix2D; - public _transformMat: Matrix2D; + public _tempMat: Matrix2D = new Matrix2D(); + public _transformMat: Matrix2D = new Matrix2D(); /** * 创建一个新的Rectanglestruct实例,指定位置、宽度和高度。 @@ -213,49 +213,50 @@ module es { this.top < value.bottom; } - public rayIntersects(ray: Ray2D, distance: Ref): boolean { - distance.value = 0; + public rayIntersects(ray: Ray2D): { intersected: boolean; distance: number } { + const res = {intersected: false, distance: 0}; let maxValue = Number.MAX_VALUE; if (Math.abs(ray.direction.x) < 1E-06) { if ((ray.start.x < this.x) || (ray.start.x > this.x + this.width)) - return false; + return res; } else { - let num11 = 1 / ray.direction.x; + const num11 = 1 / ray.direction.x; let num8 = (this.x - ray.start.x) * num11; let num7 = (this.x + this.width - ray.start.x) * num11; if (num8 > num7) { - let num14 = num8; + const num14 = num8; num8 = num7; num7 = num14; } - distance.value = Math.max(num8, distance.value); + res.distance = Math.max(num8, res.distance); maxValue = Math.min(num7, maxValue); - if (distance.value > maxValue) - return false; + if (res.distance > maxValue) + return res; } - if (Math.abs(ray.direction.y) < 1E-06) { + if (Math.abs(ray.direction.y) < 1e-06) { if ((ray.start.y < this.y) || (ray.start.y > this.y + this.height)) - return false; + return res; } else { - let num10 = 1 / ray.direction.y; + const num10 = 1 / ray.direction.y; let num6 = (this.y - ray.start.y) * num10; let num5 = (this.y + this.height - ray.start.y) * num10; if (num6 > num5) { - let num13 = num6; + const num13 = num6; num6 = num5; num5 = num13; } - distance.value = Math.max(num6, distance.value); + res.distance = Math.max(num6, res.distance); maxValue = Math.max(num5, maxValue); - if (distance.value > maxValue) - return false; + if (res.distance > maxValue) + return res; } - return true; + res.intersected = true; + return res; } /** @@ -421,12 +422,12 @@ module es { let worldPosY = parentPosition.y + position.y; // 考虑到原点,将参考点设置为世界参考 - this._transformMat = Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y); - this._tempMat = Matrix2D.createScale(scale.x, scale.y); + Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y, this._transformMat); + Matrix2D.createScale(scale.x, scale.y, this._tempMat); this._transformMat = this._transformMat.multiply(this._tempMat); - this._tempMat = Matrix2D.createRotation(rotation); + Matrix2D.createRotation(rotation, this._tempMat); this._transformMat = this._transformMat.multiply(this._tempMat); - this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY); + Matrix2D.createTranslation(worldPosX, worldPosY, this._tempMat); this._transformMat = this._transformMat.multiply(this._tempMat); // TODO: 我们可以把世界变换留在矩阵中,避免在世界空间中得到所有的四个角 diff --git a/source/src/Math/Vector2.ts b/source/src/Math/Vector2.ts index 4ecc3059..da20a636 100644 --- a/source/src/Math/Vector2.ts +++ b/source/src/Math/Vector2.ts @@ -77,74 +77,13 @@ module es { return result; } - /** - * - * @param value1 - * @param value2 - */ - public static multiply(value1: Vector2, value2: Vector2) { - let result: Vector2 = es.Vector2.zero; - result.x = value1.x * value2.x; - result.y = value1.y * value2.y; - return result; - } - - /** - * - * @param value1 - * @param value2 - * @returns - */ - public static multiplyScaler(value1: Vector2, value2: number) { - let result = es.Vector2.zero; - result.x = value1.x * value2; - result.y = value1.y * value2; - return result; - } - - /** - * - * @param value1 - * @param value2 - */ - public static subtract(value1: Vector2, value2: Vector2) { - let result: Vector2 = es.Vector2.zero; - result.x = value1.x - value2.x; - result.y = value1.y - value2.y; - return result; - } - - /** - * 创建一个新的Vector2 - * 它包含来自另一个向量的标准化值。 - * @param value - */ - public static normalize(value: Vector2) { - const d = value.distance(); - if (d > 0) { - return new Vector2(value.x / d, value.y / d); - } else { - return new Vector2(0, 1); - } - } - - /** - * 返回两个向量的点积 - * @param value1 - * @param value2 - */ - public static dot(value1: Vector2, value2: Vector2): number { - return (value1.x * value2.x) + (value1.y * value2.y); - } - /** * 返回两个向量之间距离的平方 * @param value1 * @param value2 */ - public static distanceSquared(value1: Vector2, value2: Vector2) { - let v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return (v1 * v1) + (v2 * v2); + public static sqrDistance(value1: Vector2, value2: Vector2) { + return Math.pow(value1.x - value2.x, 2) + Math.pow(value1.y - value2.y, 2); } /** @@ -207,9 +146,8 @@ module es { * @param value2 * @returns 两个向量之间的距离 */ - public static distance(value1: Vector2, value2: Vector2): number { - let v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return Math.sqrt((v1 * v1) + (v2 * v2)); + public static distance(vec1: Vector2, vec2: Vector2): number { + return Math.sqrt(Math.pow(vec1.x - vec2.x, 2) + Math.pow(vec1.y - vec2.y, 2)); } /** @@ -218,9 +156,9 @@ module es { * @param to */ public static angle(from: Vector2, to: Vector2): number { - from = Vector2.normalize(from); - to = Vector2.normalize(to); - return Math.acos(MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * MathHelper.Rad2Deg; + from = from.normalize(); + to = to.normalize(); + return Math.acos(MathHelper.clamp(from.dot(to), -1, 1)) * MathHelper.Rad2Deg; } /** @@ -266,6 +204,10 @@ module es { this.y = y; } + public negate(): Vector2 { + return this.scale(-1); + } + /** * * @param value @@ -301,9 +243,7 @@ module es { * @param value */ public multiply(value: Vector2): Vector2 { - this.x *= value.x; - this.y *= value.y; - return this; + return new Vector2(value.x * this.x, value.y * this.y); } /** @@ -332,6 +272,10 @@ module es { return this; } + public dot(v: Vector2): number { + return this.x * v.x + this.y * v.y; + } + /** * * @param size @@ -341,10 +285,32 @@ module es { return new Vector2(this.x * size, this.y * size); } + public scaleEqual(size: number): Vector2 { + this.x *= size; + this.y *= size; + return this; + } + + public transform(matrix: Matrix2D): Vector2 { + return new Vector2( + this.x * matrix.m11 + this.y * matrix.m21 + matrix.m31, + this.x * matrix.m12 + this.y * matrix.m22 + matrix.m32 + ); + } + + public normalize(): Vector2 { + const d = this.distance(); + if (d > 0) { + return new Vector2(this.x / d, this.y / d); + } else { + return new Vector2(0, 1); + } + } + /** * 将这个Vector2变成一个方向相同的单位向量 */ - public normalize() { + public normalizeEqual(): Vector2 { const d = this.distance(); if (d > 0) { this.setTo(this.x / d, this.y / d); @@ -355,14 +321,9 @@ module es { } } - /** 返回它的长度 */ - public length() { - return Math.sqrt((this.x * this.x) + (this.y * this.y)); - } - public magnitude(): number { return this.distance(); - } + } public distance(v?: Vector2): number { if (!v) { @@ -393,8 +354,8 @@ module es { * @param right */ public angleBetween(left: Vector2, right: Vector2) { - let one = Vector2.subtract(left, this); - let two = Vector2.subtract(right, this); + let one = left.sub(this); + let two = right.sub(this); return Vector2Ext.angle(one, two); } @@ -403,12 +364,8 @@ module es { * @param other 要比较的对象 * @returns 如果实例相同true 否则false */ - public equals(other: Vector2 | object): boolean { - if (other instanceof Vector2) { - return other.x == this.x && other.y == this.y; - } - - return false; + public equals(other: Vector2, tolerance: number = 0.001): boolean { + return Math.abs(this.x - other.x) <= tolerance && Math.abs(this.y - other.y) <= tolerance; } public isValid(): boolean { @@ -452,10 +409,10 @@ module es { } public static unsignedAngle(from: Vector2, to: Vector2, round: boolean = true) { - from.normalize(); - to.normalize(); + from.normalizeEqual(); + to.normalizeEqual(); const angle = - Math.acos(MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * MathHelper.Rad2Deg; + Math.acos(MathHelper.clamp(from.dot(to), -1, 1)) * MathHelper.Rad2Deg; return round ? Math.round(angle) : angle; } diff --git a/source/src/Physics/ColliderTriggerHelper.ts b/source/src/Physics/ColliderTriggerHelper.ts index 572408a3..f095d904 100644 --- a/source/src/Physics/ColliderTriggerHelper.ts +++ b/source/src/Physics/ColliderTriggerHelper.ts @@ -19,13 +19,14 @@ module es { * 它将处理任何与Collider重叠的ITriggerListeners。 */ public update() { + const lateColliders = []; // 对所有实体.colliders进行重叠检查,这些实体.colliders是触发器,与所有宽相碰撞器,无论是否触发器。 // 任何重叠都会导致触发事件 let colliders = this._entity.getComponents(Collider); for (let i = 0; i < colliders.length; i++) { let collider = colliders[i]; - let neighbors = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); + let neighbors = Physics.boxcastBroadphaseExcludingSelf(collider.bounds, collider.collidesWithLayers); for (let j = 0; j < neighbors.length; j++) { let neighbor = neighbors[j]; // 我们至少需要一个碰撞器作为触发器 @@ -33,21 +34,28 @@ module es { continue; if (collider.overlaps(neighbor)) { - let pair = new Pair(collider, neighbor); + const pair = new Pair(collider, neighbor); // 如果我们的某一个集合中已经有了这个对子(前一个或当前的触发交叉点),就不要调用输入事件了 - let shouldReportTriggerEvent = !this._activeTriggerIntersections.contains(pair) && + const shouldReportTriggerEvent = !this._activeTriggerIntersections.contains(pair) && !this._previousTriggerIntersections.contains(pair); - if (shouldReportTriggerEvent) - this.notifyTriggerListeners(pair, true); + if (shouldReportTriggerEvent) { + if (neighbor.castSortOrder >= Collider.lateSortOrder) { + lateColliders.push(pair); + } else { + this.notifyTriggerListeners(pair, true); + } + } this._activeTriggerIntersections.add(pair); } } } - ListPool.free(colliders); + for (const pair of lateColliders) { + this.notifyTriggerListeners(pair, true); + } this.checkForExitedColliders(); } diff --git a/source/src/Physics/Collision.ts b/source/src/Physics/Collision.ts index 13d6de3a..405740ff 100644 --- a/source/src/Physics/Collision.ts +++ b/source/src/Physics/Collision.ts @@ -13,22 +13,24 @@ module es { export class Collisions { public static lineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean { - let b = Vector2.subtract(a2, a1); - let d = Vector2.subtract(b2, b1); - let bDotDPerp = b.x * d.y - b.y * d.x; + const b = a2.sub(a1); + const d = b2.sub(b1); + const bDotDPerp = b.x * d.y - b.y * d.x; // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 if (bDotDPerp == 0) return false; - let c = Vector2.subtract(b1, a1); - let t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) + const c = b1.sub(a1); + const t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) { return false; + } - let u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) + const u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) { return false; + } return true; } @@ -37,24 +39,24 @@ module es { intersection.x = 0; intersection.y = 0; - let b = Vector2.subtract(a2, a1); - let d = Vector2.subtract(b2, b1); - let bDotDPerp = b.x * d.y - b.y * d.x; + const b = a2.sub(a1); + const d = b2.sub(b1); + const bDotDPerp = b.x * d.y - b.y * d.x; // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 if (bDotDPerp == 0) return false; - let c = Vector2.subtract(b1, a1); - let t = (c.x * d.y - c.y * d.x) / bDotDPerp; + const c = b1.sub(a1); + const t = (c.x * d.y - c.y * d.x) / bDotDPerp; if (t < 0 || t > 1) return false; - let u = (c.x * b.y - c.y * b.x) / bDotDPerp; + const u = (c.x * b.y - c.y * b.x) / bDotDPerp; if (u < 0 || u > 1) return false; - let temp = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); + const temp = a1.add(b.scale(t)); intersection.x = temp.x; intersection.y = temp.y; @@ -62,24 +64,24 @@ module es { } public static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2) { - let v = Vector2.subtract(lineB, lineA); - let w = Vector2.subtract(closestTo, lineA); - let t = Vector2.dot(w, v) / Vector2.dot(v, v); + const v = lineB.sub(lineA); + const w = closestTo.sub(lineA); + let t = w.dot(v) / v.dot(v); t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); + return lineA.add(v.scale(t)); } public static circleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean { - return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); + return Vector2.sqrDistance(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); } public static circleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean { - return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; + return Vector2.sqrDistance(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; } public static circleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean { - return Vector2.distanceSquared(circleCenter, point) < radius * radius; + return Vector2.sqrDistance(circleCenter, point) < radius * radius; } public static rectToCircle(rect: Rectangle, cPosition: Vector2, cRadius: number): boolean { @@ -90,30 +92,30 @@ module es { // 对照相关边缘检查圆圈 let edgeFrom: Vector2; let edgeTo: Vector2; - let sector = this.getSector(rect.x, rect.y, rect.width, rect.height, cPosition); + const sector = this.getSector(rect.x, rect.y, rect.width, rect.height, cPosition); - if ((sector & PointSectors.top) != 0){ + if ((sector & PointSectors.top) !== 0) { edgeFrom = new Vector2(rect.x, rect.y); edgeTo = new Vector2(rect.x + rect.width, rect.y); if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo)) return true; } - if ((sector & PointSectors.bottom) != 0){ + if ((sector & PointSectors.bottom) !== 0) { edgeFrom = new Vector2(rect.x, rect.y + rect.width); edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo)) return true; } - if ((sector & PointSectors.left) != 0){ + if ((sector & PointSectors.left) !== 0) { edgeFrom = new Vector2(rect.x, rect.y); edgeTo = new Vector2(rect.x, rect.y + rect.height); if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo)) return true; } - if ((sector & PointSectors.right) != 0) { + if ((sector & PointSectors.right) !== 0) { edgeFrom = new Vector2(rect.x + rect.width, rect.y); edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo)) @@ -124,15 +126,15 @@ module es { } public static rectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2) { - let fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); - let toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); + const fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); + const toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); if (fromSector == PointSectors.center || toSector == PointSectors.center) { return true; } else if ((fromSector & toSector) != 0) { return false; } else { - let both = fromSector | toSector; + const both = fromSector | toSector; // 线对边进行检查 let edgeFrom: Vector2; let edgeTo: Vector2; diff --git a/source/src/Physics/Physics.ts b/source/src/Physics/Physics.ts index 9ac09cd0..20625cdc 100644 --- a/source/src/Physics/Physics.ts +++ b/source/src/Physics/Physics.ts @@ -150,23 +150,19 @@ module es { * @param end * @param layerMask */ - public static linecast(start: Vector2, end: Vector2, layerMask: number = Physics.allLayers): RaycastHit{ + public static linecast(start: Vector2, end: Vector2, layerMask: number = this.allLayers, ignoredColliders: Set = null): RaycastHit { this._hitArray[0].reset(); this.linecastAll(start, end, this._hitArray, layerMask); - return this._hitArray[0]; - } - - public static linecastIgnoreCollider(start: Vector2,end: Vector2,layerMask: number = this.allLayers,ignoredColliders: Set = null): RaycastHit { this._hitArray[0].reset(); - Physics.linecastAllIgnoreCollider( - start, - end, - this._hitArray, - layerMask, - ignoredColliders + Physics.linecastAll( + start, + end, + this._hitArray, + layerMask, + ignoredColliders ); return this._hitArray[0].clone(); - } + } /** * 通过空间散列强制执行一行,并用该行命中的任何碰撞器填充hits数组 @@ -175,24 +171,15 @@ module es { * @param hits * @param layerMask */ - public static linecastAll(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask: number = Physics.allLayers){ - if (hits.length == 0){ - console.warn("传入了一个空的hits数组。没有点击会被返回"); - return 0; - } - - return this._spatialHash.linecast(start, end, hits, layerMask); - } - - public static linecastAllIgnoreCollider(start: Vector2,end: Vector2,hits: RaycastHit[],layerMask: number = this.allLayers,ignoredColliders: Set = null): number { - return this._spatialHash.linecastIgnoreCollider( - start, - end, - hits, - layerMask, - ignoredColliders + public static linecastAll(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask: number = this.allLayers, ignoredColliders: Set = null) { + return this._spatialHash.linecast( + start, + end, + hits, + layerMask, + ignoredColliders ); - } + } /** * 检查是否有对撞机落在一个矩形区域中 @@ -212,7 +199,7 @@ module es { * @param layerMask */ public static overlapRectangleAll(rect: Rectangle, results: Collider[], layerMask: number = Physics.allLayers) { - if (results.length == 0){ + if (results.length == 0) { console.warn("传入了一个空的结果数组。不会返回任何结果"); return 0; } diff --git a/source/src/Physics/Ray2D.ts b/source/src/Physics/Ray2D.ts index 9a2043ce..bf522a1e 100644 --- a/source/src/Physics/Ray2D.ts +++ b/source/src/Physics/Ray2D.ts @@ -3,14 +3,26 @@ module es { * 不是真正的射线(射线只有开始和方向),作为一条线和射线。 */ export class Ray2D { - public start: Vector2; - public end: Vector2; - public direction: Vector2; + public get start(): Vector2 { + return this._start; + } + + public get direction(): Vector2 { + return this._direction; + } - constructor(position: Vector2, end: Vector2){ - this.start = position; - this.end = end; - this.direction = Vector2.subtract(this.end, this.start); + public get end(): Vector2 { + return this._end; } + + constructor(pos: Vector2, end: Vector2) { + this._start = pos.clone(); + this._end = end.clone(); + this._direction = this._end.sub(this._start); + } + + private _start: Vector2; + private _direction: Vector2; + private _end: Vector2; } } \ No newline at end of file diff --git a/source/src/Physics/RaycastHit.ts b/source/src/Physics/RaycastHit.ts index 25a45b34..95843e3e 100644 --- a/source/src/Physics/RaycastHit.ts +++ b/source/src/Physics/RaycastHit.ts @@ -38,22 +38,15 @@ module es { this.centroid = Vector2.zero; } - public setValues(collider: Collider, fraction: number, distance: number, point: Vector2) { + public setAllValues(collider: Collider, fraction: number, distance: number, point: Vector2, normal: Vector2) { this.collider = collider; this.fraction = fraction; this.distance = distance; this.point = point; - } - - public setValuesNonCollider(fraction: number, distance: number, point: Vector2, normal: Vector2) { - this.fraction = fraction; - this.distance = distance; - this.point = point; this.normal = normal; } - public setAllValues(collider: Collider, fraction: number, distance: number, point: Vector2, normal: Vector2) { - this.collider = collider; + public setValues(fraction: number, distance: number, point: Vector2, normal: Vector2) { this.fraction = fraction; this.distance = distance; this.point = point; diff --git a/source/src/Physics/Shapes/Circle.ts b/source/src/Physics/Shapes/Circle.ts index 77fe7e24..02c9b541 100644 --- a/source/src/Physics/Shapes/Circle.ts +++ b/source/src/Physics/Shapes/Circle.ts @@ -16,20 +16,20 @@ module es { if (collider.shouldColliderScaleAndRotateWithTransform) { // 我们只将直线缩放为一个圆,所以我们将使用最大值 - let scale = collider.entity.transform.scale; - let hasUnitScale = scale.x == 1 && scale.y == 1; - let maxScale = Math.max(scale.x, scale.y); + const scale = collider.entity.transform.scale; + const hasUnitScale = scale.x === 1 && scale.y === 1; + const maxScale = Math.max(scale.x, scale.y); this.radius = this._originalRadius * maxScale; - if (collider.entity.transform.rotation != 0) { + if (collider.entity.transform.rotation !== 0) { // 为了处理偏移原点的旋转,我们只需要将圆心围绕(0,0)在一个圆上移动,我们的偏移量就是0角 - let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - let offsetLength = hasUnitScale ? collider._localOffsetLength : Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + const offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; + const offsetLength = hasUnitScale ? collider._localOffsetLength : collider.localOffset.multiply(collider.entity.transform.scale).magnitude(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); } } - this.position = Vector2.add(collider.entity.transform.position, this.center); + this.position = collider.transform.position.add(this.center); this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); } @@ -67,12 +67,19 @@ module es { return ShapeCollisionsLine.lineToCircle(start, end, this, hit); } + public getPointAlongEdge(angle: number): Vector2 { + return new Vector2( + this.position.x + this.radius * Math.cos(angle), + this.position.y + this.radius * Math.sin(angle) + ); + } + /** * 获取所提供的点是否在此范围内 * @param point */ public containsPoint(point: Vector2) { - return (Vector2.subtract(point, this.position)).lengthSquared() <= this.radius * this.radius; + return (point.sub(this.position)).lengthSquared() <= this.radius * this.radius; } public pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean { diff --git a/source/src/Physics/Shapes/CollisionResult.ts b/source/src/Physics/Shapes/CollisionResult.ts index d4eafa05..5b43fb79 100644 --- a/source/src/Physics/Shapes/CollisionResult.ts +++ b/source/src/Physics/Shapes/CollisionResult.ts @@ -17,15 +17,39 @@ module es { */ public point: Vector2 = Vector2.zero; + public reset() { + this.collider = null; + this.normal.setTo(0, 0); + this.minimumTranslationVector.setTo(0, 0); + if (this.point) { + this.point.setTo(0, 0); + } + } + + public cloneTo(cr: CollisionResult) { + cr.collider = this.collider; + cr.normal.setTo(this.normal.x, this.normal.y); + cr.minimumTranslationVector.setTo( + this.minimumTranslationVector.x, + this.minimumTranslationVector.y + ); + if (this.point) { + if (!cr.point) { + cr.point = new Vector2(0, 0); + } + cr.point.setTo(this.point.x, this.point.y); + } + } + /** * 改变最小平移向量,如果没有相同方向上的运动,它将移除平移的x分量。 * @param deltaMovement */ - public removeHorizontal(deltaMovement: Vector2){ + public removeHorizontalTranslation(deltaMovement: Vector2){ // 检查是否需要横向移动,如果需要,移除并固定响应 - if (Math.sign(this.normal.x) != Math.sign(deltaMovement.x) || (deltaMovement.x == 0 && this.normal.x != 0)){ - let responseDistance = this.minimumTranslationVector.length(); - let fix = responseDistance / this.normal.y; + if (Math.sign(this.normal.x) !== Math.sign(deltaMovement.x) || (deltaMovement.x === 0 && this.normal.x !== 0)){ + const responseDistance = this.minimumTranslationVector.magnitude(); + const fix = responseDistance / this.normal.y; // 检查一些边界情况。因为我们除以法线 使得x == 1和一个非常小的y这将导致一个巨大的固定值 if (Math.abs(this.normal.x) != 1 && Math.abs(fix) < Math.abs(deltaMovement.y * 3)){ @@ -35,9 +59,8 @@ module es { } public invertResult() { - this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector); - this.normal = Vector2.negate(this.normal); - return this; + this.minimumTranslationVector = this.minimumTranslationVector.negate(); + this.normal = this.normal.negate(); } public toString(){ diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index 4759e3c5..57a21144 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -114,9 +114,9 @@ module es { * @param points */ public static recenterPolygonVerts(points: Vector2[]) { - let center = this.findPolygonCenter(points); + const center = this.findPolygonCenter(points); for (let i = 0; i < points.length; i++) - points[i] = Vector2.subtract(points[i], center); + points[i] = points[i].sub(center); } /** @@ -139,13 +139,13 @@ module es { * @param points * @param direction */ - public static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2{ + public static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2 { let index = 0; - let maxDot = Vector2.dot(points[index], direction); + let maxDot = points[index].dot(direction); - for (let i = 1; i < points.length; i ++){ - let dot = Vector2.dot(points[i], direction); - if (dot > maxDot){ + for (let i = 1; i < points.length; i++) { + let dot = points[i].dot(direction); + if (dot > maxDot) { maxDot = dot; index = i; } @@ -163,35 +163,35 @@ module es { * @param distanceSquared * @param edgeNormal */ - public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Ref, edgeNormal: Vector2): Vector2 { - distanceSquared.value = Number.MAX_VALUE; - edgeNormal.x = 0; - edgeNormal.y = 0; - let closestPoint = Vector2.zero; + public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { distanceSquared: number; edgeNormal: Vector2; closestPoint: Vector2 } { + const res = { + distanceSquared: Number.MAX_VALUE, + edgeNormal: Vector2.zero, + closestPoint: Vector2.zero, + }; let tempDistanceSquared = 0; for (let i = 0; i < points.length; i++) { let j = i + 1; - if (j == points.length) + if (j === points.length) j = 0; - let closest = ShapeCollisionsCircle.closestPointOnLine(points[i], points[j], point); - tempDistanceSquared = Vector2.distanceSquared(point, closest); + const closest = ShapeCollisionsCircle.closestPointOnLine(points[i], points[j], point); + tempDistanceSquared = Vector2.sqrDistance(point, closest); - if (tempDistanceSquared < distanceSquared.value) { - distanceSquared.value = tempDistanceSquared; - closestPoint = closest; + if (tempDistanceSquared < res.distanceSquared) { + res.distanceSquared = tempDistanceSquared; + res.closestPoint = closest; // 求直线的法线 - let line = Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; + const line = points[j].sub(points[i]); + res.edgeNormal.x = line.y; + res.edgeNormal.y = -line.x; } } - Vector2Ext.normalize(edgeNormal); - - return closestPoint; + res.edgeNormal = res.edgeNormal.normalize(); + return res; } /** @@ -200,11 +200,11 @@ module es { * @param originalPoints * @param rotatedPoints */ - public static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: Vector2[]){ + public static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: Vector2[]) { let cos = Math.cos(radians); let sin = Math.sin(radians); - for (let i = 0; i < originalPoints.length; i ++){ + for (let i = 0; i < originalPoints.length; i++) { let position = originalPoints[i]; rotatedPoints[i] = new Vector2(position.x * cos + position.y * -sin, position.x * sin + position.y * cos); } @@ -212,40 +212,63 @@ module es { public recalculateBounds(collider: Collider) { // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始 - this.center = collider.localOffset.clone(); + this.center = collider.localOffset; if (collider.shouldColliderScaleAndRotateWithTransform) { let hasUnitScale = true; - let tempMat: Matrix2D; - let combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); + const tempMat: Matrix2D = new Matrix2D(); + const combinedMatrix: Matrix2D = new Matrix2D(); + Matrix2D.createTranslation( + this._polygonCenter.x * -1, + this._polygonCenter.y * -1, + combinedMatrix + ); if (!collider.entity.transform.scale.equals(Vector2.one)) { - tempMat = Matrix2D.createScale(collider.entity.transform.scale.x, collider.entity.transform.scale.y); - combinedMatrix = combinedMatrix.multiply(tempMat); + Matrix2D.createScale( + collider.entity.scale.x, + collider.entity.scale.y, + tempMat + ); + Matrix2D.multiply(combinedMatrix, tempMat, combinedMatrix); hasUnitScale = false; // 缩放偏移量并将其设置为中心。如果我们有旋转,它会在下面重置 - this.center = Vector2.multiply(collider.localOffset, collider.entity.transform.scale); + const scaledOffset = new Vector2( + collider.localOffset.x * collider.entity.scale.x, + collider.localOffset.y * collider.entity.scale.y + ); + this.center = scaledOffset; } if (collider.entity.transform.rotation != 0) { - tempMat = Matrix2D.createRotation(collider.entity.transform.rotation); - combinedMatrix = combinedMatrix.multiply(tempMat); + Matrix2D.createRotation( + MathHelper.Deg2Rad * collider.entity.rotation, + tempMat + ); + Matrix2D.multiply(combinedMatrix, tempMat, combinedMatrix); // 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动 // 我们的偏移使角度为0我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。 - let offsetAngle = Math.atan2(collider.localOffset.y * collider.entity.transform.scale.y, collider.localOffset.x * collider.entity.transform.scale.x) * MathHelper.Rad2Deg; - let offsetLength = hasUnitScale ? collider._localOffsetLength : - Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); + const offsetAngle = Math.atan2(collider.localOffset.y * collider.entity.transform.scale.y, collider.localOffset.x * collider.entity.transform.scale.x) * MathHelper.Rad2Deg; + const offsetLength = hasUnitScale ? collider._localOffsetLength : + collider.localOffset.multiply(collider.entity.transform.scale).magnitude(); this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); } - tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); - combinedMatrix = combinedMatrix.multiply(tempMat); + Matrix2D.createTranslation( + this._polygonCenter.x, + this._polygonCenter.y, + tempMat + ); + Matrix2D.multiply(combinedMatrix, tempMat, combinedMatrix); // 最后变换原始点 - Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); + this.points = []; + this._originalPoints.forEach(p => { + this.points.push(p.transform(combinedMatrix)); + }); this.isUnrotated = collider.entity.transform.rotation == 0; @@ -254,9 +277,9 @@ module es { this._areEdgeNormalsDirty = true; } - this.position = Vector2.add(collider.entity.transform.position, this.center); + this.position = collider.transform.position.add(this.center); this.bounds = Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = Vector2.add(this.bounds.location, this.position); + this.bounds.location = this.bounds.location.add(this.position); } public overlaps(other: Shape) { @@ -304,11 +327,11 @@ module es { */ public containsPoint(point: Vector2) { // 将点归一化到多边形坐标空间中 - point.sub(this.position); + point = point.sub(this.position); let isInside = false; for (let i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { - if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && + if (((this.points[i].y > point.y) !== (this.points[j].y > point.y)) && (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + this.points[i].x)) { isInside = !isInside; diff --git a/source/src/Physics/Shapes/RealtimeCollisions.ts b/source/src/Physics/Shapes/RealtimeCollisions.ts index 22cc1480..4f89ae3a 100644 --- a/source/src/Physics/Shapes/RealtimeCollisions.ts +++ b/source/src/Physics/Shapes/RealtimeCollisions.ts @@ -1,20 +1,21 @@ module es { export class RealtimeCollisions { - public static intersectMovingCircleBox(s: Circle, b: Box, movement: Vector2, time: Ref): boolean { + public static intersectMovingCircleBox(s: Circle, b: Box, movement: Vector2, time: number): boolean { // 计算将b按球面半径r扩大后的AABB - let e = b.bounds.clone(); + const e = b.bounds; e.inflate(s.radius, s.radius); // 将射线与展开的矩形e相交,如果射线错过了e,则以无交点退出,否则得到交点p和时间t作为结果。 - let ray = new Ray2D(Vector2.subtract(s.position, movement), s.position); - if (!e.rayIntersects(ray, time) && time.value > 1) + const ray = new Ray2D(s.position.sub(movement), s.position); + const res = e.rayIntersects(ray); + if (!res.intersected && res.distance > 1) return false; // 求交点 - let point = Vector2.add(ray.start, Vector2.multiplyScaler(ray.direction, time.value)); + const point = ray.start.add(ray.direction.scale(time)); // 计算交点p位于b的哪个最小面和最大面之外。注意,u和v不能有相同的位集,它们之间必须至少有一个位集。 - let u, v = 0; + let u: number, v: number = 0; if (point.x < b.bounds.left) u |= 1; if (point.x > b.bounds.right) @@ -25,7 +26,7 @@ module es { v |= 2; // 'or'将所有的比特集合在一起,形成一个比特掩码(注意u + v == u | v) - let m = u + v; + const m = u + v; // 如果这3个比特都被设置,那么该点就在顶点区域内。 if (m == 3){ @@ -66,8 +67,8 @@ module es { point = box.bounds.getClosestPointOnRectangleToPoint(cirlce.position); // 圆和方块相交,如果圆心到点的距离小于圆的半径,则圆和方块相交 - let v = Vector2.subtract(point, cirlce.position); - let dist = Vector2.dot(v, v); + const v = point.sub(cirlce.position); + const dist = v.dot(v); return dist <= cirlce.radius * cirlce.radius; } diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsBox.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsBox.ts index 89c4369b..fdb43604 100644 --- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsBox.ts +++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsBox.ts @@ -1,7 +1,7 @@ module es { export class ShapeCollisionsBox { public static boxToBox(first: Box, second: Box, result: CollisionResult): boolean { - let minkowskiDiff = this.minkowskiDifference(first, second); + const minkowskiDiff = this.minkowskiDifference(first, second); if (minkowskiDiff.contains(0, 0)) { // 计算MTV。如果它是零,我们就可以称它为非碰撞 result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); @@ -9,8 +9,8 @@ module es { if (result.minimumTranslationVector.equals(Vector2.zero)) return false; - result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); - result.normal.normalize(); + result.normal = result.minimumTranslationVector.scale(-1); + result.normal = result.normal.normalize(); return true; } @@ -27,29 +27,29 @@ module es { */ public static boxToBoxCast(first: Box, second: Box, movement: Vector2, hit: RaycastHit): boolean { // 首先,我们检查是否有重叠。如果有重叠,我们就不做扫描测试 - let minkowskiDiff = this.minkowskiDifference(first, second); + const minkowskiDiff = this.minkowskiDifference(first, second); if (minkowskiDiff.contains(0, 0)) { // 计算MTV。如果它是零,我们就可以称它为非碰撞 - let mtv = minkowskiDiff.getClosestPointOnBoundsToOrigin(); + const mtv = minkowskiDiff.getClosestPointOnBoundsToOrigin(); if (mtv.equals(Vector2.zero)) return false; hit.normal = new Vector2(-mtv.x, -mtv.y); - hit.normal.normalize(); + hit.normal = hit.normal.normalize(); hit.distance = 0; hit.fraction = 0; return true; } else { // 射线投射移动矢量 - let ray = new Ray2D(Vector2.zero, new Vector2(-movement.x, -movement.y)); - let fraction = new Ref(0); - if (minkowskiDiff.rayIntersects(ray, fraction) && fraction.value <= 1) { - hit.fraction = fraction.value; - hit.distance = movement.length() * fraction.value; - hit.normal = new Vector2(-movement.x, -movement.y); - hit.normal.normalize(); - hit.centroid = Vector2.add(first.bounds.center, Vector2.multiplyScaler(movement, fraction.value)); + const ray = new Ray2D(Vector2.zero, movement.scale(-1)); + const res = minkowskiDiff.rayIntersects(ray); + if (res.intersected && res.distance <= 1) { + hit.fraction = res.distance; + hit.distance = movement.magnitude() * res.distance; + hit.normal = movement.scale(-1); + hit.normal = hit.normal.normalize(); + hit.centroid = first.bounds.center.add(movement.scale(res.distance)); return true; } @@ -61,9 +61,9 @@ module es { private static minkowskiDifference(first: Box, second: Box): Rectangle { // 我们需要第一个框的左上角 // 碰撞器只会修改运动的位置所以我们需要用位置来计算出运动是什么。 - let positionOffset = Vector2.subtract(first.position, Vector2.add(first.bounds.location, new Vector2(first.bounds.size.x / 2, first.bounds.size.y / 2))); - let topLeft = Vector2.subtract(Vector2.add(first.bounds.location, positionOffset), second.bounds.max); - let fullSize = Vector2.add(first.bounds.size, second.bounds.size); + const positionOffset = first.position.sub(first.bounds.center); + const topLeft = first.bounds.location.add(positionOffset.sub(second.bounds.max)); + const fullSize = first.bounds.size.add(second.bounds.size); return new Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y) } diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsCircle.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsCircle.ts index 93b1636f..4e85e5e5 100644 --- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsCircle.ts +++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsCircle.ts @@ -1,19 +1,46 @@ module es { export class ShapeCollisionsCircle { + public static circleToCircleCast(first: Circle,second: Circle,deltaMovement: Vector2,hit: RaycastHit): boolean { + let endPointOfCast = first.position.add(deltaMovement); + let d = this.closestPointOnLine(first.position,endPointOfCast,second.position); + + let closestDistanceSquared = Vector2.sqrDistance(second.position, d); + const sumOfRadiiSquared = (first.radius + second.radius) * (first.radius + second.radius); + if (closestDistanceSquared <= sumOfRadiiSquared) { + const normalizedDeltaMovement = deltaMovement.normalize(); + if (d === endPointOfCast) { + endPointOfCast = first.position.add( + deltaMovement.add(normalizedDeltaMovement.scale(second.radius)) + ); + d = this.closestPointOnLine( + first.position, + endPointOfCast, + second.position + ); + closestDistanceSquared = Vector2.sqrDistance(second.position, d); + } + + const backDist = Math.sqrt(sumOfRadiiSquared - closestDistanceSquared); + hit.centroid = d.sub(normalizedDeltaMovement.scale(backDist)); + hit.normal = hit.centroid.sub(second.position).normalize(); + hit.fraction = (hit.centroid.x - first.position.x) / deltaMovement.x; + hit.distance = Vector2.distance(first.position, hit.centroid); + hit.point = second.position.add(hit.normal.scale(second.radius)); + return true; + } + + return false; + } + public static circleToCircle(first: Circle, second: Circle, result: CollisionResult = new CollisionResult()): boolean { - let distanceSquared = Vector2.distanceSquared(first.position, second.position); - let sumOfRadii = first.radius + second.radius; - let collided = distanceSquared < sumOfRadii * sumOfRadii; + const distanceSquared = Vector2.sqrDistance(first.position, second.position); + const sumOfRadii = first.radius + second.radius; + const collided = distanceSquared < sumOfRadii * sumOfRadii; if (collided) { - result.normal = Vector2.normalize(Vector2.subtract(first.position, second.position)); - let depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiplyScaler(result.normal, -depth); - result.point = Vector2.add(second.position, Vector2.multiplyScaler(result.normal, second.radius)); - - // 这可以得到实际的碰撞点,可能有用也可能没用,所以我们暂时把它留在这里 - // let collisionPointX = ((first.position.x * second.radius) + (second.position.x * first.radius)) / sumOfRadii; - // let collisionPointY = ((first.position.y * second.radius) + (second.position.y * first.radius)) / sumOfRadii; - // result.point = new Vector2(collisionPointX, collisionPointY); + result.normal = first.position.sub(second.position).normalize(); + const depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = result.normal.scale(-depth); + result.point = second.position.add(result.normal.scale(second.radius)); return true; } @@ -28,31 +55,31 @@ module es { * @param result */ public static circleToBox(circle: Circle, box: Box, result: CollisionResult = new CollisionResult()): boolean { - let closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); + const closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); // 先处理中心在盒子里的圆,如果我们是包含的, 它的成本更低, if (box.containsPoint(circle.position)) { - result.point = closestPointOnBounds.clone(); + result.point = closestPointOnBounds; // 计算MTV。找出安全的、非碰撞的位置,并从中得到MTV - let safePlace = Vector2.add(closestPointOnBounds, Vector2.multiplyScaler(result.normal, circle.radius)); - result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); + const safePlace = closestPointOnBounds.add(result.normal.scale(circle.radius)); + result.minimumTranslationVector = circle.position.sub(safePlace); return true; } - let sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); + const sqrDistance = Vector2.sqrDistance(closestPointOnBounds, circle.position); // 看框上的点距圆的半径是否小于圆的半径 if (sqrDistance == 0) { - result.minimumTranslationVector = Vector2.multiplyScaler(result.normal, circle.radius); + result.minimumTranslationVector = result.normal.scale(circle.radius); } else if (sqrDistance <= circle.radius * circle.radius) { - result.normal = Vector2.subtract(circle.position, closestPointOnBounds); - let depth = result.normal.length() - circle.radius; + result.normal = circle.position.sub(closestPointOnBounds); + const depth = result.normal.magnitude() - circle.radius; result.point = closestPointOnBounds; - Vector2Ext.normalize(result.normal); - result.minimumTranslationVector = Vector2.multiplyScaler(result.normal, depth); + result.normal = result.normal.normalize(); + result.minimumTranslationVector = result.normal.scale(depth); return true; } @@ -62,47 +89,47 @@ module es { public static circleToPolygon(circle: Circle, polygon: Polygon, result: CollisionResult = new CollisionResult()): boolean { // 圆圈在多边形中的位置坐标 - let poly2Circle = Vector2.subtract(circle.position, polygon.position); + const poly2Circle = circle.position.sub(polygon.position); // 首先,我们需要找到从圆到多边形的最近距离 - let distanceSquared = new Ref(0); - let closestPoint = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle, distanceSquared, result.normal); + const res = Polygon.getClosestPointOnPolygonToPoint(polygon.points,poly2Circle); + result.normal = res.edgeNormal; // 确保距离的平方小于半径的平方,否则我们不会相撞。 // 请注意,如果圆完全包含在多边形中,距离可能大于半径。 // 正因为如此,我们还要确保圆的位置不在多边形内。 - let circleCenterInsidePoly = polygon.containsPoint(circle.position); - if (distanceSquared.value > circle.radius * circle.radius && !circleCenterInsidePoly) + const circleCenterInsidePoly = polygon.containsPoint(circle.position); + if (res.distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) return false; // 算出MTV。我们要注意处理完全包含在多边形中的圆或包含其中心的圆 let mtv: Vector2; if (circleCenterInsidePoly) { - mtv = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared.value) - circle.radius)); + mtv = result.normal.scale(Math.sqrt(res.distanceSquared) - circle.radius); } else { // 如果我们没有距离,这意味着圆心在多边形的边缘上。只需根据它的半径移动它 - if (distanceSquared.value == 0) { - mtv = new Vector2(result.normal.x * circle.radius, result.normal.y * circle.radius); + if (res.distanceSquared === 0) { + mtv = result.normal.scale(circle.radius); } else { - let distance = Math.sqrt(distanceSquared.value); - mtv = Vector2.multiplyScaler(Vector2.subtract(poly2Circle, closestPoint), -1) - .multiply(new Vector2((circle.radius - distance) / distance)); + const distance = Math.sqrt(res.distanceSquared); + mtv = poly2Circle + .sub(res.closestPoint) + .scale(((circle.radius - distance) / distance) * -1); } } result.minimumTranslationVector = mtv; - result.point = Vector2.add(closestPoint, polygon.position); + result.point = res.closestPoint.add(polygon.position); return true; } public static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2 { - let v = Vector2.subtract(lineB, lineA); - let w = Vector2.subtract(closestTo, lineA); - let t = Vector2.dot(w, v) / Vector2.dot(v, v); + const v = lineB.sub(lineA); + const w = closestTo.sub(lineA); + let t = w.dot(v) / v.dot(v); t = MathHelper.clamp(t, 0, 1); - - return Vector2.add(lineA, Vector2.multiplyScaler(v, t)); + return lineA.add(v.scaleEqual(t)); } } } \ No newline at end of file diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsLine.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsLine.ts index 0303d0f7..b758f44d 100644 --- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsLine.ts +++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsLine.ts @@ -7,10 +7,10 @@ module es { let hasIntersection = false; for (let j = polygon.points.length - 1, i = 0; i < polygon.points.length; j = i, i ++){ - let edge1 = Vector2.add(polygon.position, polygon.points[j]); - let edge2 = Vector2.add(polygon.position, polygon.points[i]); - let intersection: Vector2 = Vector2.zero; - if (this.lineToLine(edge1, edge2, start, end, intersection)){ + const edge1 = Vector2.add(polygon.position, polygon.points[j]); + const edge2 = Vector2.add(polygon.position, polygon.points[i]); + const intersection: Vector2 = Vector2.zero; + if (ShapeCollisionsLine.lineToLine(edge1, edge2, start, end, intersection)){ hasIntersection = true; // TODO: 这是得到分数的正确和最有效的方法吗? @@ -20,7 +20,7 @@ module es { distanceFraction = (intersection.y - start.y) / (end.y - start.y); if (distanceFraction < fraction){ - let edge = Vector2.subtract(edge2, edge1); + const edge = edge2.sub(edge1); normal = new Vector2(edge.y, -edge.x); fraction = distanceFraction; intersectionPoint = intersection; @@ -29,9 +29,9 @@ module es { } if (hasIntersection){ - normal.normalize(); - let distance = Vector2.distance(start, intersectionPoint); - hit.setValuesNonCollider(fraction, distance, intersectionPoint, normal); + normal = normal.normalize(); + const distance = Vector2.distance(start, intersectionPoint); + hit.setValues(fraction, distance, intersectionPoint, normal); return true; } @@ -39,24 +39,24 @@ module es { } public static lineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2, intersection: Vector2){ - let b = Vector2.subtract(a2, a1); - let d = Vector2.subtract(b2, b1); - let bDotDPerp = b.x * d.y - b.y * d.x; + const b = a2.sub(a1); + const d = b2.sub(b1); + const bDotDPerp = b.x * d.y - b.y * d.x; // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 if (bDotDPerp == 0) return false; - let c = Vector2.subtract(b1, a1); - let t = (c.x * d.y - c.y * d.x) / bDotDPerp; + const c = b1.sub(a1); + const t = (c.x * d.y - c.y * d.x) / bDotDPerp; if (t < 0 || t > 1) return false; - let u = (c.x * b.y - c.y * b.x) / bDotDPerp; + const u = (c.x * b.y - c.y * b.x) / bDotDPerp; if (u < 0 || u > 1) return false; - let r = Vector2.add(a1, Vector2.multiplyScaler(b, t)); + const r = a1.add(b.scale(t)); intersection.x = r.x; intersection.y = r.y; @@ -65,11 +65,11 @@ module es { public static lineToCircle(start: Vector2, end: Vector2, s: Circle, hit: RaycastHit): boolean{ // 计算这里的长度并分别对d进行标准化,因为如果我们命中了我们需要它来得到分数 - let lineLength = Vector2.distance(start, end); - let d = Vector2.divideScaler(Vector2.subtract(end, start), lineLength); - let m = Vector2.subtract(start, s.position); - let b = Vector2.dot(m, d); - let c = Vector2.dot(m, m) - s.radius * s.radius; + const lineLength = Vector2.distance(start, end); + const d = Vector2.divideScaler(end.sub(start), lineLength); + const m = start.sub(s.position); + const b = m.dot(d); + const c = m.dot(m) - s.radius * s.radius; // 如果r的原点在s之外,(c>0)和r指向s (b>0) 则返回 if (c > 0 && b > 0) @@ -87,9 +87,9 @@ module es { if (hit.fraction < 0) hit.fraction = 0; - hit.point = Vector2.add(start, Vector2.multiplyScaler(d, hit.fraction)); + hit.point = start.add(d.scale(hit.fraction)); hit.distance = Vector2.distance(start, hit.point); - hit.normal = Vector2.normalize(Vector2.subtract(hit.point, s.position)); + hit.normal = hit.point.sub(s.position).normalize(); hit.fraction = hit.distance / lineLength; return true; diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsPoint.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsPoint.ts index 96ec3902..a2270497 100644 --- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsPoint.ts +++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsPoint.ts @@ -1,14 +1,14 @@ module es { export class ShapeCollisionsPoint { public static pointToCircle(point: Vector2, circle: Circle, result: CollisionResult): boolean { - let distanceSquared = Vector2.distanceSquared(point, circle.position); + let distanceSquared = Vector2.sqrDistance(point, circle.position); let sumOfRadii = 1 + circle.radius; let collided = distanceSquared < sumOfRadii * sumOfRadii; if (collided) { - result.normal = Vector2.normalize(Vector2.subtract(point, circle.position)); + result.normal = point.sub(circle.position).normalize(); let depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiplyScaler(result.normal, -depth); - result.point = Vector2.add(circle.position, Vector2.multiplyScaler(result.normal, circle.radius)); + result.minimumTranslationVector = result.normal.scale(-depth);; + result.point = circle.position.add(result.normal.scale(circle.radius)); return true; } @@ -16,11 +16,11 @@ module es { return false; } - public static pointToBox(point: Vector2, box: Box, result: CollisionResult = new CollisionResult()){ - if (box.containsPoint(point)){ + public static pointToBox(point: Vector2, box: Box, result: CollisionResult = new CollisionResult()) { + if (box.containsPoint(point)) { // 在方框的空间里找到点 result.point = box.bounds.getClosestPointOnRectangleBorderToPoint(point, result.normal); - result.minimumTranslationVector = Vector2.subtract(point, result.point); + result.minimumTranslationVector = point.sub(result.point); return true; } @@ -30,12 +30,15 @@ module es { public static pointToPoly(point: Vector2, poly: Polygon, result: CollisionResult = new CollisionResult()): boolean { if (poly.containsPoint(point)) { - let distanceSquared = new Ref(0); - let closestPoint = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position), distanceSquared, result.normal); - - result.minimumTranslationVector = new Vector2(result.normal.x * Math.sqrt(distanceSquared.value), result.normal.y * Math.sqrt(distanceSquared.value)); - result.point = Vector2.add(closestPoint, poly.position); - + const res = Polygon.getClosestPointOnPolygonToPoint( + poly.points, + point.sub(poly.position) + ); + result.normal = res.edgeNormal; + result.minimumTranslationVector = result.normal.scale( + Math.sqrt(res.distanceSquared) + ); + result.point = res.closestPoint.sub(poly.position); return true; } diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsPolygon.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsPolygon.ts index 23aafd7e..d20c2b4d 100644 --- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsPolygon.ts +++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisionsPolygon.ts @@ -12,8 +12,8 @@ module es { const firstEdges = first.edgeNormals; const secondEdges = second.edgeNormals; let minIntervalDistance = Number.POSITIVE_INFINITY; - let translationAxis = es.Vector2.zero; - let polygonOffset = Vector2.subtract(first.position, second.position); + let translationAxis = Vector2.zero; + let polygonOffset = first.position.sub(second.position); let axis: Vector2; // 循环穿过两个多边形的所有边 @@ -28,7 +28,7 @@ module es { const {min: minB, max: maxB} = this.getInterval(axis, second); // 将区间设为第二个多边形的空间。由轴上投影的位置差偏移。 - let relativeIntervalOffset = Vector2.dot(polygonOffset, axis); + const relativeIntervalOffset = polygonOffset.dot(axis); minA += relativeIntervalOffset; maxA += relativeIntervalOffset; @@ -50,14 +50,14 @@ module es { minIntervalDistance = intervalDist; translationAxis.setTo(axis.x, axis.y); - if (Vector2.dot(translationAxis, polygonOffset) < 0) + if (translationAxis.dot(polygonOffset) < 0) translationAxis = translationAxis.scale(-1); } } // 利用最小平移向量对多边形进行推入。 result.normal = translationAxis; - result.minimumTranslationVector = translationAxis.scale(minIntervalDistance * -1); + result.minimumTranslationVector = translationAxis.scale(-minIntervalDistance); return true; } @@ -72,11 +72,11 @@ module es { public static getInterval(axis: Vector2, polygon: Polygon): {min: number, max: number} { const res = {min: 0, max: 0}; let dot: number; - dot = Vector2.dot( polygon.points[0], axis); + dot = polygon.points[0].dot(axis); res.max = dot; res.min = dot; for (let i = 1; i < polygon.points.length; i++) { - dot = Vector2.dot(polygon.points[i], axis); + dot = polygon.points[i].dot(axis); if (dot < res.min) { res.min = dot; } else if (dot > res.max) { diff --git a/source/src/Physics/SpatialHash.ts b/source/src/Physics/SpatialHash.ts index 1f9f08b9..ad57f63b 100644 --- a/source/src/Physics/SpatialHash.ts +++ b/source/src/Physics/SpatialHash.ts @@ -118,12 +118,12 @@ module es { public aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[] { this._tempHashSet.clear(); - let p1 = this.cellCoords(bounds.x, bounds.y); - let p2 = this.cellCoords(bounds.right, bounds.bottom); + const p1 = this.cellCoords(bounds.x, bounds.y); + const p2 = this.cellCoords(bounds.right, bounds.bottom); for (let x = p1.x; x <= p2.x; x++) { for (let y = p1.y; y <= p2.y; y++) { - let cell = this.cellAtPosition(x, y); + const cell = this.cellAtPosition(x, y); if (!cell) continue; @@ -154,9 +154,9 @@ module es { * @param hits * @param layerMask */ - public linecast(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask: number) { + public linecast(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask: number, ignoredColliders: Set) { let ray = new Ray2D(start, end); - this._raycastParser.start(ray, hits, layerMask); + this._raycastParser.start(ray, hits, layerMask, ignoredColliders); // 获取我们的起始/结束位置,与我们的网格在同一空间内 let currentCell = this.cellCoords(start.x, start.y); @@ -217,67 +217,6 @@ module es { return this._raycastParser.hitCounter; } - public linecastIgnoreCollider(start: Vector2, end: Vector2, hits: RaycastHit[], layerMask: number, ignoredColliders: Set): number { - start = start.clone(); - const ray = new Ray2D(start, end); - this._raycastParser.startIgnoreCollider(ray, hits, layerMask, ignoredColliders); - start.x = start.x * this._inverseCellSize; - start.y = start.y * this._inverseCellSize; - const endCell = this.cellCoords(end.x, end.y); - let intX = Math.floor(start.x); - let intY = Math.floor(start.y); - let stepX = Math.sign(ray.direction.x); - let stepY = Math.sign(ray.direction.y); - if (intX === endCell.x) { - stepX = 0; - } - - if (intY === endCell.y) { - stepY = 0; - } - - const boundaryX = intX + (stepX > 0 ? 1 : 0); - const boundaryY = intY + (stepY > 0 ? 1 : 0); - - let tMaxX = (boundaryX - start.x) / ray.direction.x; - let tMaxY = (boundaryY - start.y) / ray.direction.y; - if (ray.direction.x === 0 || stepX === 0) { - tMaxX = Number.POSITIVE_INFINITY; - } - if (ray.direction.y === 0 || stepY === 0) { - tMaxY = Number.POSITIVE_INFINITY; - } - - const tDeltaX = stepX / ray.direction.x; - const tDeltaY = stepY / ray.direction.y; - let cell = this.cellAtPosition(intX, intY); - if (cell && this._raycastParser.checkRayIntersection(intX, intY, cell)) { - this._raycastParser.reset(); - return this._raycastParser.hitCounter; - } - - let n = 0; - while ((intX !== endCell.x || intY !== endCell.y) && n < 100) { - if (tMaxX < tMaxY) { - intX = intX + stepX; - tMaxX = tMaxX + tDeltaX; - } else { - intY = intY + stepY; - tMaxY = tMaxY + tDeltaY; - } - - cell = this.cellAtPosition(intX, intY); - if (cell && this._raycastParser.checkRayIntersection(intX, intY, cell)) { - this._raycastParser.reset(); - return this._raycastParser.hitCounter; - } - n++; - } - - this._raycastParser.reset(); - return this._raycastParser.hitCounter; - } - /** * 获取所有在指定矩形范围内的碰撞器 @@ -425,7 +364,11 @@ module es { export class RaycastResultParser { public hitCounter: number; public static compareRaycastHits = (a: RaycastHit, b: RaycastHit) => { - return a.distance - b.distance; + if (a.distance !== b.distance) { + return a.distance - b.distance; + } else { + return a.collider.castSortOrder - b.collider.castSortOrder; + } }; public _hits: RaycastHit[]; @@ -436,14 +379,7 @@ module es { public _layerMask: number; private _ignoredColliders: Set; - public start(ray: Ray2D, hits: RaycastHit[], layerMask: number) { - this._ray = ray; - this._hits = hits; - this._layerMask = layerMask; - this.hitCounter = 0; - } - - public startIgnoreCollider(ray: Ray2D, hits: RaycastHit[], layerMask: number, ignoredColliders: Set) { + public start(ray: Ray2D, hits: RaycastHit[], layerMask: number, ignoredColliders: Set) { this._ray = ray; this._hits = hits; this._layerMask = layerMask; @@ -458,9 +394,8 @@ module es { * @param cell */ public checkRayIntersection(cellX: number, cellY: number, cell: Collider[]): boolean { - let fraction: Ref = new Ref(0); for (let i = 0; i < cell.length; i++) { - let potential = cell[i]; + const potential = cell[i]; // 管理我们已经处理过的碰撞器 if (new es.List(this._checkedColliders).contains(potential)) @@ -475,11 +410,16 @@ module es { if (!Flags.isFlagSet(this._layerMask, potential.physicsLayer.value)) continue; + if (this._ignoredColliders && this._ignoredColliders.has(potential)) { + continue; + } + // TODO: rayIntersects的性能够吗?需要测试它。Collisions.rectToLine可能更快 // TODO: 如果边界检查返回更多数据,我们就不需要为BoxCollider检查做任何事情 // 在做形状测试之前先做一个边界检查 - let colliderBounds = potential.bounds.clone(); - if (colliderBounds.rayIntersects(this._ray, fraction) && fraction.value <= 1) { + const colliderBounds = potential.bounds; + const res = colliderBounds.rayIntersects(this._ray); + if (res.intersected && res.distance <= 1) { if (potential.shape.collidesWithLine(this._ray.start, this._ray.end, this._tempHit)) { // 检查一下,我们应该排除这些射线,射线cast是否在碰撞器中开始 if (!Physics.raycastsStartInColliders && potential.shape.containsPoint(this._ray.start)) @@ -493,7 +433,7 @@ module es { } } - if (this._cellHits.length == 0) + if (this._cellHits.length === 0) return false; // 所有处理单元完成。对结果进行排序并将命中结果打包到结果数组中 @@ -503,7 +443,7 @@ module es { // 增加命中计数器,如果它已经达到数组大小的限制,我们就完成了 this.hitCounter++; - if (this.hitCounter == this._hits.length) + if (this.hitCounter === this._hits.length) return true; } @@ -514,6 +454,7 @@ module es { this._hits = null; this._checkedColliders.length = 0; this._cellHits.length = 0; + this._ignoredColliders = null; } } } diff --git a/source/src/Utils/Extensions/Vector2Ext.ts b/source/src/Utils/Extensions/Vector2Ext.ts index b40d4a6b..7ac94d1a 100644 --- a/source/src/Utils/Extensions/Vector2Ext.ts +++ b/source/src/Utils/Extensions/Vector2Ext.ts @@ -7,7 +7,7 @@ module es { * @param c */ public static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2) { - return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0; + return this.cross(center.sub(a), c.sub(center)) < 0; } public static halfVector(): Vector2 { @@ -48,7 +48,7 @@ module es { public static angle(from: Vector2, to: Vector2) { this.normalize(from); this.normalize(to); - return Math.acos(MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * MathHelper.Rad2Deg; + return Math.acos(MathHelper.clamp(from.dot(to), -1, 1)) * MathHelper.Rad2Deg; } /** @@ -58,8 +58,8 @@ module es { * @param right */ public static angleBetween(self: Vector2, left: Vector2, right: Vector2) { - let one = Vector2.subtract(left, self); - let two = Vector2.subtract(right, self); + const one = left.sub(self); + const two = right.sub(self); return this.angle(one, two); } diff --git a/source/src/Utils/PolygonLight/VisibilityComputer.ts b/source/src/Utils/PolygonLight/VisibilityComputer.ts index ddaff62b..c174113e 100644 --- a/source/src/Utils/PolygonLight/VisibilityComputer.ts +++ b/source/src/Utils/PolygonLight/VisibilityComputer.ts @@ -63,7 +63,7 @@ module es { * @param radius */ public addCircleOccluder(position: Vector2, radius: number){ - let dirToCircle = Vector2.subtract(position, this._origin); + let dirToCircle = position.sub(this._origin); let angle = Math.atan2(dirToCircle.y, dirToCircle.x); let stepSize = Math.PI / this.lineCountForCircleApproximation; diff --git a/source/src/Utils/Triangulator.ts b/source/src/Utils/Triangulator.ts index 6994d05d..65e489e0 100644 --- a/source/src/Utils/Triangulator.ts +++ b/source/src/Utils/Triangulator.ts @@ -13,15 +13,15 @@ module es { public static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean { // 如果点在AB的右边,那么外边的三角形是 - if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0) + if (Vector2Ext.cross(point.sub(a), b.sub(a)) < 0) return false; // 如果点在BC的右边,则在三角形的外侧 - if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0) + if (Vector2Ext.cross(point.sub(b), c.sub(b)) < 0) return false; // 如果点在ca的右边,则在三角形的外面 - if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0) + if (Vector2Ext.cross(point.sub(c), a.sub(c)) < 0) return false; // 点在三角形上