diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index a05d0b2e..87f2a989 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -17,280 +17,6 @@ declare interface Array { groupBy(keySelector: Function): Array; sum(selector: Function): number; } -declare module es { - class PriorityQueueNode { - priority: number; - insertionIndex: number; - queueIndex: number; - } -} -declare module es { - class AStarPathfinder { - static search(graph: IAstarGraph, start: T, goal: T): T[]; - static recontructPath(cameFrom: Map, start: T, goal: T): T[]; - private static hasKey; - private static getKey; - } -} -declare module es { - class AstarGridGraph implements IAstarGraph { - dirs: Vector2[]; - walls: Vector2[]; - weightedNodes: Vector2[]; - defaultWeight: number; - weightedNodeWeight: number; - private _width; - private _height; - private _neighbors; - constructor(width: number, height: number); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - search(start: Vector2, goal: Vector2): Vector2[]; - getNeighbors(node: Vector2): Vector2[]; - cost(from: Vector2, to: Vector2): number; - heuristic(node: Vector2, goal: Vector2): number; - } -} -declare module es { - interface IAstarGraph { - getNeighbors(node: T): Array; - cost(from: T, to: T): number; - heuristic(node: T, goal: T): any; - } -} -declare module es { - class PriorityQueue { - private _numNodes; - private _nodes; - private _numNodesEverEnqueued; - constructor(maxNodes: number); - readonly count: number; - readonly maxSize: number; - clear(): void; - contains(node: T): boolean; - enqueue(node: T, priority: number): void; - dequeue(): T; - remove(node: T): void; - isValidQueue(): boolean; - private onNodeUpdated; - private cascadeDown; - private cascadeUp; - private swap; - private hasHigherPriority; - } -} -declare module es { - class BreadthFirstPathfinder { - static search(graph: IUnweightedGraph, start: T, goal: T): T[]; - private static hasKey; - } -} -declare module es { - interface IUnweightedGraph { - getNeighbors(node: T): T[]; - } -} -declare module es { - class UnweightedGraph implements IUnweightedGraph { - edges: Map; - addEdgesForNode(node: T, edges: T[]): this; - getNeighbors(node: T): T[]; - } -} -declare module es { - class Vector2 implements IEquatable { - x: number; - y: number; - constructor(x?: number, y?: number); - static readonly zero: Vector2; - static readonly one: Vector2; - static readonly unitX: Vector2; - static readonly unitY: Vector2; - static add(value1: Vector2, value2: Vector2): Vector2; - static divide(value1: Vector2, value2: Vector2): Vector2; - static multiply(value1: Vector2, value2: Vector2): Vector2; - static subtract(value1: Vector2, value2: Vector2): Vector2; - static normalize(value: Vector2): Vector2; - static dot(value1: Vector2, value2: Vector2): number; - static distanceSquared(value1: Vector2, value2: Vector2): number; - static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2; - static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2; - static transform(position: Vector2, matrix: Matrix2D): Vector2; - static distance(value1: Vector2, value2: Vector2): number; - static angle(from: Vector2, to: Vector2): number; - static negate(value: Vector2): Vector2; - add(value: Vector2): Vector2; - divide(value: Vector2): Vector2; - multiply(value: Vector2): Vector2; - subtract(value: Vector2): this; - normalize(): void; - length(): number; - lengthSquared(): number; - round(): Vector2; - equals(other: Vector2 | object): boolean; - } -} -declare module es { - class UnweightedGridGraph implements IUnweightedGraph { - private static readonly CARDINAL_DIRS; - private static readonly COMPASS_DIRS; - walls: Vector2[]; - private _width; - private _hegiht; - private _dirs; - private _neighbors; - constructor(width: number, height: number, allowDiagonalSearch?: boolean); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - getNeighbors(node: Vector2): Vector2[]; - search(start: Vector2, goal: Vector2): Vector2[]; - } -} -declare module es { - interface IWeightedGraph { - getNeighbors(node: T): T[]; - cost(from: T, to: T): number; - } -} -declare module es { - class WeightedGridGraph implements IWeightedGraph { - static readonly CARDINAL_DIRS: Vector2[]; - private static readonly COMPASS_DIRS; - walls: Vector2[]; - weightedNodes: Vector2[]; - defaultWeight: number; - weightedNodeWeight: number; - private _width; - private _height; - private _dirs; - private _neighbors; - constructor(width: number, height: number, allowDiagonalSearch?: boolean); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - search(start: Vector2, goal: Vector2): Vector2[]; - getNeighbors(node: Vector2): Vector2[]; - cost(from: Vector2, to: Vector2): number; - } -} -declare module es { - class WeightedNode extends PriorityQueueNode { - data: T; - constructor(data: T); - } - class WeightedPathfinder { - static search(graph: IWeightedGraph, start: T, goal: T): T[]; - static recontructPath(cameFrom: Map, start: T, goal: T): T[]; - private static hasKey; - private static getKey; - } -} -declare module es { - class AStarStorage { - static readonly MAX_NODES: number; - _opened: AStarNode[]; - _closed: AStarNode[]; - _numOpened: number; - _numClosed: number; - _lastFoundOpened: number; - _lastFoundClosed: number; - constructor(); - clear(): void; - findOpened(node: AStarNode): AStarNode; - findClosed(node: AStarNode): AStarNode; - hasOpened(): boolean; - removeOpened(node: AStarNode): void; - removeClosed(node: AStarNode): void; - isOpen(node: AStarNode): boolean; - isClosed(node: AStarNode): boolean; - addToOpenList(node: AStarNode): void; - addToClosedList(node: AStarNode): void; - removeCheapestOpenNode(): AStarNode; - } -} -declare module es { - class AStarNode implements IEquatable, IPoolable { - worldState: WorldState; - costSoFar: number; - heuristicCost: number; - costSoFarAndHeuristicCost: number; - action: Action; - parent: AStarNode; - parentWorldState: WorldState; - depth: number; - equals(other: AStarNode): boolean; - compareTo(other: AStarNode): number; - reset(): void; - clone(): AStarNode; - toString(): string; - } - class AStar { - static storage: AStarStorage; - static plan(ap: ActionPlanner, start: WorldState, goal: WorldState, selectedNodes?: AStarNode[]): Action[]; - static reconstructPlan(goalNode: AStarNode, selectedNodes: AStarNode[]): Action[]; - static calculateHeuristic(fr: WorldState, to: WorldState): number; - } -} -declare module es { - class Action { - name: string; - cost: number; - _preConditions: Set<[string, boolean]>; - _postConditions: Set<[string, boolean]>; - constructor(name?: string, cost?: number); - setPrecondition(conditionName: string, value: boolean): void; - setPostcondition(conditionName: string, value: boolean): void; - validate(): boolean; - toString(): string; - } -} -declare module es { - class ActionPlanner { - static readonly MAX_CONDITIONS: number; - conditionNames: string[]; - _actions: Action[]; - _viableActions: Action[]; - _preConditions: WorldState[]; - _postConditions: WorldState[]; - _numConditionNames: number; - constructor(); - createWorldState(): WorldState; - addAction(action: Action): void; - plan(startState: WorldState, goalState: WorldState, selectedNode?: any): Action[]; - getPossibleTransitions(fr: WorldState): AStarNode[]; - applyPostConditions(ap: ActionPlanner, actionnr: number, fr: WorldState): WorldState; - findConditionNameIndex(conditionName: string): any; - findActionIndex(action: Action): number; - } -} -declare module es { - abstract class Agent { - actions: Action[]; - _planner: ActionPlanner; - constructor(); - plan(debugPlan?: boolean): boolean; - hasActionPlan(): boolean; - abstract getWorldState(): WorldState; - abstract getGoalState(): WorldState; - } -} -declare module es { - class WorldState implements IEquatable { - values: number; - dontCare: number; - planner: ActionPlanner; - static create(planner: ActionPlanner): WorldState; - constructor(planner: ActionPlanner, values: number, dontcare: number); - set(conditionId: number | string, value: boolean): boolean; - equals(other: WorldState): boolean; - describe(planner: ActionPlanner): string; - } -} -declare module es { - class DebugDefaults { - static verletParticle: number; - static verletConstraintEdge: number; - } -} declare module es { abstract class Component { entity: Entity; @@ -1137,6 +863,39 @@ declare module es { reset(): void; } } +declare module es { + class Vector2 implements IEquatable { + x: number; + y: number; + constructor(x?: number, y?: number); + static readonly zero: Vector2; + static readonly one: Vector2; + static readonly unitX: Vector2; + static readonly unitY: Vector2; + static add(value1: Vector2, value2: Vector2): Vector2; + static divide(value1: Vector2, value2: Vector2): Vector2; + static multiply(value1: Vector2, value2: Vector2): Vector2; + static subtract(value1: Vector2, value2: Vector2): Vector2; + static normalize(value: Vector2): Vector2; + static dot(value1: Vector2, value2: Vector2): number; + static distanceSquared(value1: Vector2, value2: Vector2): number; + static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2; + static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2; + static transform(position: Vector2, matrix: Matrix2D): Vector2; + static distance(value1: Vector2, value2: Vector2): number; + static angle(from: Vector2, to: Vector2): number; + static negate(value: Vector2): Vector2; + add(value: Vector2): Vector2; + divide(value: Vector2): Vector2; + multiply(value: Vector2): Vector2; + subtract(value: Vector2): this; + normalize(): void; + length(): number; + lengthSquared(): number; + round(): Vector2; + equals(other: Vector2 | object): boolean; + } +} declare module es { class Vector3 { x: number; diff --git a/source/bin/framework.js b/source/bin/framework.js index 9175fa10..ef9c23a9 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -1,13 +1,3 @@ -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } @@ -43,6 +33,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) { if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); Array.prototype.findIndex = function (predicate) { function findIndex(array, predicate) { for (var i = 0, len = array.length; i < len; i++) { @@ -278,1096 +278,6 @@ Array.prototype.sum = function (selector) { return sum(this, selector); }; var es; -(function (es) { - var PriorityQueueNode = (function () { - function PriorityQueueNode() { - this.priority = 0; - this.insertionIndex = 0; - this.queueIndex = 0; - } - return PriorityQueueNode; - }()); - es.PriorityQueueNode = PriorityQueueNode; -})(es || (es = {})); -var es; -(function (es) { - var AStarPathfinder = (function () { - function AStarPathfinder() { - } - AStarPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new es.PriorityQueue(1000); - frontier.enqueue(new AStarNode(start), 0); - costSoFar.set(start, 0); - var _loop_2 = function () { - var current = frontier.dequeue(); - if (current.data instanceof es.Vector2 && goal instanceof es.Vector2 && current.data.equals(goal)) { - foundPath = true; - return "break"; - } - else if (current.data == goal) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priority = newCost + graph.heuristic(next, goal); - frontier.enqueue(new AStarNode(next), priority); - cameFrom.set(next, current.data); - } - }); - }; - while (frontier.count > 0) { - var state_1 = _loop_2(); - if (state_1 === "break") - break; - } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - AStarPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - AStarPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (r.value instanceof es.Vector2 && compareKey instanceof es.Vector2 && r.value.equals(compareKey)) - return true; - else if (r.value == compareKey) - return true; - } - return false; - }; - AStarPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (r.value instanceof es.Vector2 && compareKey instanceof es.Vector2 && r.value.equals(compareKey)) - return v.value; - else if (r.value == compareKey) - return v.value; - } - return null; - }; - return AStarPathfinder; - }()); - es.AStarPathfinder = AStarPathfinder; - var AStarNode = (function (_super) { - __extends(AStarNode, _super); - function AStarNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return AStarNode; - }(es.PriorityQueueNode)); -})(es || (es = {})); -var es; -(function (es) { - var AstarGridGraph = (function () { - function AstarGridGraph(width, height) { - this.dirs = [ - new es.Vector2(1, 0), - new es.Vector2(0, -1), - new es.Vector2(-1, 0), - new es.Vector2(0, 1) - ]; - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - } - AstarGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - }; - AstarGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return wall.equals(node); }); - }; - AstarGridGraph.prototype.search = function (start, goal) { - return es.AStarPathfinder.search(this, start, goal); - }; - AstarGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this.dirs.forEach(function (dir) { - var next = new es.Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - AstarGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (p) { return p.equals(to); }) ? this.weightedNodeWeight : this.defaultWeight; - }; - AstarGridGraph.prototype.heuristic = function (node, goal) { - return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); - }; - return AstarGridGraph; - }()); - es.AstarGridGraph = AstarGridGraph; -})(es || (es = {})); -var es; -(function (es) { - var PriorityQueue = (function () { - function PriorityQueue(maxNodes) { - this._numNodes = 0; - this._nodes = new Array(maxNodes + 1); - this._numNodesEverEnqueued = 0; - } - Object.defineProperty(PriorityQueue.prototype, "count", { - get: function () { - return this._numNodes; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(PriorityQueue.prototype, "maxSize", { - get: function () { - return this._nodes.length - 1; - }, - enumerable: true, - configurable: true - }); - PriorityQueue.prototype.clear = function () { - this._nodes.splice(1, this._numNodes); - this._numNodes = 0; - }; - PriorityQueue.prototype.contains = function (node) { - if (!node) { - console.error("node cannot be null"); - return false; - } - if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length) { - console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); - return false; - } - return (this._nodes[node.queueIndex] == node); - }; - PriorityQueue.prototype.enqueue = function (node, priority) { - node.priority = priority; - this._numNodes++; - this._nodes[this._numNodes] = node; - node.queueIndex = this._numNodes; - node.insertionIndex = this._numNodesEverEnqueued++; - this.cascadeUp(this._nodes[this._numNodes]); - }; - PriorityQueue.prototype.dequeue = function () { - var returnMe = this._nodes[1]; - this.remove(returnMe); - return returnMe; - }; - PriorityQueue.prototype.remove = function (node) { - if (node.queueIndex == this._numNodes) { - this._nodes[this._numNodes] = null; - this._numNodes--; - return; - } - var formerLastNode = this._nodes[this._numNodes]; - this.swap(node, formerLastNode); - delete this._nodes[this._numNodes]; - this._numNodes--; - this.onNodeUpdated(formerLastNode); - }; - PriorityQueue.prototype.isValidQueue = function () { - for (var i = 1; i < this._nodes.length; i++) { - if (this._nodes[i]) { - var childLeftIndex = 2 * i; - if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && - this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) - return false; - var childRightIndex = childLeftIndex + 1; - if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && - this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) - return false; - } - } - return true; - }; - PriorityQueue.prototype.onNodeUpdated = function (node) { - var parentIndex = Math.floor(node.queueIndex / 2); - var parentNode = this._nodes[parentIndex]; - if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { - this.cascadeUp(node); - } - else { - this.cascadeDown(node); - } - }; - PriorityQueue.prototype.cascadeDown = function (node) { - var newParent; - var finalQueueIndex = node.queueIndex; - while (true) { - newParent = node; - var childLeftIndex = 2 * finalQueueIndex; - if (childLeftIndex > this._numNodes) { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - var childLeft = this._nodes[childLeftIndex]; - if (this.hasHigherPriority(childLeft, newParent)) { - newParent = childLeft; - } - var childRightIndex = childLeftIndex + 1; - if (childRightIndex <= this._numNodes) { - var childRight = this._nodes[childRightIndex]; - if (this.hasHigherPriority(childRight, newParent)) { - newParent = childRight; - } - } - if (newParent != node) { - this._nodes[finalQueueIndex] = newParent; - var temp = newParent.queueIndex; - newParent.queueIndex = finalQueueIndex; - finalQueueIndex = temp; - } - else { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - } - }; - PriorityQueue.prototype.cascadeUp = function (node) { - var parent = Math.floor(node.queueIndex / 2); - while (parent >= 1) { - var parentNode = this._nodes[parent]; - if (this.hasHigherPriority(parentNode, node)) - break; - this.swap(node, parentNode); - parent = Math.floor(node.queueIndex / 2); - } - }; - PriorityQueue.prototype.swap = function (node1, node2) { - this._nodes[node1.queueIndex] = node2; - this._nodes[node2.queueIndex] = node1; - var temp = node1.queueIndex; - node1.queueIndex = node2.queueIndex; - node2.queueIndex = temp; - }; - PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { - return (higher.priority < lower.priority || - (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); - }; - return PriorityQueue; - }()); - es.PriorityQueue = PriorityQueue; -})(es || (es = {})); -var es; -(function (es) { - var BreadthFirstPathfinder = (function () { - function BreadthFirstPathfinder() { - } - BreadthFirstPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var frontier = []; - frontier.unshift(start); - var cameFrom = new Map(); - cameFrom.set(start, start); - var _loop_3 = function () { - var current = frontier.shift(); - if (JSON.stringify(current) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current).forEach(function (next) { - if (!_this.hasKey(cameFrom, next)) { - frontier.unshift(next); - cameFrom.set(next, current); - } - }); - }; - while (frontier.length > 0) { - var state_2 = _loop_3(); - if (state_2 === "break") - break; - } - return foundPath ? es.AStarPathfinder.recontructPath(cameFrom, start, goal) : null; - }; - BreadthFirstPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; - } - return false; - }; - return BreadthFirstPathfinder; - }()); - es.BreadthFirstPathfinder = BreadthFirstPathfinder; -})(es || (es = {})); -var es; -(function (es) { - var UnweightedGraph = (function () { - function UnweightedGraph() { - this.edges = new Map(); - } - UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { - this.edges.set(node, edges); - return this; - }; - UnweightedGraph.prototype.getNeighbors = function (node) { - return this.edges.get(node); - }; - return UnweightedGraph; - }()); - es.UnweightedGraph = UnweightedGraph; -})(es || (es = {})); -var es; -(function (es) { - var Vector2 = (function () { - function Vector2(x, y) { - this.x = 0; - this.y = 0; - this.x = x ? x : 0; - this.y = y != undefined ? y : this.x; - } - Object.defineProperty(Vector2, "zero", { - get: function () { - return new Vector2(0, 0); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "one", { - get: function () { - return new Vector2(1, 1); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "unitX", { - get: function () { - return new Vector2(1, 0); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "unitY", { - get: function () { - return new Vector2(0, 1); - }, - enumerable: true, - configurable: true - }); - Vector2.add = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x + value2.x; - result.y = value1.y + value2.y; - return result; - }; - Vector2.divide = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x / value2.x; - result.y = value1.y / value2.y; - return result; - }; - Vector2.multiply = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x * value2.x; - result.y = value1.y * value2.y; - return result; - }; - Vector2.subtract = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x - value2.x; - result.y = value1.y - value2.y; - return result; - }; - Vector2.normalize = function (value) { - var nValue = new Vector2(value.x, value.y); - var val = 1 / Math.sqrt((nValue.x * nValue.x) + (nValue.y * nValue.y)); - nValue.x *= val; - nValue.y *= val; - return nValue; - }; - Vector2.dot = function (value1, value2) { - return (value1.x * value2.x) + (value1.y * value2.y); - }; - Vector2.distanceSquared = function (value1, value2) { - var v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return (v1 * v1) + (v2 * v2); - }; - Vector2.clamp = function (value1, min, max) { - return new Vector2(es.MathHelper.clamp(value1.x, min.x, max.x), es.MathHelper.clamp(value1.y, min.y, max.y)); - }; - Vector2.lerp = function (value1, value2, amount) { - return new Vector2(es.MathHelper.lerp(value1.x, value2.x, amount), es.MathHelper.lerp(value1.y, value2.y, amount)); - }; - Vector2.transform = function (position, matrix) { - return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31, (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32); - }; - Vector2.distance = function (value1, value2) { - var v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return Math.sqrt((v1 * v1) + (v2 * v2)); - }; - 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; - }; - Vector2.negate = function (value) { - value.x = -value.x; - value.y = -value.y; - return value; - }; - Vector2.prototype.add = function (value) { - this.x += value.x; - this.y += value.y; - return this; - }; - Vector2.prototype.divide = function (value) { - this.x /= value.x; - this.y /= value.y; - return this; - }; - Vector2.prototype.multiply = function (value) { - this.x *= value.x; - this.y *= value.y; - return this; - }; - Vector2.prototype.subtract = function (value) { - this.x -= value.x; - this.y -= value.y; - return this; - }; - Vector2.prototype.normalize = function () { - var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); - this.x *= val; - this.y *= val; - }; - Vector2.prototype.length = function () { - return Math.sqrt((this.x * this.x) + (this.y * this.y)); - }; - Vector2.prototype.lengthSquared = function () { - return (this.x * this.x) + (this.y * this.y); - }; - Vector2.prototype.round = function () { - return new Vector2(Math.round(this.x), Math.round(this.y)); - }; - Vector2.prototype.equals = function (other) { - if (other instanceof Vector2) { - return other.x == this.x && other.y == this.y; - } - return false; - }; - return Vector2; - }()); - es.Vector2 = Vector2; -})(es || (es = {})); -var es; -(function (es) { - var UnweightedGridGraph = (function () { - function UnweightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } - this.walls = []; - this._neighbors = new Array(4); - this._width = width; - this._hegiht = height; - this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; - } - UnweightedGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; - }; - UnweightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); - }; - UnweightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new es.Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - UnweightedGridGraph.prototype.search = function (start, goal) { - return es.BreadthFirstPathfinder.search(this, start, goal); - }; - UnweightedGridGraph.CARDINAL_DIRS = [ - new es.Vector2(1, 0), - new es.Vector2(0, -1), - new es.Vector2(-1, 0), - new es.Vector2(0, -1) - ]; - UnweightedGridGraph.COMPASS_DIRS = [ - new es.Vector2(1, 0), - new es.Vector2(1, -1), - new es.Vector2(0, -1), - new es.Vector2(-1, -1), - new es.Vector2(-1, 0), - new es.Vector2(-1, 1), - new es.Vector2(0, 1), - new es.Vector2(1, 1), - ]; - return UnweightedGridGraph; - }()); - es.UnweightedGridGraph = UnweightedGridGraph; -})(es || (es = {})); -var es; -(function (es) { - var WeightedGridGraph = (function () { - function WeightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; - } - WeightedGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - }; - WeightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); - }; - WeightedGridGraph.prototype.search = function (start, goal) { - return es.WeightedPathfinder.search(this, start, goal); - }; - WeightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new es.Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - WeightedGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; - }; - WeightedGridGraph.CARDINAL_DIRS = [ - new es.Vector2(1, 0), - new es.Vector2(0, -1), - new es.Vector2(-1, 0), - new es.Vector2(0, 1) - ]; - WeightedGridGraph.COMPASS_DIRS = [ - new es.Vector2(1, 0), - new es.Vector2(1, -1), - new es.Vector2(0, -1), - new es.Vector2(-1, -1), - new es.Vector2(-1, 0), - new es.Vector2(-1, 1), - new es.Vector2(0, 1), - new es.Vector2(1, 1), - ]; - return WeightedGridGraph; - }()); - es.WeightedGridGraph = WeightedGridGraph; -})(es || (es = {})); -var es; -(function (es) { - var WeightedNode = (function (_super) { - __extends(WeightedNode, _super); - function WeightedNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return WeightedNode; - }(es.PriorityQueueNode)); - es.WeightedNode = WeightedNode; - var WeightedPathfinder = (function () { - function WeightedPathfinder() { - } - WeightedPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new es.PriorityQueue(1000); - frontier.enqueue(new WeightedNode(start), 0); - costSoFar.set(start, 0); - var _loop_4 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priprity = newCost; - frontier.enqueue(new WeightedNode(next), priprity); - cameFrom.set(next, current.data); - } - }); - }; - while (frontier.count > 0) { - var state_3 = _loop_4(); - if (state_3 === "break") - break; - } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - WeightedPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; - } - return false; - }; - WeightedPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return v.value; - } - return null; - }; - return WeightedPathfinder; - }()); - es.WeightedPathfinder = WeightedPathfinder; -})(es || (es = {})); -var es; -(function (es) { - var AStarStorage = (function () { - function AStarStorage() { - this._opened = new Array(AStarStorage.MAX_NODES); - this._closed = new Array(AStarStorage.MAX_NODES); - } - AStarStorage.prototype.clear = function () { - for (var i = 0; i < this._numOpened; i++) { - es.Pool.free(this._opened[i]); - this._opened[i] = null; - } - for (var i = 0; i < this._numClosed; i++) { - es.Pool.free(this._closed[i]); - this._closed[i] = null; - } - this._numOpened = this._numClosed = 0; - this._lastFoundClosed = this._lastFoundOpened = 0; - }; - AStarStorage.prototype.findOpened = function (node) { - for (var i = 0; i < this._numOpened; i++) { - var care = node.worldState.dontCare ^ -1; - if ((node.worldState.values & care) == (this._opened[i].worldState.values & care)) { - this._lastFoundClosed = i; - return this._closed[i]; - } - } - return null; - }; - AStarStorage.prototype.findClosed = function (node) { - for (var i = 0; i < this._numClosed; i++) { - var care = node.worldState.dontCare ^ -1; - if ((node.worldState.values & care) == (this._closed[i].worldState.values & care)) { - this._lastFoundClosed = i; - return this._closed[i]; - } - } - return null; - }; - AStarStorage.prototype.hasOpened = function () { - return this._numOpened > 0; - }; - AStarStorage.prototype.removeOpened = function (node) { - if (this._numOpened > 0) - this._opened[this._lastFoundOpened] = this._opened[this._numOpened - 1]; - this._numOpened--; - }; - AStarStorage.prototype.removeClosed = function (node) { - if (this._numClosed > 0) - this._closed[this._lastFoundClosed] = this._closed[this._numClosed - 1]; - this._numClosed--; - }; - AStarStorage.prototype.isOpen = function (node) { - return this._opened.indexOf(node) > -1; - }; - AStarStorage.prototype.isClosed = function (node) { - return this._closed.indexOf(node) > -1; - }; - AStarStorage.prototype.addToOpenList = function (node) { - this._opened[this._numOpened++] = node; - }; - AStarStorage.prototype.addToClosedList = function (node) { - this._closed[this._numClosed++] = node; - }; - AStarStorage.prototype.removeCheapestOpenNode = function () { - var lowestVal = Number.MAX_VALUE; - this._lastFoundOpened = -1; - for (var i = 0; i < this._numOpened; i++) { - if (this._opened[i].costSoFarAndHeuristicCost < lowestVal) { - lowestVal = this._opened[i].costSoFarAndHeuristicCost; - this._lastFoundOpened = i; - } - } - var val = this._opened[this._lastFoundOpened]; - this.removeOpened(val); - return val; - }; - AStarStorage.MAX_NODES = 128; - return AStarStorage; - }()); - es.AStarStorage = AStarStorage; -})(es || (es = {})); -var es; -(function (es) { - var AStarNode = (function () { - function AStarNode() { - } - AStarNode.prototype.equals = function (other) { - var care = this.worldState.dontCare ^ -1; - return (this.worldState.values & care) == (other.worldState.values & care); - }; - AStarNode.prototype.compareTo = function (other) { - return this.costSoFarAndHeuristicCost - other.costSoFarAndHeuristicCost; - }; - AStarNode.prototype.reset = function () { - this.action = null; - this.parent = null; - }; - AStarNode.prototype.clone = function () { - var node = new AStarNode(); - node.action = this.action; - node.costSoFar = this.costSoFar; - node.depth = this.depth; - node.parent = this.parent; - node.parentWorldState = this.parentWorldState; - node.heuristicCost = this.heuristicCost; - node.worldState = this.worldState; - return node; - }; - AStarNode.prototype.toString = function () { - return "[cost: " + this.costSoFar + " | heuristic: " + this.heuristicCost + "]: " + this.action; - }; - return AStarNode; - }()); - es.AStarNode = AStarNode; - var AStar = (function () { - function AStar() { - } - AStar.plan = function (ap, start, goal, selectedNodes) { - if (selectedNodes === void 0) { selectedNodes = null; } - this.storage.clear(); - var currentNode = es.Pool.obtain(AStarNode); - currentNode.worldState = start; - currentNode.parentWorldState = start; - currentNode.costSoFar = 0; - currentNode.heuristicCost = this.calculateHeuristic(start, goal); - currentNode.costSoFarAndHeuristicCost = currentNode.costSoFar + currentNode.heuristicCost; - currentNode.depth = 1; - this.storage.addToOpenList(currentNode); - while (true) { - if (!this.storage.hasOpened()) { - this.storage.clear(); - return null; - } - currentNode = this.storage.removeCheapestOpenNode(); - this.storage.addToClosedList(currentNode); - if (goal.equals(currentNode.worldState)) { - var plan = this.reconstructPlan(currentNode, selectedNodes); - this.storage.clear(); - return plan; - } - var neighbors = ap.getPossibleTransitions(currentNode.worldState); - for (var i = 0; i < neighbors.length; i++) { - var cur = neighbors[i]; - var opened = this.storage.findOpened(cur); - var closed_1 = this.storage.findClosed(cur); - var cost = currentNode.costSoFar + cur.costSoFar; - if (opened != null && cost < opened.costSoFar) { - this.storage.removeOpened(opened); - opened = null; - } - if (closed_1 != null && cost < closed_1.costSoFar) { - this.storage.removeClosed(closed_1); - } - if (opened == null && closed_1 == null) { - var nb = es.Pool.obtain(AStarNode); - nb.worldState = cur.worldState; - nb.costSoFar = cost; - nb.heuristicCost = this.calculateHeuristic(cur.worldState, goal); - nb.costSoFarAndHeuristicCost = nb.costSoFar + nb.heuristicCost; - nb.action = cur.action; - nb.parentWorldState = currentNode.worldState; - nb.parent = currentNode; - nb.depth = currentNode.depth + 1; - this.storage.addToOpenList(nb); - } - } - es.ListPool.free(neighbors); - } - }; - AStar.reconstructPlan = function (goalNode, selectedNodes) { - var totalActionsInPlan = goalNode.depth - 1; - var plan = new Array(totalActionsInPlan); - var curnode = goalNode; - for (var i = 0; i <= totalActionsInPlan - 1; i++) { - if (selectedNodes != null) - selectedNodes.push(curnode.clone()); - plan.push(curnode.action); - curnode = curnode.parent; - } - if (selectedNodes != null) - selectedNodes.reverse(); - return plan; - }; - AStar.calculateHeuristic = function (fr, to) { - var care = (to.dontCare ^ -1); - var diff = (fr.values & care) ^ (to.values & care); - var dist = 0; - for (var i = 0; i < es.ActionPlanner.MAX_CONDITIONS; ++i) - if ((diff & (1 << i)) != 0) - dist++; - return dist; - }; - AStar.storage = new es.AStarStorage(); - return AStar; - }()); - es.AStar = AStar; -})(es || (es = {})); -var es; -(function (es) { - var Action = (function () { - function Action(name, cost) { - if (cost === void 0) { cost = 1; } - this.cost = 1; - this._preConditions = new Set(); - this._postConditions = new Set(); - this.name = name; - this.cost = cost; - } - Action.prototype.setPrecondition = function (conditionName, value) { - this._preConditions.add([conditionName, value]); - }; - Action.prototype.setPostcondition = function (conditionName, value) { - this._preConditions.add([conditionName, value]); - }; - Action.prototype.validate = function () { - return true; - }; - Action.prototype.toString = function () { - return "[Action] " + this.name + " - cost: " + this.cost; - }; - return Action; - }()); - es.Action = Action; -})(es || (es = {})); -var es; -(function (es) { - var ActionPlanner = (function () { - function ActionPlanner() { - this.conditionNames = new Array(ActionPlanner.MAX_CONDITIONS); - this._actions = []; - this._viableActions = []; - this._preConditions = new Array(ActionPlanner.MAX_CONDITIONS); - this._postConditions = new Array(ActionPlanner.MAX_CONDITIONS); - this._numConditionNames = 0; - for (var i = 0; i < ActionPlanner.MAX_CONDITIONS; ++i) { - this.conditionNames[i] = null; - this._preConditions[i] = es.WorldState.create(this); - this._postConditions[i] = es.WorldState.create(this); - } - } - ActionPlanner.prototype.createWorldState = function () { - return es.WorldState.create(this); - }; - ActionPlanner.prototype.addAction = function (action) { - var _this = this; - var actionId = this.findActionIndex(action); - if (actionId == -1) - throw new Error("无法找到或创建行动"); - action._preConditions.forEach(function (preCondition) { - var conditionId = _this.findConditionNameIndex(preCondition[0]); - if (conditionId == -1) - throw new Error("无法找到或创建条件名称"); - _this._preConditions[actionId].set(conditionId, preCondition[1]); - }); - action._postConditions.forEach(function (postCondition) { - var conditionId = _this.findConditionNameIndex(postCondition[0]); - if (conditionId == -1) - throw new Error("找不到条件名称"); - _this._postConditions[actionId].set(conditionId, postCondition[1]); - }); - }; - ActionPlanner.prototype.plan = function (startState, goalState, selectedNode) { - if (selectedNode === void 0) { selectedNode = null; } - this._viableActions.length = 0; - for (var i = 0; i < this._actions.length; i++) { - if (this._actions[i].validate()) - this._viableActions.push(this._actions[i]); - } - return es.AStar.plan(this, startState, goalState, selectedNode); - }; - ActionPlanner.prototype.getPossibleTransitions = function (fr) { - var result = es.ListPool.obtain(); - for (var i = 0; i < this._viableActions.length; ++i) { - var pre = this._preConditions[i]; - var care = (pre.dontCare ^ -1); - var met = ((pre.values & care) == (fr.values & care)); - if (met) { - var node = es.Pool.obtain(es.AStarNode); - node.action = this._viableActions[i]; - node.costSoFar = this._viableActions[i].cost; - node.worldState = this.applyPostConditions(this, i, fr); - result.push(node); - } - } - return result; - }; - ActionPlanner.prototype.applyPostConditions = function (ap, actionnr, fr) { - var pst = ap._postConditions[actionnr]; - var unaffected = pst.dontCare; - var affected = (unaffected ^ -1); - fr.values = (fr.values & unaffected) | (pst.values & affected); - fr.dontCare &= pst.dontCare; - return fr; - }; - ActionPlanner.prototype.findConditionNameIndex = function (conditionName) { - var idx; - for (idx = 0; idx < this._numConditionNames; ++idx) { - if (this.conditionNames[idx] == conditionName) - return idx; - } - if (idx < ActionPlanner.MAX_CONDITIONS - 1) { - this.conditionNames[idx] = conditionName; - this._numConditionNames++; - return idx; - } - return -1; - }; - ActionPlanner.prototype.findActionIndex = function (action) { - var idx = this._actions.indexOf(action); - if (idx > -1) - return idx; - this._actions.push(action); - return this._actions.length - 1; - }; - ActionPlanner.MAX_CONDITIONS = 64; - return ActionPlanner; - }()); - es.ActionPlanner = ActionPlanner; -})(es || (es = {})); -var es; -(function (es) { - var Agent = (function () { - function Agent() { - this._planner = new es.ActionPlanner(); - } - Agent.prototype.plan = function (debugPlan) { - if (debugPlan === void 0) { debugPlan = false; } - var nodes = null; - if (debugPlan) - nodes = []; - this.actions = this._planner.plan(this.getWorldState(), this.getGoalState(), nodes); - if (nodes != null && nodes.length > 0) { - console.log("---- ActionPlanner plan ----"); - console.log("plan cost = " + nodes[nodes.length - 1].costSoFar); - console.log(" start" + "\t" + this.getWorldState().describe(this._planner)); - for (var i = 0; i < nodes.length; i++) { - console.log(i + ": " + nodes[i].action.name + "\t" + nodes[i].worldState.describe(this._planner)); - es.Pool.free(nodes[i]); - } - } - return this.hasActionPlan(); - }; - Agent.prototype.hasActionPlan = function () { - return this.actions != null && this.actions.length > 0; - }; - return Agent; - }()); - es.Agent = Agent; -})(es || (es = {})); -var es; -(function (es) { - var WorldState = (function () { - function WorldState(planner, values, dontcare) { - this.planner = planner; - this.values = values; - this.dontCare = dontcare; - } - WorldState.create = function (planner) { - return new WorldState(planner, 0, -1); - }; - WorldState.prototype.set = function (conditionId, value) { - if (typeof conditionId == "string") { - return this.set(this.planner.findConditionNameIndex(conditionId), value); - } - this.values = value ? (this.values | (1 << conditionId)) : (this.values & ~(1 << conditionId)); - this.dontCare ^= (1 << conditionId); - return true; - }; - WorldState.prototype.equals = function (other) { - var care = this.dontCare ^ -1; - return (this.values & care) == (other.values & care); - }; - WorldState.prototype.describe = function (planner) { - var s = ""; - for (var i = 0; i < es.ActionPlanner.MAX_CONDITIONS; i++) { - if ((this.dontCare & (1 << i)) == 0) { - var val = planner.conditionNames[i]; - if (val == null) - continue; - var set = ((this.values & (1 << i)) != 0); - if (s.length > 0) - s += ", "; - s += (set ? val.toUpperCase() : val); - } - } - return s; - }; - return WorldState; - }()); - es.WorldState = WorldState; -})(es || (es = {})); -var es; -(function (es) { - var DebugDefaults = (function () { - function DebugDefaults() { - } - DebugDefaults.verletParticle = 0xDC345E; - DebugDefaults.verletConstraintEdge = 0x433E36; - return DebugDefaults; - }()); - es.DebugDefaults = DebugDefaults; -})(es || (es = {})); -var es; (function (es) { var Component = (function () { function Component() { @@ -5411,6 +4321,148 @@ var es; es.SubpixelVector2 = SubpixelVector2; })(es || (es = {})); var es; +(function (es) { + var Vector2 = (function () { + function Vector2(x, y) { + this.x = 0; + this.y = 0; + this.x = x ? x : 0; + this.y = y != undefined ? y : this.x; + } + Object.defineProperty(Vector2, "zero", { + get: function () { + return new Vector2(0, 0); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "one", { + get: function () { + return new Vector2(1, 1); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitX", { + get: function () { + return new Vector2(1, 0); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitY", { + get: function () { + return new Vector2(0, 1); + }, + enumerable: true, + configurable: true + }); + Vector2.add = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x + value2.x; + result.y = value1.y + value2.y; + return result; + }; + Vector2.divide = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x / value2.x; + result.y = value1.y / value2.y; + return result; + }; + Vector2.multiply = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x * value2.x; + result.y = value1.y * value2.y; + return result; + }; + Vector2.subtract = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x - value2.x; + result.y = value1.y - value2.y; + return result; + }; + Vector2.normalize = function (value) { + var nValue = new Vector2(value.x, value.y); + var val = 1 / Math.sqrt((nValue.x * nValue.x) + (nValue.y * nValue.y)); + nValue.x *= val; + nValue.y *= val; + return nValue; + }; + Vector2.dot = function (value1, value2) { + return (value1.x * value2.x) + (value1.y * value2.y); + }; + Vector2.distanceSquared = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return (v1 * v1) + (v2 * v2); + }; + Vector2.clamp = function (value1, min, max) { + return new Vector2(es.MathHelper.clamp(value1.x, min.x, max.x), es.MathHelper.clamp(value1.y, min.y, max.y)); + }; + Vector2.lerp = function (value1, value2, amount) { + return new Vector2(es.MathHelper.lerp(value1.x, value2.x, amount), es.MathHelper.lerp(value1.y, value2.y, amount)); + }; + Vector2.transform = function (position, matrix) { + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31, (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32); + }; + Vector2.distance = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return Math.sqrt((v1 * v1) + (v2 * v2)); + }; + 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; + }; + Vector2.negate = function (value) { + value.x = -value.x; + value.y = -value.y; + return value; + }; + Vector2.prototype.add = function (value) { + this.x += value.x; + this.y += value.y; + return this; + }; + Vector2.prototype.divide = function (value) { + this.x /= value.x; + this.y /= value.y; + return this; + }; + Vector2.prototype.multiply = function (value) { + this.x *= value.x; + this.y *= value.y; + return this; + }; + Vector2.prototype.subtract = function (value) { + this.x -= value.x; + this.y -= value.y; + return this; + }; + Vector2.prototype.normalize = function () { + var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); + this.x *= val; + this.y *= val; + }; + Vector2.prototype.length = function () { + return Math.sqrt((this.x * this.x) + (this.y * this.y)); + }; + Vector2.prototype.lengthSquared = function () { + return (this.x * this.x) + (this.y * this.y); + }; + Vector2.prototype.round = function () { + return new Vector2(Math.round(this.x), Math.round(this.y)); + }; + Vector2.prototype.equals = function (other) { + if (other instanceof Vector2) { + return other.x == this.x && other.y == this.y; + } + return false; + }; + return Vector2; + }()); + es.Vector2 = Vector2; +})(es || (es = {})); +var es; (function (es) { var Vector3 = (function () { function Vector3(x, y, z) { @@ -5436,7 +4488,7 @@ var es; for (var i = 0; i < colliders.length; i++) { var collider = colliders[i]; var neighbors = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); - var _loop_5 = function (j) { + var _loop_2 = function (j) { var neighbor = neighbors[j]; if (!collider.isTrigger && !neighbor.isTrigger) return "continue"; @@ -5455,7 +4507,7 @@ var es; }; var this_1 = this; for (var j = 0; j < neighbors.length; j++) { - _loop_5(j); + _loop_2(j); } } es.ListPool.free(colliders); @@ -5463,7 +4515,7 @@ var es; }; ColliderTriggerHelper.prototype.checkForExitedColliders = function () { var _this = this; - var _loop_6 = function (i) { + var _loop_3 = function (i) { var index = this_2._previousTriggerIntersections.findIndex(function (value) { if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second) return true; @@ -5474,7 +4526,7 @@ var es; }; var this_2 = this; for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - _loop_6(i); + _loop_3(i); } for (var i = 0; i < this._previousTriggerIntersections.length; i++) { this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); @@ -5850,7 +4902,7 @@ var es; var cell = this.cellAtPosition(x, y); if (!cell) continue; - var _loop_7 = function (i) { + var _loop_4 = function (i) { var collider = cell[i]; if (collider == excludeCollider || !es.Flags.isFlagSet(layerMask, collider.physicsLayer.value)) return "continue"; @@ -5861,7 +4913,7 @@ var es; }; var this_3 = this; for (var i = 0; i < cell.length; i++) { - _loop_7(i); + _loop_4(i); } } } diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index b259829c..f8b87c3c 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.es={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((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]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e.hasKey=function(e,n){for(var i,r=e.keys();!(i=r.next()).done;){if(i.value instanceof t.Vector2&&n instanceof t.Vector2&&i.value.equals(n))return!0;if(i.value==n)return!0}return!1},e.getKey=function(e,n){for(var i,r,o=e.keys(),s=e.values();i=o.next(),r=s.next(),!i.done;){if(i.value instanceof t.Vector2&&n instanceof t.Vector2&&i.value.equals(n))return r.value;if(i.value==n)return r.value}return null},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode)}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},t.prototype.enqueue=function(t,e){t.priority=e,this._numNodes++,this._nodes[this._numNodes]=t,t.queueIndex=this._numNodes,t.insertionIndex=this._numNodesEverEnqueued++,this.cascadeUp(this._nodes[this._numNodes])},t.prototype.dequeue=function(){var t=this._nodes[1];return this.remove(t),t},t.prototype.remove=function(t){if(t.queueIndex==this._numNodes)return this._nodes[this._numNodes]=null,void this._numNodes--;var e=this._nodes[this._numNodes];this.swap(t,e),delete this._nodes[this._numNodes],this._numNodes--,this.onNodeUpdated(e)},t.prototype.isValidQueue=function(){for(var t=1;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=null!=e?e:this.x}return Object.defineProperty(e,"zero",{get:function(){return new e(0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return new e(1,1)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return new e(1,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return new e(0,1)},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.normalize=function(t){var n=new e(t.x,t.y),i=1/Math.sqrt(n.x*n.x+n.y*n.y);return n.x*=i,n.y*=i,n},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.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.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.prototype.add=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.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},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.equals=function(t){return t instanceof e&&(t.x==this.x&&t.y==this.y)},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){this._opened=new Array(e.MAX_NODES),this._closed=new Array(e.MAX_NODES)}return e.prototype.clear=function(){for(var e=0;e0},e.prototype.removeOpened=function(t){this._numOpened>0&&(this._opened[this._lastFoundOpened]=this._opened[this._numOpened-1]),this._numOpened--},e.prototype.removeClosed=function(t){this._numClosed>0&&(this._closed[this._lastFoundClosed]=this._closed[this._numClosed-1]),this._numClosed--},e.prototype.isOpen=function(t){return this._opened.indexOf(t)>-1},e.prototype.isClosed=function(t){return this._closed.indexOf(t)>-1},e.prototype.addToOpenList=function(t){this._opened[this._numOpened++]=t},e.prototype.addToClosedList=function(t){this._closed[this._numClosed++]=t},e.prototype.removeCheapestOpenNode=function(){var t=Number.MAX_VALUE;this._lastFoundOpened=-1;for(var e=0;e-1?e:(this._actions.push(t),this._actions.length-1)},e.MAX_CONDITIONS=64,e}();t.ActionPlanner=e}(es||(es={})),function(t){var e=function(){function e(){this._planner=new t.ActionPlanner}return e.prototype.plan=function(e){void 0===e&&(e=!1);var n=null;if(e&&(n=[]),this.actions=this._planner.plan(this.getWorldState(),this.getGoalState(),n),null!=n&&n.length>0){console.log("---- ActionPlanner plan ----"),console.log("plan cost = "+n[n.length-1].costSoFar),console.log(" start\t"+this.getWorldState().describe(this._planner));for(var i=0;i0},e}();t.Agent=e}(es||(es={})),function(t){var e=function(){function e(t,e,n){this.planner=t,this.values=e,this.dontCare=n}return e.create=function(t){return new e(t,0,-1)},e.prototype.set=function(t,e){return"string"==typeof t?this.set(this.planner.findConditionNameIndex(t),e):(this.values=e?this.values|1<0&&(n+=", "),n+=o?r.toUpperCase():r}return n},e}();t.WorldState=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(t){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t}();t.Component=e}(es||(es={})),function(t){var e=function(){function e(n,i){this._globalManagers=[],this._timerManager=new t.TimerManager,this._frameCounterElapsedTime=0,this._frameCounter=0,this.width=n,this.height=i,e._instance=this,e.emitter=new t.Emitter,e.registerGlobalManager(this._timerManager),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(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),e.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),e.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},e.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},e.getGlobalManager=function(t){for(var e=0;e=0;t--)this._globalManagers[t].enabled&&this._globalManagers[t].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),[4,this._scene.begin()]):[3,2];case 1:e.sent(),e.label=2;case 2:return[4,this.draw()];case 3:return e.sent(),[2]}})})},e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){!function(t){t[t.GraphicsDeviceReset=0]="GraphicsDeviceReset",t[t.SceneChanged=1]="SceneChanged",t[t.OrientationChanged=2]="OrientationChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localScale",{get:function(){return this.transform.localScale},set:function(t){this.transform.setLocalScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene&&(this.scene.entities.markEntityListUnsorted(),this.scene.entities.markTagUnsorted(this.tag)),this},e.prototype.destroy=function(){this._isDestroyed=!0,this.scene.entities.remove(this),this.transform.parent=null;for(var t=this.transform.childCount-1;t>=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateList()},e.prototype.render=function(){if(0!=this._renderers.length)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,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=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(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),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(this._translationMatrix),this.parent||(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),this.parent&&(this._worldTransform=this._localTransform.multiply(this.parent._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)}this._children||(this._children=[]);for(var n=0;n0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e,t.isIUpdatable=function(t){return void 0!==t.js}}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(){function e(){this.updateOrder=0,this._enabled=!0}return Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.onRemovedFromScene=function(){},e.prototype.update=function(){},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled),this},e.prototype.setUpdateOrder=function(e){return this.updateOrder!=e&&(this.updateOrder=e,t.Core.scene._sceneComponents.sort(this.compareTo)),this},e.prototype.compareTo=function(t){return this.updateOrder-t.updateOrder},e}();t.SceneComponent=e}(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){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.LONG_MASK=63,t}();t.BitSet=e}(es||(es={})),function(t){var e=function(){function e(e){this._components=new t.FastList,this._updatableComponents=new t.FastList,this._componentsToAdd=[],this._componentsToRemove=[],this._tempBufferList=[],this._entity=e}return Object.defineProperty(e.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buffer",{get:function(){return this._components.buffer},enumerable:!0,configurable:!0}),e.prototype.markEntityListUnsorted=function(){this._isComponentListUnsorted=!0},e.prototype.add=function(t){this._componentsToAdd.push(t)},e.prototype.remove=function(t){this._componentsToRemove.contains(t)&&console.warn("您正在尝试删除一个您已经删除的组件("+t+")"),this._componentsToAdd.contains(t)?this._componentsToAdd.remove(t):this._componentsToRemove.push(t)},e.prototype.removeAllComponents=function(){for(var t=0;t0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){for(var e=0,n=this._entitiesToRemove;e0;){(i=this._addToSceneEntityList.shift()).onAddedToScene()}if(this._entitiesToAdded.length>0)if(this.frameAllocate&&this._entitiesToAdded.length>this.maxAllocate){for(var r=0;r0;)this.perEntityAddToScene();this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(function(t,e){return t.compareTo(e)}),this._isEntityListUnsorted=!1),0==this._addToSceneEntityList.length&&this._unsortedTags.size>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort(function(t,e){return t.compareTo(e)})}),this._unsortedTags.clear())},e.prototype.perEntityAddToScene=function(){var t=this._entitiesToAdded.shift();this._addToSceneEntityList.push(t),-1==this._entities.findIndex(function(e){return e.id==t.id})&&(this._entities.push(t),t.scene=this.scene,this.addToTagList(t),this.scene.entityProcessors.onEntityAdded(t))},e.prototype.findEntity=function(t){for(var e=0;ethis._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(){function e(t){void 0===t&&(t=5),this.length=0,this.buffer=new Array(t)}return e.prototype.clear=function(){this.buffer.length=0,this.length=0},e.prototype.reset=function(){this.length=0},e.prototype.add=function(t){this.length==this.buffer.length&&(this.buffer.length=Math.max(this.buffer.length<<1,10)),this.buffer[this.length++]=t},e.prototype.remove=function(e){for(var n=t.EqualityComparer.default(),i=0;i=this.length)throw new Error("index超出范围!");this.length--,this.buffer.removeAt(t)},e.prototype.contains=function(e){for(var n=t.EqualityComparer.default(),i=0;i=this.buffer.length&&(this.buffer.length=Math.max(this.buffer.length<<1,this.length+t))},e.prototype.addRange=function(t){for(var e=0,n=t;e=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;i=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=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){var e=(t-this._lastTime)/1e3;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 Math.floor(this._timeSinceSceneLoad/t)>Math.floor((this._timeSinceSceneLoad-this.deltaTime)/t)},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,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,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},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(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;on?n:t},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.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.incrementWithWrap=function(t,e){return++t==e?0:t},e.approach=function(t,e,n){return ti&&(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,c=(this.y-t.start.y)*a,h=(this.y+this.height-t.start.y)*a;if(c>h){var u=c;c=h,h=u}if(e.value=Math.max(c,e.value),n=Math.max(h,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=h>0?l-h:-l-h,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 this.x^this.y^this.width^this.height},e.emptyRectangle=new e,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.floor(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(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},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.reset=function(){this.collider=null,this.fraction=this.distance=0},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)},e.clear=function(){this._spatialHash.clear()},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.error("An empty results array was passed in. No results will ever be returned.")},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.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.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.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e._hitArray=[new t.RaycastHit],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._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=[],this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds;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++){var a=this.cellAtPosition(o,s,!0);a.firstOrDefault(function(t){return t==e})||a.push(e)}},e.prototype.remove=function(t){for(var e=t.registeredPhysicsBounds,n=this.cellCoords(e.x,e.y),i=this.cellCoords(e.right,e.bottom),r=n.x;r<=i.x;r++)for(var o=n.y;o<=i.y;o++){var s=this.cellAtPosition(r,o);s?s.remove(t):console.log("从不存在碰撞器的单元格中移除碰撞器: ["+t+"]")}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.debugDraw=function(t,e){void 0===e&&(e=1);for(var n=this.gridBounds.x;n<=this.gridBounds.right;n++)for(var i=this.gridBounds.y;i<=this.gridBounds.bottom;i++){var r=this.cellAtPosition(n,i);r&&r.length>0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;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 c=this.cellAtPosition(s,a);if(c)for(var h=function(r){var o=c[r];if(o==n||!t.Flags.isFlagSet(i,o.physicsLayer.value))return"continue";e.intersects(o.bounds)&&(u._tempHashSet.firstOrDefault(function(t){return t==o})||u._tempHashSet.push(o))},u=this,l=0;l=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=new t.Vector2(0,0),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.ShapeCollisions.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,c=t.Vector2.add(s.start,t.Vector2.add(s.direction,new t.Vector2(r.value))),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var u=a+h;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),!0},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.polygonToPolygon=function(e,n,i){for(var r,o=!0,s=e.edgeNormals,a=n.edgeNormals,c=Number.POSITIVE_INFINITY,h=new t.Vector2,u=t.Vector2.subtract(e.position,n.position),l=0;l0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=new t.Ref(0),a=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,s,i.normal),c=n.containsPoint(e.position);if(s.value>e.radius*e.radius&&!c)return!1;if(c)r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(s.value)-e.radius));else if(0==s.value)r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var h=Math.sqrt(s.value);r=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(o,a)),new t.Vector2((e.radius-s.value)/h))}return i.minimumTranslationVector=r,i.point=t.Vector2.add(a,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r1)return!1;var l=(h.x*s.y-h.y*s.x)/c;return!(l<0||l>1)&&(o=o.add(e).add(t.Vector2.multiply(new t.Vector2(u),s)),!0)},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divide(t.Vector2.subtract(n,e),new t.Vector2(o)),a=t.Vector2.subtract(e,i.position),c=t.Vector2.dot(a,s),h=t.Vector2.dot(a,a)-i.radius*i.radius;if(h>0&&c>0)return!1;var u=c*c-h;return!(u<0)&&(r.fraction=-c-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(r.fraction),s)),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.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),r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,new t.Vector2(-i.x)),c=new t.Ref(0);return!!(o.rayIntersects(a,c)&&c.value<=1)&&(r.fraction=c.value,r.distance=i.length()*c.value,r.normal=new t.Vector2(-i.x,-i.y),r.normal.normalize(),r.centroid=t.Vector2.add(e.bounds.center,t.Vector2.multiply(i,new t.Vector2(c.value))),!0)},e}();t.ShapeCollisions=e}(es||(es={}));var ArrayUtils=function(){function t(){}return t.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}},t.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},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.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)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.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},t.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},t}();!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=[],c=0;c>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(c++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(c++))),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,c=[],h=0;h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c.push(this._keyStr.charAt(r)),c.push(this._keyStr.charAt(o)),c.push(this._keyStr.charAt(s)),c.push(this._keyStr.charAt(a));return c=c.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>16},set:function(t){this._packedValue=4278255615&this._packedValue|t<<16},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"g",{get:function(){return this._packedValue>>8},set:function(t){this._packedValue=4294902015&this._packedValue|t<<8},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"r",{get:function(){return this._packedValue},set:function(t){this._packedValue=4294967040&this._packedValue|t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"a",{get:function(){return this._packedValue>>24},set:function(t){this._packedValue=16777215&this._packedValue|t<<24},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"packedValue",{get:function(){return this._packedValue},set:function(t){this._packedValue=t},enumerable:!0,configurable:!0}),e.prototype.equals=function(t){return this._packedValue==t._packedValue},e}();t.Color=e}(es||(es={})),function(t){var e=function(){function e(){}return e.oppositeEdge=function(e){switch(e){case t.Edge.bottom:return t.Edge.top;case t.Edge.top:return t.Edge.bottom;case t.Edge.left:return t.Edge.right;case t.Edge.right:return t.Edge.left}},e.isHorizontal=function(e){return e==t.Edge.right||e==t.Edge.left},e.isVertical=function(e){return e==t.Edge.top||e==t.Edge.bottom},e}();t.EdgeExt=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();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.repeat=function(t,e){for(var n=[];e--;)n.push(t);return n},t}();t.Enumerable=e}(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}();t.EqualityComparer=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function t(){}return t.warmCache=function(t){if((t-=this._objectQueue.length)>0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.toNumber=function(t){return null==t?0:Number(t)},t}();t.NumberExtension=e}(es||(es={})),function(t){var e=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}();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.js}}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(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}();!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,r.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}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){return function(t){this.value=t}}();t.Ref=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelNumber=e}(es||(es={})),function(t){var e=function(){function e(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return e.testPointTriangle=function(e,n,i,r){return!(t.Vector2Ext.cross(t.Vector2.subtract(e,n),t.Vector2.subtract(i,n))<0)&&(!(t.Vector2Ext.cross(t.Vector2.subtract(e,i),t.Vector2.subtract(r,i))<0)&&!(t.Vector2Ext.cross(t.Vector2.subtract(e,r),t.Vector2.subtract(n,r))<0))},e.prototype.triangulate=function(n,i){void 0===i&&(i=!0);var r=n.length;this.initialize(r);for(var o=0,s=0;r>3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,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.lengtht.MathHelper.Epsilon?e.divide(new t.Vector2(n)):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis._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 t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),this._timers.removeAt(t))},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 transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((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]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r=0;t--)this._globalManagers[t].enabled&&this._globalManagers[t].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),[4,this._scene.begin()]):[3,2];case 1:e.sent(),e.label=2;case 2:return[4,this.draw()];case 3:return e.sent(),[2]}})})},e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){!function(t){t[t.GraphicsDeviceReset=0]="GraphicsDeviceReset",t[t.SceneChanged=1]="SceneChanged",t[t.OrientationChanged=2]="OrientationChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localScale",{get:function(){return this.transform.localScale},set:function(t){this.transform.setLocalScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene&&(this.scene.entities.markEntityListUnsorted(),this.scene.entities.markTagUnsorted(this.tag)),this},e.prototype.destroy=function(){this._isDestroyed=!0,this.scene.entities.remove(this),this.transform.parent=null;for(var t=this.transform.childCount-1;t>=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateList()},e.prototype.render=function(){if(0!=this._renderers.length)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,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=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(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),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(this._translationMatrix),this.parent||(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),this.parent&&(this._worldTransform=this._localTransform.multiply(this.parent._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)}this._children||(this._children=[]);for(var n=0;n0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e,t.isIUpdatable=function(t){return void 0!==t.js}}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(){function e(){this.updateOrder=0,this._enabled=!0}return Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.onRemovedFromScene=function(){},e.prototype.update=function(){},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled),this},e.prototype.setUpdateOrder=function(e){return this.updateOrder!=e&&(this.updateOrder=e,t.Core.scene._sceneComponents.sort(this.compareTo)),this},e.prototype.compareTo=function(t){return this.updateOrder-t.updateOrder},e}();t.SceneComponent=e}(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){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.LONG_MASK=63,t}();t.BitSet=e}(es||(es={})),function(t){var e=function(){function e(e){this._components=new t.FastList,this._updatableComponents=new t.FastList,this._componentsToAdd=[],this._componentsToRemove=[],this._tempBufferList=[],this._entity=e}return Object.defineProperty(e.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buffer",{get:function(){return this._components.buffer},enumerable:!0,configurable:!0}),e.prototype.markEntityListUnsorted=function(){this._isComponentListUnsorted=!0},e.prototype.add=function(t){this._componentsToAdd.push(t)},e.prototype.remove=function(t){this._componentsToRemove.contains(t)&&console.warn("您正在尝试删除一个您已经删除的组件("+t+")"),this._componentsToAdd.contains(t)?this._componentsToAdd.remove(t):this._componentsToRemove.push(t)},e.prototype.removeAllComponents=function(){for(var t=0;t0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){for(var e=0,n=this._entitiesToRemove;e0;){(i=this._addToSceneEntityList.shift()).onAddedToScene()}if(this._entitiesToAdded.length>0)if(this.frameAllocate&&this._entitiesToAdded.length>this.maxAllocate){for(var r=0;r0;)this.perEntityAddToScene();this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(function(t,e){return t.compareTo(e)}),this._isEntityListUnsorted=!1),0==this._addToSceneEntityList.length&&this._unsortedTags.size>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort(function(t,e){return t.compareTo(e)})}),this._unsortedTags.clear())},e.prototype.perEntityAddToScene=function(){var t=this._entitiesToAdded.shift();this._addToSceneEntityList.push(t),-1==this._entities.findIndex(function(e){return e.id==t.id})&&(this._entities.push(t),t.scene=this.scene,this.addToTagList(t),this.scene.entityProcessors.onEntityAdded(t))},e.prototype.findEntity=function(t){for(var e=0;ethis._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(){function e(t){void 0===t&&(t=5),this.length=0,this.buffer=new Array(t)}return e.prototype.clear=function(){this.buffer.length=0,this.length=0},e.prototype.reset=function(){this.length=0},e.prototype.add=function(t){this.length==this.buffer.length&&(this.buffer.length=Math.max(this.buffer.length<<1,10)),this.buffer[this.length++]=t},e.prototype.remove=function(e){for(var n=t.EqualityComparer.default(),i=0;i=this.length)throw new Error("index超出范围!");this.length--,this.buffer.removeAt(t)},e.prototype.contains=function(e){for(var n=t.EqualityComparer.default(),i=0;i=this.buffer.length&&(this.buffer.length=Math.max(this.buffer.length<<1,this.length+t))},e.prototype.addRange=function(t){for(var e=0,n=t;e=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;i=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=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){var e=(t-this._lastTime)/1e3;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 Math.floor(this._timeSinceSceneLoad/t)>Math.floor((this._timeSinceSceneLoad-this.deltaTime)/t)},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,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,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},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(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;on?n:t},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.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.incrementWithWrap=function(t,e){return++t==e?0:t},e.approach=function(t,e,n){return ti&&(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,c=(this.y-t.start.y)*a,h=(this.y+this.height-t.start.y)*a;if(c>h){var u=c;c=h,h=u}if(e.value=Math.max(c,e.value),n=Math.max(h,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=h>0?l-h:-l-h,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 this.x^this.y^this.width^this.height},e.emptyRectangle=new e,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.floor(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(t,e){this.x=0,this.y=0,this.x=t||0,this.y=null!=e?e:this.x}return Object.defineProperty(e,"zero",{get:function(){return new e(0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return new e(1,1)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return new e(1,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return new e(0,1)},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.normalize=function(t){var n=new e(t.x,t.y),i=1/Math.sqrt(n.x*n.x+n.y*n.y);return n.x*=i,n.y*=i,n},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.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.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.prototype.add=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.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},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.equals=function(t){return t instanceof e&&(t.x==this.x&&t.y==this.y)},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},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.reset=function(){this.collider=null,this.fraction=this.distance=0},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)},e.clear=function(){this._spatialHash.clear()},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.error("An empty results array was passed in. No results will ever be returned.")},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.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.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.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e._hitArray=[new t.RaycastHit],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._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=[],this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds;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++){var a=this.cellAtPosition(o,s,!0);a.firstOrDefault(function(t){return t==e})||a.push(e)}},e.prototype.remove=function(t){for(var e=t.registeredPhysicsBounds,n=this.cellCoords(e.x,e.y),i=this.cellCoords(e.right,e.bottom),r=n.x;r<=i.x;r++)for(var o=n.y;o<=i.y;o++){var s=this.cellAtPosition(r,o);s?s.remove(t):console.log("从不存在碰撞器的单元格中移除碰撞器: ["+t+"]")}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.debugDraw=function(t,e){void 0===e&&(e=1);for(var n=this.gridBounds.x;n<=this.gridBounds.right;n++)for(var i=this.gridBounds.y;i<=this.gridBounds.bottom;i++){var r=this.cellAtPosition(n,i);r&&r.length>0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;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 c=this.cellAtPosition(s,a);if(c)for(var h=function(r){var o=c[r];if(o==n||!t.Flags.isFlagSet(i,o.physicsLayer.value))return"continue";e.intersects(o.bounds)&&(u._tempHashSet.firstOrDefault(function(t){return t==o})||u._tempHashSet.push(o))},u=this,l=0;l=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=new t.Vector2(0,0),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.ShapeCollisions.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,c=t.Vector2.add(s.start,t.Vector2.add(s.direction,new t.Vector2(r.value))),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var u=a+h;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),!0},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.polygonToPolygon=function(e,n,i){for(var r,o=!0,s=e.edgeNormals,a=n.edgeNormals,c=Number.POSITIVE_INFINITY,h=new t.Vector2,u=t.Vector2.subtract(e.position,n.position),l=0;l0&&(o=!1),!o)return!1;(y=Math.abs(y))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=new t.Ref(0),a=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,s,i.normal),c=n.containsPoint(e.position);if(s.value>e.radius*e.radius&&!c)return!1;if(c)r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(s.value)-e.radius));else if(0==s.value)r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var h=Math.sqrt(s.value);r=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(o,a)),new t.Vector2((e.radius-s.value)/h))}return i.minimumTranslationVector=r,i.point=t.Vector2.add(a,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r1)return!1;var l=(h.x*s.y-h.y*s.x)/c;return!(l<0||l>1)&&(o=o.add(e).add(t.Vector2.multiply(new t.Vector2(u),s)),!0)},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divide(t.Vector2.subtract(n,e),new t.Vector2(o)),a=t.Vector2.subtract(e,i.position),c=t.Vector2.dot(a,s),h=t.Vector2.dot(a,a)-i.radius*i.radius;if(h>0&&c>0)return!1;var u=c*c-h;return!(u<0)&&(r.fraction=-c-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(r.fraction),s)),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.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),r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,new t.Vector2(-i.x)),c=new t.Ref(0);return!!(o.rayIntersects(a,c)&&c.value<=1)&&(r.fraction=c.value,r.distance=i.length()*c.value,r.normal=new t.Vector2(-i.x,-i.y),r.normal.normalize(),r.centroid=t.Vector2.add(e.bounds.center,t.Vector2.multiply(i,new t.Vector2(c.value))),!0)},e}();t.ShapeCollisions=e}(es||(es={}));var ArrayUtils=function(){function t(){}return t.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}},t.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},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.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)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.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},t.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},t}();!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=[],c=0;c>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(c++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(c++))),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,c=[],h=0;h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c.push(this._keyStr.charAt(r)),c.push(this._keyStr.charAt(o)),c.push(this._keyStr.charAt(s)),c.push(this._keyStr.charAt(a));return c=c.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>16},set:function(t){this._packedValue=4278255615&this._packedValue|t<<16},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"g",{get:function(){return this._packedValue>>8},set:function(t){this._packedValue=4294902015&this._packedValue|t<<8},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"r",{get:function(){return this._packedValue},set:function(t){this._packedValue=4294967040&this._packedValue|t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"a",{get:function(){return this._packedValue>>24},set:function(t){this._packedValue=16777215&this._packedValue|t<<24},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"packedValue",{get:function(){return this._packedValue},set:function(t){this._packedValue=t},enumerable:!0,configurable:!0}),e.prototype.equals=function(t){return this._packedValue==t._packedValue},e}();t.Color=e}(es||(es={})),function(t){var e=function(){function e(){}return e.oppositeEdge=function(e){switch(e){case t.Edge.bottom:return t.Edge.top;case t.Edge.top:return t.Edge.bottom;case t.Edge.left:return t.Edge.right;case t.Edge.right:return t.Edge.left}},e.isHorizontal=function(e){return e==t.Edge.right||e==t.Edge.left},e.isVertical=function(e){return e==t.Edge.top||e==t.Edge.bottom},e}();t.EdgeExt=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();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.repeat=function(t,e){for(var n=[];e--;)n.push(t);return n},t}();t.Enumerable=e}(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}();t.EqualityComparer=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function t(){}return t.warmCache=function(t){if((t-=this._objectQueue.length)>0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.toNumber=function(t){return null==t?0:Number(t)},t}();t.NumberExtension=e}(es||(es={})),function(t){var e=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}();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.js}}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(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}();!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,r.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}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){return function(t){this.value=t}}();t.Ref=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelNumber=e}(es||(es={})),function(t){var e=function(){function e(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return e.testPointTriangle=function(e,n,i,r){return!(t.Vector2Ext.cross(t.Vector2.subtract(e,n),t.Vector2.subtract(i,n))<0)&&(!(t.Vector2Ext.cross(t.Vector2.subtract(e,i),t.Vector2.subtract(r,i))<0)&&!(t.Vector2Ext.cross(t.Vector2.subtract(e,r),t.Vector2.subtract(n,r))<0))},e.prototype.triangulate=function(n,i){void 0===i&&(i=!0);var r=n.length;this.initialize(r);for(var o=0,s=0;r>3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,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.lengtht.MathHelper.Epsilon?e.divide(new t.Vector2(n)):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis._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 t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),this._timers.removeAt(t))},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/AI/Pathfinding/AStar/AStarPathfinder.ts b/source/src/AI/Pathfinding/AStar/AStarPathfinder.ts deleted file mode 100644 index dc81de3e..00000000 --- a/source/src/AI/Pathfinding/AStar/AStarPathfinder.ts +++ /dev/null @@ -1,110 +0,0 @@ -/// -module es { - /** - * 计算路径给定的IAstarGraph和开始/目标位置 - */ - export class AStarPathfinder { - /** - * 尽可能从开始到目标找到一条路径。如果没有找到路径,则返回null。 - * @param graph - * @param start - * @param goal - */ - public static search(graph: IAstarGraph, start: T, goal: T) { - let foundPath = false; - let cameFrom = new Map(); - cameFrom.set(start, start); - - let costSoFar = new Map(); - let frontier = new PriorityQueue>(1000); - frontier.enqueue(new AStarNode(start), 0); - - costSoFar.set(start, 0); - - while (frontier.count > 0) { - let current = frontier.dequeue(); - - if (current.data instanceof Vector2 && goal instanceof Vector2 && current.data.equals(goal)) { - foundPath = true; - break; - } else if (current.data == goal){ - foundPath = true; - break; - } - - graph.getNeighbors(current.data).forEach(next => { - let newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - let priority = newCost + graph.heuristic(next, goal); - frontier.enqueue(new AStarNode(next), priority); - cameFrom.set(next, current.data); - } - }); - } - - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - } - - /** - * 从cameFrom字典重新构造路径 - * @param cameFrom - * @param start - * @param goal - */ - public static recontructPath(cameFrom: Map, start: T, goal: T): T[] { - let path = []; - let current = goal; - path.push(goal); - - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - - path.reverse(); - - return path; - } - - private static hasKey(map: Map, compareKey: T) { - let iterator = map.keys(); - let r: IteratorResult; - while (r = iterator.next() , !r.done) { - if (r.value instanceof Vector2 && compareKey instanceof Vector2 && r.value.equals(compareKey)) - return true; - else if (r.value == compareKey) - return true; - } - - return false; - } - - private static getKey(map: Map, compareKey: T) { - let iterator = map.keys(); - let valueIterator = map.values(); - let r: IteratorResult; - let v: IteratorResult; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (r.value instanceof Vector2 && compareKey instanceof Vector2 && r.value.equals(compareKey)) - return v.value; - else if (r.value == compareKey) - return v.value; - } - - return null; - } - } - - /** - * 使用PriorityQueue需要的额外字段将原始数据封装在一个小类中 - */ - class AStarNode extends PriorityQueueNode { - public data: T; - - constructor(data: T) { - super(); - this.data = data; - } - } -} diff --git a/source/src/AI/Pathfinding/AStar/AstarGridGraph.ts b/source/src/AI/Pathfinding/AStar/AstarGridGraph.ts deleted file mode 100644 index ea7041eb..00000000 --- a/source/src/AI/Pathfinding/AStar/AstarGridGraph.ts +++ /dev/null @@ -1,74 +0,0 @@ -module es { - /** - * 基本静态网格图与A*一起使用 - * 将walls添加到walls HashSet,并将加权节点添加到weightedNodes - */ - export class AstarGridGraph implements IAstarGraph { - public dirs: Vector2[] = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, 1) - ]; - - public walls: Vector2[] = []; - public weightedNodes: Vector2[] = []; - public defaultWeight: number = 1; - public weightedNodeWeight = 5; - - private _width; - private _height; - private _neighbors: Vector2[] = new Array(4); - - constructor(width: number, height: number) { - this._width = width; - this._height = height; - } - - /** - * 确保节点在网格图的边界内 - * @param node - */ - public isNodeInBounds(node: Vector2): boolean { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - } - - /** - * 检查节点是否可以通过。walls是不可逾越的。 - * @param node - */ - public isNodePassable(node: Vector2): boolean { - return !this.walls.firstOrDefault(wall => wall.equals(node)); - } - - /** - * 调用AStarPathfinder.search的快捷方式 - * @param start - * @param goal - */ - public search(start: Vector2, goal: Vector2) { - return AStarPathfinder.search(this, start, goal); - } - - public getNeighbors(node: Vector2): Vector2[] { - this._neighbors.length = 0; - - this.dirs.forEach(dir => { - let next = new Vector2(node.x + dir.x, node.y + dir.y); - if (this.isNodeInBounds(next) && this.isNodePassable(next)) - this._neighbors.push(next); - }); - - return this._neighbors; - } - - public cost(from: Vector2, to: Vector2): number { - return this.weightedNodes.find((p) => p.equals(to)) ? this.weightedNodeWeight : this.defaultWeight; - } - - public heuristic(node: Vector2, goal: Vector2) { - return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); - } - - } -} diff --git a/source/src/AI/Pathfinding/AStar/IAstarGraph.ts b/source/src/AI/Pathfinding/AStar/IAstarGraph.ts deleted file mode 100644 index 839edb41..00000000 --- a/source/src/AI/Pathfinding/AStar/IAstarGraph.ts +++ /dev/null @@ -1,26 +0,0 @@ -module es { - /** - * graph的接口,可以提供给AstarPathfinder.search方法 - */ - export interface IAstarGraph { - /** - * getNeighbors方法应该返回从传入的节点可以到达的任何相邻节点 - * @param node - */ - getNeighbors(node: T): Array; - - /** - * 计算从从from到to的成本 - * @param from - * @param to - */ - cost(from: T, to: T): number; - - /** - * 计算从node到to的启发式。参见WeightedGridGraph了解常用的Manhatten方法。 - * @param node - * @param goal - */ - heuristic(node: T, goal: T); - } -} diff --git a/source/src/AI/Pathfinding/AStar/PriorityQueue.ts b/source/src/AI/Pathfinding/AStar/PriorityQueue.ts deleted file mode 100644 index ae315fa4..00000000 --- a/source/src/AI/Pathfinding/AStar/PriorityQueue.ts +++ /dev/null @@ -1,236 +0,0 @@ -module es { - /** - * 使用堆实现最小优先级队列 O(1)复杂度 - * 这种查找速度比使用字典快5-10倍 - * 但是,由于IPriorityQueue.contains()是许多寻路算法中调用最多的方法,因此尽可能快地实现它对于我们的应用程序非常重要。 - */ - export class PriorityQueue { - private _numNodes: number; - private _nodes: T[]; - private _numNodesEverEnqueued; - - /** - * 实例化一个新的优先级队列 - * @param maxNodes 允许加入队列的最大节点(执行此操作将导致undefined的行为) - */ - constructor(maxNodes: number) { - this._numNodes = 0; - this._nodes = new Array(maxNodes + 1); - this._numNodesEverEnqueued = 0; - } - - /** - * 返回队列中的节点数。 - * O(1)复杂度 - */ - public get count() { - return this._numNodes; - } - - /** - * 返回可同时进入此队列的最大项数。一旦你达到这个数字(即。一旦Count == MaxSize),尝试加入另一个项目将导致undefined的行为 - * O(1)复杂度 - */ - public get maxSize() { - return this._nodes.length - 1; - } - - /** - * 从队列中删除每个节点。 - * O(n)复杂度 所有尽可能少调用该方法 - */ - public clear() { - this._nodes.splice(1, this._numNodes); - this._numNodes = 0; - } - - /** - * 返回(在O(1)中)给定节点是否在队列中 - * O (1)复杂度 - * @param node - */ - public contains(node: T): boolean { - if (!node) { - console.error("node cannot be null"); - return false; - } - - if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length) { - console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); - return false; - } - - return (this._nodes[node.queueIndex] == node); - } - - /** - * 将节点放入优先队列 较低的值放在前面 先入先出 - * 如果队列已满,则结果undefined。如果节点已经加入队列,则结果undefined。 - * O(log n) - * @param node - * @param priority - */ - public enqueue(node: T, priority: number) { - node.priority = priority; - this._numNodes++; - this._nodes[this._numNodes] = node; - node.queueIndex = this._numNodes; - node.insertionIndex = this._numNodesEverEnqueued++; - this.cascadeUp(this._nodes[this._numNodes]); - } - - /** - * 删除队列头(具有最小优先级的节点;按插入顺序断开连接),并返回它。如果队列为空,结果undefined - * O(log n) - */ - public dequeue(): T { - let returnMe = this._nodes[1]; - this.remove(returnMe); - return returnMe; - } - - /** - * 从队列中删除一个节点。节点不需要是队列的头。如果节点不在队列中,则结果未定义。如果不确定,首先检查Contains() - * O(log n) - * @param node - */ - public remove(node: T) { - if (node.queueIndex == this._numNodes) { - this._nodes[this._numNodes] = null; - this._numNodes--; - return; - } - - let formerLastNode = this._nodes[this._numNodes]; - this.swap(node, formerLastNode); - delete this._nodes[this._numNodes]; - this._numNodes--; - - this.onNodeUpdated(formerLastNode); - } - - /** - * 检查以确保队列仍然处于有效状态。用于测试/调试队列。 - */ - public isValidQueue(): boolean { - for (let i = 1; i < this._nodes.length; i++) { - if (this._nodes[i]) { - let childLeftIndex = 2 * i; - if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && - this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) - return false; - - let childRightIndex = childLeftIndex + 1; - if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && - this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) - return false; - } - } - - return true; - } - - private onNodeUpdated(node: T) { - // 将更新后的节点按适当的方式向上或向下冒泡 - let parentIndex = Math.floor(node.queueIndex / 2); - let parentNode = this._nodes[parentIndex]; - - if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { - this.cascadeUp(node); - } else { - // 注意,如果parentNode == node(即节点是根),则将调用CascadeDown。 - this.cascadeDown(node); - } - } - - private cascadeDown(node: T) { - // 又名Heapify-down - let newParent: T; - let finalQueueIndex = node.queueIndex; - while (true) { - newParent = node; - let childLeftIndex = 2 * finalQueueIndex; - - // 检查左子节点的优先级是否高于当前节点 - if (childLeftIndex > this._numNodes) { - // 这可以放在循环之外,但是我们必须检查newParent != node两次 - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - - let childLeft = this._nodes[childLeftIndex]; - if (this.hasHigherPriority(childLeft, newParent)) { - newParent = childLeft; - } - - // 检查右子节点的优先级是否高于当前节点或左子节点 - let childRightIndex = childLeftIndex + 1; - if (childRightIndex <= this._numNodes) { - let childRight = this._nodes[childRightIndex]; - if (this.hasHigherPriority(childRight, newParent)) { - newParent = childRight; - } - } - - // 如果其中一个子节点具有更高(更小)的优先级,则交换并继续级联 - if (newParent != node) { - // 将新的父节点移动到它的新索引 - // 节点将被移动一次,这样做比调用Swap()少一个赋值操作。 - this._nodes[finalQueueIndex] = newParent; - - let temp = newParent.queueIndex; - newParent.queueIndex = finalQueueIndex; - finalQueueIndex = temp; - } else { - // 参见上面的笔记 - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - } - } - - /** - * 当没有内联时,性能会稍微好一些 - * @param node - */ - private cascadeUp(node: T) { - // 又名Heapify-up - let parent = Math.floor(node.queueIndex / 2); - while (parent >= 1) { - let parentNode = this._nodes[parent]; - if (this.hasHigherPriority(parentNode, node)) - break; - - // 节点具有较低的优先级值,因此将其向上移动到堆中 - // 出于某种原因,使用Swap()比使用单独的操作更快,如CascadeDown() - this.swap(node, parentNode); - - parent = Math.floor(node.queueIndex / 2); - } - } - - private swap(node1: T, node2: T) { - // 交换节点 - this._nodes[node1.queueIndex] = node2; - this._nodes[node2.queueIndex] = node1; - - // 交换他们的indicies - let temp = node1.queueIndex; - node1.queueIndex = node2.queueIndex; - node2.queueIndex = temp; - } - - /** - * 如果higher的优先级高于lower,则返回true,否则返回false。 - * 注意,调用HasHigherPriority(节点,节点)(即。两个参数为同一个节点)将返回false - * @param higher - * @param lower - */ - private hasHigherPriority(higher: T, lower: T) { - return (higher.priority < lower.priority || - (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); - } - } -} diff --git a/source/src/AI/Pathfinding/AStar/PriorityQueueNode.ts b/source/src/AI/Pathfinding/AStar/PriorityQueueNode.ts deleted file mode 100644 index 29c86e2c..00000000 --- a/source/src/AI/Pathfinding/AStar/PriorityQueueNode.ts +++ /dev/null @@ -1,16 +0,0 @@ -module es { - export class PriorityQueueNode { - /** - * 插入此节点的优先级。在将节点添加到队列之前必须设置 - */ - public priority: number = 0; - /** - * 由优先级队列使用-不要编辑此值。表示插入节点的顺序 - */ - public insertionIndex: number = 0; - /** - * 由优先级队列使用-不要编辑此值。表示队列中的当前位置 - */ - public queueIndex: number = 0; - } -} diff --git a/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts b/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts deleted file mode 100644 index c352fea3..00000000 --- a/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts +++ /dev/null @@ -1,43 +0,0 @@ -module es { - /** - * 计算路径给定的IUnweightedGraph和开始/目标位置 - */ - export class BreadthFirstPathfinder { - public static search(graph: IUnweightedGraph, start: T, goal: T): T[] { - let foundPath = false; - let frontier = []; - frontier.unshift(start); - - let cameFrom = new Map(); - cameFrom.set(start, start); - - while (frontier.length > 0) { - let current = frontier.shift(); - if (JSON.stringify(current) == JSON.stringify(goal)) { - foundPath = true; - break; - } - - graph.getNeighbors(current).forEach(next => { - if (!this.hasKey(cameFrom, next)) { - frontier.unshift(next); - cameFrom.set(next, current); - } - }); - } - - return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null; - } - - private static hasKey(map: Map, compareKey: T) { - let iterator = map.keys(); - let r: IteratorResult; - while (r = iterator.next() , !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; - } - - return false; - } - } -} diff --git a/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts deleted file mode 100644 index 7e53339c..00000000 --- a/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts +++ /dev/null @@ -1,9 +0,0 @@ -module es { - export interface IUnweightedGraph { - /** - * getNeighbors方法应该返回从传入的节点可以到达的任何相邻节点。 - * @param node - */ - getNeighbors(node: T): T[]; - } -} diff --git a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts deleted file mode 100644 index fb841a61..00000000 --- a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts +++ /dev/null @@ -1,18 +0,0 @@ -module es { - /** - * 一个未加权图的基本实现。所有的边都被缓存。这种类型的图最适合于非基于网格的图。 - * 作为边添加的任何节点都必须在边字典中有一个条目作为键。 - */ - export class UnweightedGraph implements IUnweightedGraph { - public edges: Map = new Map(); - - public addEdgesForNode(node: T, edges: T[]) { - this.edges.set(node, edges); - return this; - } - - public getNeighbors(node: T) { - return this.edges.get(node); - } - } -} diff --git a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts deleted file mode 100644 index e0516a93..00000000 --- a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts +++ /dev/null @@ -1,63 +0,0 @@ -/// -module es { - /** - * 基本的未加权网格图形用于BreadthFirstPathfinder - */ - export class UnweightedGridGraph implements IUnweightedGraph { - private static readonly CARDINAL_DIRS: Vector2[] = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, -1) - ]; - - private static readonly COMPASS_DIRS = [ - new Vector2(1, 0), - new Vector2(1, -1), - new Vector2(0, -1), - new Vector2(-1, -1), - new Vector2(-1, 0), - new Vector2(-1, 1), - new Vector2(0, 1), - new Vector2(1, 1), - ]; - - public walls: Vector2[] = []; - - private _width: number; - private _hegiht: number; - - private _dirs: Vector2[]; - private _neighbors: Vector2[] = new Array(4); - - constructor(width: number, height: number, allowDiagonalSearch: boolean = false) { - this._width = width; - this._hegiht = height; - this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; - } - - public isNodeInBounds(node: Vector2): boolean { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; - } - - public isNodePassable(node: Vector2): boolean { - return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); - } - - public getNeighbors(node: Vector2) { - this._neighbors.length = 0; - - this._dirs.forEach(dir => { - let next = new Vector2(node.x + dir.x, node.y + dir.y); - if (this.isNodeInBounds(next) && this.isNodePassable(next)) - this._neighbors.push(next); - }); - - return this._neighbors; - } - - public search(start: Vector2, goal: Vector2): Vector2[] { - return BreadthFirstPathfinder.search(this, start, goal); - } - } -} diff --git a/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts b/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts deleted file mode 100644 index 60e743ce..00000000 --- a/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts +++ /dev/null @@ -1,16 +0,0 @@ -module es { - export interface IWeightedGraph { - /** - * - * @param node - */ - getNeighbors(node: T): T[]; - - /** - * - * @param from - * @param to - */ - cost(from: T, to: T): number; - } -} diff --git a/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts b/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts deleted file mode 100644 index 3392d5b1..00000000 --- a/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts +++ /dev/null @@ -1,69 +0,0 @@ -/// -module es { - /** - * 支持一种加权节点的基本网格图 - */ - export class WeightedGridGraph implements IWeightedGraph { - public static readonly CARDINAL_DIRS = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, 1) - ]; - - private static readonly COMPASS_DIRS = [ - new Vector2(1, 0), - new Vector2(1, -1), - new Vector2(0, -1), - new Vector2(-1, -1), - new Vector2(-1, 0), - new Vector2(-1, 1), - new Vector2(0, 1), - new Vector2(1, 1), - ]; - - public walls: Vector2[] = []; - public weightedNodes: Vector2[] = []; - public defaultWeight = 1; - public weightedNodeWeight = 5; - - private _width: number; - private _height: number; - private _dirs: Vector2[]; - private _neighbors: Vector2[] = new Array(4); - - constructor(width: number, height: number, allowDiagonalSearch: boolean = false) { - this._width = width; - this._height = height; - this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; - } - - public isNodeInBounds(node: Vector2) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - } - - public isNodePassable(node: Vector2): boolean { - return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); - } - - public search(start: Vector2, goal: Vector2) { - return WeightedPathfinder.search(this, start, goal); - } - - public getNeighbors(node: Vector2): Vector2[] { - this._neighbors.length = 0; - - this._dirs.forEach(dir => { - let next = new Vector2(node.x + dir.x, node.y + dir.y); - if (this.isNodeInBounds(next) && this.isNodePassable(next)) - this._neighbors.push(next); - }); - - return this._neighbors; - } - - public cost(from: Vector2, to: Vector2): number { - return this.weightedNodes.find(t => JSON.stringify(t) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight; - } - } -} diff --git a/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts b/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts deleted file mode 100644 index 0e10e293..00000000 --- a/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts +++ /dev/null @@ -1,85 +0,0 @@ -module es { - export class WeightedNode extends PriorityQueueNode { - public data: T; - - constructor(data: T) { - super(); - this.data = data; - } - } - - export class WeightedPathfinder { - public static search(graph: IWeightedGraph, start: T, goal: T) { - let foundPath = false; - - let cameFrom = new Map(); - cameFrom.set(start, start); - - let costSoFar = new Map(); - let frontier = new PriorityQueue>(1000); - frontier.enqueue(new WeightedNode(start), 0); - - costSoFar.set(start, 0); - - while (frontier.count > 0) { - let current = frontier.dequeue(); - - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - break; - } - - graph.getNeighbors(current.data).forEach(next => { - let newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - let priprity = newCost; - frontier.enqueue(new WeightedNode(next), priprity); - cameFrom.set(next, current.data); - } - }); - } - - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - } - - public static recontructPath(cameFrom: Map, start: T, goal: T): T[] { - let path = []; - let current = goal; - path.push(goal); - - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - - path.reverse(); - - return path; - } - - private static hasKey(map: Map, compareKey: T) { - let iterator = map.keys(); - let r: IteratorResult; - while (r = iterator.next() , !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; - } - - return false; - } - - private static getKey(map: Map, compareKey: T) { - let iterator = map.keys(); - let valueIterator = map.values(); - let r: IteratorResult; - let v: IteratorResult; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return v.value; - } - - return null; - } - } -} diff --git a/source/src/AI/Pathfinding/GOAP/AStar.ts b/source/src/AI/Pathfinding/GOAP/AStar.ts deleted file mode 100644 index c4d26af9..00000000 --- a/source/src/AI/Pathfinding/GOAP/AStar.ts +++ /dev/null @@ -1,200 +0,0 @@ -/// -module es { - export class AStarNode implements IEquatable, IPoolable { - /** - * 这个节点的世界状态 - */ - public worldState: WorldState; - - /** - * 到目前为止的花费 - */ - public costSoFar: number; - - /** - * 剩余成本的启发式(不要高估!) - */ - public heuristicCost: number; - - /** - * costSoFar+heuristicCost(g+h)组合 - */ - public costSoFarAndHeuristicCost: number; - - /** - * 与此节点相关的动作 - */ - public action: Action; - - /** - * 父节点 - */ - public parent: AStarNode; - - /** - * - */ - public parentWorldState: WorldState; - - /** - * - */ - public depth: number; - - /** - * - * @param other - */ - public equals(other: AStarNode): boolean { - let care = this.worldState.dontCare ^ -1; - return (this.worldState.values & care) == (other.worldState.values & care); - } - - public compareTo(other: AStarNode){ - return this.costSoFarAndHeuristicCost - other.costSoFarAndHeuristicCost; - } - - public reset(){ - this.action = null; - this.parent = null; - } - - public clone(): AStarNode{ - let node = new AStarNode(); - node.action = this.action; - node.costSoFar = this.costSoFar; - node.depth = this.depth; - node.parent = this.parent; - node.parentWorldState = this.parentWorldState; - node.heuristicCost = this.heuristicCost; - node.worldState = this.worldState; - return node; - } - - public toString(): string{ - return `[cost: ${this.costSoFar} | heuristic: ${this.heuristicCost}]: ${this.action}`; - } - } - - export class AStar { - public static storage: AStarStorage = new AStarStorage(); - - /** - * 制定达到理想世界状态的行动计划 - * @param ap - * @param start - * @param goal - * @param selectedNodes - */ - public static plan(ap: ActionPlanner, start: WorldState, goal: WorldState, selectedNodes: AStarNode[] = null){ - this.storage.clear(); - - let currentNode = Pool.obtain(AStarNode); - currentNode.worldState = start; - currentNode.parentWorldState = start; - currentNode.costSoFar = 0; - currentNode.heuristicCost = this.calculateHeuristic(start, goal); - currentNode.costSoFarAndHeuristicCost = currentNode.costSoFar + currentNode.heuristicCost; - currentNode.depth = 1; - - this.storage.addToOpenList(currentNode); - - while(true){ - // 无路可走,无路可寻 - if (!this.storage.hasOpened()){ - this.storage.clear(); - return null; - } - - currentNode = this.storage.removeCheapestOpenNode(); - - this.storage.addToClosedList(currentNode); - - // 全部完成。 我们达到了我们的目标 - if (goal.equals(currentNode.worldState)){ - let plan = this.reconstructPlan(currentNode, selectedNodes); - this.storage.clear(); - return plan; - } - - let neighbors = ap.getPossibleTransitions(currentNode.worldState); - for (let i = 0; i < neighbors.length; i++){ - let cur = neighbors[i]; - let opened = this.storage.findOpened(cur); - let closed = this.storage.findClosed(cur); - let cost = currentNode.costSoFar + cur.costSoFar; - - // 如果neighbors处于open状态,且成本小于g(neighbors)。 - if (opened != null && cost < opened.costSoFar){ - // 将neighbors从OPEN中移除,因为新的路径更好。 - this.storage.removeOpened(opened); - opened = null; - } - - // 如果neighbors在CLOSED,且成本小于g(neighbors) - if (closed != null && cost < closed.costSoFar){ - // 从CLOSED中删除neighbors - this.storage.removeClosed(closed); - } - - // 如果neighbors不在OPEN,neighbors不在CLOSED。 - if (opened == null && closed == null){ - let nb = Pool.obtain(AStarNode); - nb.worldState = cur.worldState; - nb.costSoFar = cost; - nb.heuristicCost = this.calculateHeuristic(cur.worldState, goal); - nb.costSoFarAndHeuristicCost = nb.costSoFar + nb.heuristicCost; - nb.action = cur.action; - nb.parentWorldState = currentNode.worldState; - nb.parent = currentNode; - nb.depth = currentNode.depth + 1; - this.storage.addToOpenList(nb); - } - } - - ListPool.free(neighbors); - } - } - - /** - * 内部函数,通过从最后一个节点到初始节点的追踪来重建计划。 - * @param goalNode - * @param selectedNodes - */ - public static reconstructPlan(goalNode: AStarNode, selectedNodes: AStarNode[]){ - let totalActionsInPlan = goalNode.depth - 1; - let plan: Action[] = new Array(totalActionsInPlan); - - let curnode = goalNode; - for (let i = 0; i <= totalActionsInPlan - 1; i ++){ - // 如果我们被传递了一个节点,可以选择将该节点添加到列表中 - if (selectedNodes != null) - selectedNodes.push(curnode.clone()); - plan.push(curnode.action); - curnode = curnode.parent; - } - - // 我们的节点从目标回到了起点,所以把它们反过来。 - if (selectedNodes != null) - selectedNodes.reverse(); - - return plan; - } - - /** - * - * @param fr - * @param to - */ - public static calculateHeuristic(fr: WorldState, to: WorldState){ - let care = (to.dontCare ^ -1); - let diff = (fr.values & care) ^ (to.values & care); - let dist = 0; - - for (let i = 0; i < ActionPlanner.MAX_CONDITIONS; ++i) - if ((diff & (1 << i)) != 0) - dist ++; - return dist; - } - } -} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/GOAP/AStarStorage.ts b/source/src/AI/Pathfinding/GOAP/AStarStorage.ts deleted file mode 100644 index 524a7e54..00000000 --- a/source/src/AI/Pathfinding/GOAP/AStarStorage.ts +++ /dev/null @@ -1,107 +0,0 @@ -module es { - export class AStarStorage { - /** - * 我们可以存储的最大节点数 - */ - public static readonly MAX_NODES = 128; - - public _opened: AStarNode[] = new Array(AStarStorage.MAX_NODES); - public _closed: AStarNode[] = new Array(AStarStorage.MAX_NODES); - public _numOpened: number; - public _numClosed: number; - - public _lastFoundOpened: number; - public _lastFoundClosed: number; - - constructor(){} - - public clear(){ - for (let i = 0; i < this._numOpened; i ++){ - Pool.free(this._opened[i]); - this._opened[i] = null; - } - - for (let i = 0; i < this._numClosed; i ++){ - Pool.free(this._closed[i]); - this._closed[i] = null; - } - - this._numOpened = this._numClosed = 0; - this._lastFoundClosed = this._lastFoundOpened = 0; - } - - public findOpened(node: AStarNode): AStarNode { - for (let i = 0; i < this._numOpened; i ++){ - let care = node.worldState.dontCare ^ -1; - if ((node.worldState.values & care) == (this._opened[i].worldState.values & care)){ - this._lastFoundClosed = i; - return this._closed[i]; - } - } - - return null; - } - - public findClosed(node: AStarNode): AStarNode { - for (let i = 0; i < this._numClosed; i ++){ - let care = node.worldState.dontCare ^ -1; - if ((node.worldState.values & care) == (this._closed[i].worldState.values & care)){ - this._lastFoundClosed = i; - return this._closed[i]; - } - } - - return null; - } - - public hasOpened(): boolean { - return this._numOpened > 0; - } - - public removeOpened(node: AStarNode){ - if (this._numOpened > 0) - this._opened[this._lastFoundOpened] = this._opened[this._numOpened - 1]; - this._numOpened --; - } - - public removeClosed(node: AStarNode) { - if (this._numClosed > 0) - this._closed[this._lastFoundClosed] = this._closed[this._numClosed - 1]; - this._numClosed--; - } - - public isOpen(node: AStarNode): boolean{ - return this._opened.indexOf(node) > -1; - } - - public isClosed(node: AStarNode): boolean { - return this._closed.indexOf(node) > -1; - } - - public addToOpenList(node: AStarNode){ - this._opened[this._numOpened++] = node; - } - - public addToClosedList(node: AStarNode){ - this._closed[this._numClosed++] = node; - } - - /** - * - */ - public removeCheapestOpenNode(): AStarNode { - let lowestVal = Number.MAX_VALUE; - this._lastFoundOpened = -1; - for (let i = 0; i < this._numOpened; i ++){ - if (this._opened[i].costSoFarAndHeuristicCost < lowestVal){ - lowestVal = this._opened[i].costSoFarAndHeuristicCost; - this._lastFoundOpened = i; - } - } - - var val = this._opened[this._lastFoundOpened]; - this.removeOpened(val); - return val; - } - } -} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/GOAP/Action.ts b/source/src/AI/Pathfinding/GOAP/Action.ts deleted file mode 100644 index 1faf5736..00000000 --- a/source/src/AI/Pathfinding/GOAP/Action.ts +++ /dev/null @@ -1,41 +0,0 @@ -module es { - export class Action { - /** - * Action的可选名称。用于调试目的 - */ - public name: string; - - /** - * 执行动作的成本。 改变它将会影响到计划期间的行动/选择。 - */ - public cost: number = 1; - - public _preConditions: Set<[string, boolean]> = new Set<[string, boolean]>(); - public _postConditions: Set<[string, boolean]> = new Set<[string, boolean]>(); - - constructor(name?: string, cost: number = 1){ - this.name = name; - this.cost = cost; - } - - public setPrecondition(conditionName: string, value: boolean){ - this._preConditions.add([conditionName, value]); - } - - public setPostcondition(conditionName: string, value: boolean){ - this._preConditions.add([conditionName, value]); - } - - /** - * 在ActionPlanner进行plan之前调用。让Action有机会设置它的分数,或者在没有用的情况下选择退出。 - * 例如,如果Action是要拿起一把枪,但世界上没有枪,返回false将使Action不被ActionPlanner考虑 - */ - public validate(): boolean{ - return true; - } - - public toString(): string{ - return `[Action] ${this.name} - cost: ${this.cost}`; - } - } -} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/GOAP/ActionPlanner.ts b/source/src/AI/Pathfinding/GOAP/ActionPlanner.ts deleted file mode 100644 index e08bcdaa..00000000 --- a/source/src/AI/Pathfinding/GOAP/ActionPlanner.ts +++ /dev/null @@ -1,129 +0,0 @@ -module es { - export class ActionPlanner { - public static readonly MAX_CONDITIONS: number = 64; - - /** - * 与所有世界状态原子相关的名称 - */ - public conditionNames: string[] = new Array(ActionPlanner.MAX_CONDITIONS); - - public _actions: Action[] = []; - public _viableActions: Action[] = []; - - /** - * 所有行动的前提条件 - */ - public _preConditions: WorldState[] = new Array(ActionPlanner.MAX_CONDITIONS); - - /** - * 所有行动的后置条件(行动效果) - */ - public _postConditions: WorldState[] = new Array(ActionPlanner.MAX_CONDITIONS); - - /** - * 世界状态原子的数量 - */ - public _numConditionNames: number; - - constructor(){ - this._numConditionNames = 0; - for (let i = 0; i < ActionPlanner.MAX_CONDITIONS; ++i){ - this.conditionNames[i] = null; - this._preConditions[i] = WorldState.create(this); - this._postConditions[i] = WorldState.create(this); - } - } - - /** - * 读取世界状态对象的便利方法 - */ - public createWorldState(): WorldState { - return WorldState.create(this); - } - - public addAction(action: Action){ - let actionId = this.findActionIndex(action); - if (actionId == -1) - throw new Error("无法找到或创建行动"); - - action._preConditions.forEach((preCondition)=>{ - let conditionId = this.findConditionNameIndex(preCondition[0]); - if (conditionId == -1) - throw new Error("无法找到或创建条件名称"); - - this._preConditions[actionId].set(conditionId, preCondition[1]); - }); - - action._postConditions.forEach((postCondition)=>{ - let conditionId = this.findConditionNameIndex(postCondition[0]); - if (conditionId == -1) - throw new Error("找不到条件名称"); - - this._postConditions[actionId].set(conditionId, postCondition[1]); - }); - } - - public plan(startState: WorldState, goalState: WorldState, selectedNode = null){ - this._viableActions.length = 0; - for (let i = 0; i < this._actions.length; i++){ - if (this._actions[i].validate()) - this._viableActions.push(this._actions[i]); - } - - return AStar.plan(this, startState, goalState, selectedNode); - } - - public getPossibleTransitions(fr: WorldState){ - let result = ListPool.obtain(); - for (let i = 0; i < this._viableActions.length; ++i){ - let pre = this._preConditions[i]; - let care = (pre.dontCare ^ -1); - let met = ((pre.values & care) == (fr.values & care)); - if (met){ - let node = Pool.obtain(AStarNode); - node.action = this._viableActions[i]; - node.costSoFar = this._viableActions[i].cost; - node.worldState = this.applyPostConditions(this, i, fr); - result.push(node); - } - } - - return result; - } - - public applyPostConditions(ap: ActionPlanner, actionnr: number, fr: WorldState){ - let pst = ap._postConditions[actionnr]; - let unaffected = pst.dontCare; - let affected = (unaffected ^ -1); - - fr.values = (fr.values & unaffected) | (pst.values & affected); - fr.dontCare &= pst.dontCare; - return fr; - } - - public findConditionNameIndex(conditionName: string){ - let idx; - for (idx = 0; idx < this._numConditionNames; ++idx){ - if (this.conditionNames[idx] == conditionName) - return idx; - } - - if (idx < ActionPlanner.MAX_CONDITIONS - 1){ - this.conditionNames[idx] = conditionName; - this._numConditionNames ++; - return idx; - } - - return -1; - } - - public findActionIndex(action: Action): number{ - let idx = this._actions.indexOf(action); - if (idx > -1) - return idx; - - this._actions.push(action); - return this._actions.length - 1; - } - } -} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/GOAP/Agent.ts b/source/src/AI/Pathfinding/GOAP/Agent.ts deleted file mode 100644 index ba35a28a..00000000 --- a/source/src/AI/Pathfinding/GOAP/Agent.ts +++ /dev/null @@ -1,41 +0,0 @@ -module es { - /** - * Agent提供了一个简单明了的方式来使用计划书。 - * 它根本不需要使用,因为它只是ActionPlanner的一个方便的封装器,使其更容易获得计划和存储结果。 - */ - export abstract class Agent { - public actions: Action[]; - public _planner: ActionPlanner; - - constructor(){ - this._planner = new ActionPlanner(); - } - - public plan(debugPlan: boolean = false){ - let nodes: AStarNode[] = null; - if (debugPlan) - nodes = []; - this.actions = this._planner.plan(this.getWorldState(), this.getGoalState(), nodes); - - if (nodes != null && nodes.length > 0){ - console.log("---- ActionPlanner plan ----"); - console.log(`plan cost = ${nodes[nodes.length - 1].costSoFar}`); - console.log(`${" start"}\t${this.getWorldState().describe(this._planner)}`); - for (let i = 0; i < nodes.length; i++){ - console.log(`${i}: ${nodes[i].action.name}\t${nodes[i].worldState.describe(this._planner)}`); - Pool.free(nodes[i]); - } - } - - return this.hasActionPlan(); - } - - public hasActionPlan(){ - return this.actions != null && this.actions.length > 0; - } - - public abstract getWorldState(): WorldState; - - public abstract getGoalState(): WorldState; - } -} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/GOAP/WorldState.ts b/source/src/AI/Pathfinding/GOAP/WorldState.ts deleted file mode 100644 index f76b87a3..00000000 --- a/source/src/AI/Pathfinding/GOAP/WorldState.ts +++ /dev/null @@ -1,80 +0,0 @@ -module es { - export class WorldState implements IEquatable { - /** - * 我们使用条件索引上的位掩码移位来翻转位。 - */ - public values: number; - - /** - * 比特掩码用于明确表示false。 - * 我们需要一个单独的负值存储空间,因为一个值的缺失并不一定意味着它是假的 - */ - public dontCare: number; - - /** - * 是必需的,这样我们就可以从字符串名称中获取条件索引 - */ - public planner: ActionPlanner; - - /** - * - * @param planner - */ - public static create(planner: ActionPlanner): WorldState { - return new WorldState(planner, 0, -1); - } - - /** - * - * @param planner - * @param values - * @param dontcare - */ - constructor(planner: ActionPlanner, values: number, dontcare: number){ - this.planner = planner; - this.values = values; - this.dontCare = dontcare; - } - - public set(conditionId: number | string, value: boolean): boolean { - if (typeof conditionId == "string"){ - return this.set(this.planner.findConditionNameIndex(conditionId), value); - } - - this.values = value ? (this.values | (1 << conditionId)) : (this.values & ~(1 << conditionId)); - this.dontCare ^= (1 << conditionId); - return true; - } - - /** - * - * @param other - */ - public equals(other: WorldState): boolean { - let care = this.dontCare ^ -1; - return (this.values & care) == (other.values & care); - } - - /** - * 用于调试目的。提供一个包含所有前提条件的可读字符串 - * @param planner - */ - public describe(planner: ActionPlanner): string { - let s = ""; - for (let i = 0; i < ActionPlanner.MAX_CONDITIONS; i ++){ - if ((this.dontCare & (1 << i)) == 0){ - let val = planner.conditionNames[i]; - if (val == null) - continue; - - let set = ((this.values & (1 << i)) != 0); - if (s.length > 0) - s += ", "; - s += (set ? val.toUpperCase() : val); - } - } - - return s; - } - } -} \ No newline at end of file diff --git a/source/src/Debug/DebugDefaults.ts b/source/src/Debug/DebugDefaults.ts deleted file mode 100644 index febc8a01..00000000 --- a/source/src/Debug/DebugDefaults.ts +++ /dev/null @@ -1,6 +0,0 @@ -module es { - export class DebugDefaults { - public static verletParticle = 0xDC345E; - public static verletConstraintEdge = 0x433E36; - } -}