diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index ad85ebc9..0b37c123 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -72,6 +72,69 @@ declare class PriorityQueue { private swap; private hasHigherPriority; } +declare class BreadthFirstPathfinder { + static search(graph: IUnweightedGraph, start: T, goal: T): T[]; + private static hasKey; +} +interface IUnweightedGraph { + getNeighbors(node: T): T[]; +} +declare class UnweightedGraph implements IUnweightedGraph { + edges: Map; + addEdgesForNode(node: T, edges: T[]): this; + getNeighbors(node: T): T[]; +} +declare class Point { + x: number; + y: number; + constructor(x: number, y: number); +} +declare class UnweightedGridGraph implements IUnweightedGraph { + private static readonly CARDINAL_DIRS; + private static readonly COMPASS_DIRS; + walls: Point[]; + private _width; + private _hegiht; + private _dirs; + private _neighbors; + constructor(width: number, height: number, allowDiagonalSearch?: boolean); + isNodeInBounds(node: Point): boolean; + isNodePassable(node: Point): boolean; + getNeighbors(node: Point): Point[]; + search(start: Point, goal: Point): Point[]; +} +interface IWeightedGraph { + getNeighbors(node: T): T[]; + cost(from: T, to: T): number; +} +declare class WeightedGridGraph implements IWeightedGraph { + static readonly CARDINAL_DIRS: Point[]; + private static readonly COMPASS_DIRS; + walls: Point[]; + weightedNodes: Point[]; + defaultWeight: number; + weightedNodeWeight: number; + private _width; + private _height; + private _dirs; + private _neighbors; + constructor(width: number, height: number, allowDiagonalSearch?: boolean); + isNodeInBounds(node: Point): boolean; + isNodePassable(node: Point): boolean; + search(start: Point, goal: Point): Point[]; + getNeighbors(node: Point): Point[]; + cost(from: Point, to: Point): number; +} +declare class WeightedNode extends PriorityQueueNode { + data: T; + constructor(data: T); +} +declare class WeightedPathfinder { + static search(graph: IWeightedGraph, start: T, goal: T): T[]; + private static hasKey; + private static getKey; + static recontructPath(cameFrom: Map, start: T, goal: T): T[]; +} declare abstract class Component { entity: Entity; displayRender: egret.DisplayObject; @@ -266,6 +329,7 @@ declare class Mesh extends Component { setVertPosition(positions: Vector2[]): this; setTriangles(triangles: number[]): this; recalculateBounds(): this; + render(): void; } declare class VertexPosition { position: Vector2; @@ -422,11 +486,6 @@ declare class Matrix2D { static createRotation(radians: number, result?: Matrix2D): Matrix2D; static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; } -declare class Point { - x: number; - y: number; - constructor(x: number, y: number); -} declare class Rectangle { x: number; y: number; diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index 3b04efe7..df0ead62 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -343,7 +343,7 @@ var AstarGridGraph = (function () { return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; }; AstarGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.contains(node); + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); }; AstarGridGraph.prototype.search = function (start, goal) { return AStarPathfinder.search(this, start, goal); @@ -494,6 +494,242 @@ var PriorityQueue = (function () { }; return PriorityQueue; }()); +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 ? 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; +}()); +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; +}()); +var Point = (function () { + function Point(x, y) { + this.x = x; + this.y = y; + } + return Point; +}()); +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 Point(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 BreadthFirstPathfinder.search(this, start, goal); + }; + UnweightedGridGraph.CARDINAL_DIRS = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, -1) + ]; + UnweightedGridGraph.COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + return UnweightedGridGraph; +}()); +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 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 Point(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 Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, 1) + ]; + WeightedGridGraph.COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + return WeightedGridGraph; +}()); +var WeightedNode = (function (_super) { + __extends(WeightedNode, _super); + function WeightedNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; + } + return WeightedNode; +}(PriorityQueueNode)); +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 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.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; + }; + 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; + }; + return WeightedPathfinder; +}()); var Component = (function () { function Component() { this._enabled = true; @@ -1403,6 +1639,8 @@ var Mesh = (function (_super) { this._height = max.y - this._topLeftVertPosition.y; return this; }; + Mesh.prototype.render = function () { + }; return Mesh; }(Component)); var VertexPosition = (function () { @@ -2129,13 +2367,6 @@ var Matrix2D = (function () { Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); return Matrix2D; }()); -var Point = (function () { - function Point(x, y) { - this.x = x; - this.y = y; - } - return Point; -}()); var Rectangle = (function () { function Rectangle(x, y, width, height) { this.x = x; diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 0abf54ea..7c8e3a59 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var 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)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var n=0,i=t.length;n-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,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=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,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.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},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,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 o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];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.priority=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var n=t.call(this)||this;return e.stage.addChild(n),n._projectionMatrix=new Matrix2D(0,0,0,0,0,0),n.entityProcessors=new EntityProcessorList,n.entities=new EntityList(n),n.addEventListener(egret.Event.ACTIVATE,n.onActive,n),n.addEventListener(egret.Event.DEACTIVATE,n.onDeactive,n),n.addEventListener(egret.Event.ENTER_FRAME,n.update,n),n}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){var t=this;SceneManager.getActiveScene().entities.buffer.forEach(function(e){return e.components.buffer.forEach(function(e){e.displayRender&&(-1==t.entity.scene.$children.indexOf(e.displayRender)&&t.entity.scene.stage.addChild(e.displayRender))})})},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areMatrixesDirty=!1)},e.prototype.destory=function(){},e}(Component),Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&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<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._lastTime=t},t.timeScale=1,t._lastTime=0,t}(),MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t.map=function(t,e,n,i,o){return i+(t-e)*(o-i)/(n-e)},t.clamp=function(t,e,n){return tn?n:t},t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=o,this.m32=r}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(t,e){var n=t.m11*e.m11+t.m12*e.m21,i=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=n,t.m12=i,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=t.identity);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n,i){return void 0===i&&(i=t.identity),i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=t.identity;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=t.identity),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t._identity=new t(1,0,0,1,0,0),t}(),Point=function(){return function(t,e){this.x=t,this.y=e}}(),Rectangle=function(){return function(t,e,n,i){this.x=t,this.y=e,this.width=n,this.height=i}}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t,this.y=e}return Object.defineProperty(t,"One",{get:function(){return this.unitVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"Zero",{get:function(){return this.zeroVector},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.x+=e.x,t.y+=e.y,t},t.divide=function(t,e){return t.x/=e.x,t.y/=e.y,t},t.multiply=function(t,e){return t.x*=e.x,t.y*=e.y,t},t.subtract=function(t,e){return t.x-=e.x,t.y-=e.y,t},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.zeroVector=new t(0,0),t.unitVector=new t(1,1),t}();!function(t){t[t.center=0]="center",t[t.top=1]="top",t[t.bottom=2]="bottom",t[t.topLeft=9]="topLeft",t[t.topRight=5]="topRight",t[t.left=8]="left",t[t.right=4]="right",t[t.bottomLeft=10]="bottomLeft",t[t.bottomRight=6]="bottomRight"}(PointSectors||(PointSectors={}));var Collisions=function(){function t(){}return t.isLineToLine=function(t,e,n,i){var o=Vector2.subtract(e,t),r=Vector2.subtract(i,n),s=o.x*r.y-o.y*r.x;if(0==s)return!1;var a=Vector2.subtract(n,t),h=(a.x*r.y-a.y*r.x)/s;if(h<0||h>1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,n,i){var o=Vector2.Zero,r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(n,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.length-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,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=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,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.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},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,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 o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];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"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.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},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t,this.y=e}}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.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},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.bind=function(t){return this.displayRender=t,this},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var n=t.call(this)||this;return e.stage.addChild(n),n._projectionMatrix=new Matrix2D(0,0,0,0,0,0),n.entityProcessors=new EntityProcessorList,n.entities=new EntityList(n),n.addEventListener(egret.Event.ACTIVATE,n.onActive,n),n.addEventListener(egret.Event.DEACTIVATE,n.onDeactive,n),n.addEventListener(egret.Event.ENTER_FRAME,n.update,n),n}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){var t=this;SceneManager.getActiveScene().entities.buffer.forEach(function(e){return e.components.buffer.forEach(function(e){e.displayRender&&(-1==t.entity.scene.$children.indexOf(e.displayRender)&&t.entity.scene.stage.addChild(e.displayRender))})})},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areMatrixesDirty=!1)},e.prototype.destory=function(){},e}(Component),Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&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<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._lastTime=t},t.timeScale=1,t._lastTime=0,t}(),MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t.map=function(t,e,n,i,o){return i+(t-e)*(o-i)/(n-e)},t.clamp=function(t,e,n){return tn?n:t},t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=o,this.m32=r}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(t,e){var n=t.m11*e.m11+t.m12*e.m21,i=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=n,t.m12=i,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=t.identity);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n,i){return void 0===i&&(i=t.identity),i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=t.identity;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=t.identity),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){return function(t,e,n,i){this.x=t,this.y=e,this.width=n,this.height=i}}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t,this.y=e}return Object.defineProperty(t,"One",{get:function(){return this.unitVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"Zero",{get:function(){return this.zeroVector},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.x+=e.x,t.y+=e.y,t},t.divide=function(t,e){return t.x/=e.x,t.y/=e.y,t},t.multiply=function(t,e){return t.x*=e.x,t.y*=e.y,t},t.subtract=function(t,e){return t.x-=e.x,t.y-=e.y,t},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.zeroVector=new t(0,0),t.unitVector=new t(1,1),t}();!function(t){t[t.center=0]="center",t[t.top=1]="top",t[t.bottom=2]="bottom",t[t.topLeft=9]="topLeft",t[t.topRight=5]="topRight",t[t.left=8]="left",t[t.right=4]="right",t[t.bottomLeft=10]="bottomLeft",t[t.bottomRight=6]="bottomRight"}(PointSectors||(PointSectors={}));var Collisions=function(){function t(){}return t.isLineToLine=function(t,e,n,i){var o=Vector2.subtract(e,t),r=Vector2.subtract(i,n),s=o.x*r.y-o.y*r.x;if(0==s)return!1;var a=Vector2.subtract(n,t),h=(a.x*r.y-a.y*r.x)/s;if(h<0||h>1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,n,i){var o=Vector2.Zero,r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(n,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.length(); + + graph.addEdgesForNode("a", ["b"]); // a->b + graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d + graph.addEdgesForNode("c", ["a"]); // c->a + graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a + graph.addEdgesForNode("e", ["b"]); // e->b + + // 计算从c到e的路径 + let path = BreadthFirstPathfinder.search(graph, "c", "e"); + console.log(path); + } + + public dijkstraTest(){ + let graph = new WeightedGridGraph(20, 20); + + graph.weightedNodes.push(new Point(3, 3)); + graph.weightedNodes.push(new Point(3, 4)); + graph.weightedNodes.push(new Point(4, 3)); + graph.weightedNodes.push(new Point(4, 4)); + + let path = graph.search(new Point(3, 4), new Point(15, 17)); + console.log(path); } public astarTest(){ diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index ad85ebc9..0b37c123 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -72,6 +72,69 @@ declare class PriorityQueue { private swap; private hasHigherPriority; } +declare class BreadthFirstPathfinder { + static search(graph: IUnweightedGraph, start: T, goal: T): T[]; + private static hasKey; +} +interface IUnweightedGraph { + getNeighbors(node: T): T[]; +} +declare class UnweightedGraph implements IUnweightedGraph { + edges: Map; + addEdgesForNode(node: T, edges: T[]): this; + getNeighbors(node: T): T[]; +} +declare class Point { + x: number; + y: number; + constructor(x: number, y: number); +} +declare class UnweightedGridGraph implements IUnweightedGraph { + private static readonly CARDINAL_DIRS; + private static readonly COMPASS_DIRS; + walls: Point[]; + private _width; + private _hegiht; + private _dirs; + private _neighbors; + constructor(width: number, height: number, allowDiagonalSearch?: boolean); + isNodeInBounds(node: Point): boolean; + isNodePassable(node: Point): boolean; + getNeighbors(node: Point): Point[]; + search(start: Point, goal: Point): Point[]; +} +interface IWeightedGraph { + getNeighbors(node: T): T[]; + cost(from: T, to: T): number; +} +declare class WeightedGridGraph implements IWeightedGraph { + static readonly CARDINAL_DIRS: Point[]; + private static readonly COMPASS_DIRS; + walls: Point[]; + weightedNodes: Point[]; + defaultWeight: number; + weightedNodeWeight: number; + private _width; + private _height; + private _dirs; + private _neighbors; + constructor(width: number, height: number, allowDiagonalSearch?: boolean); + isNodeInBounds(node: Point): boolean; + isNodePassable(node: Point): boolean; + search(start: Point, goal: Point): Point[]; + getNeighbors(node: Point): Point[]; + cost(from: Point, to: Point): number; +} +declare class WeightedNode extends PriorityQueueNode { + data: T; + constructor(data: T); +} +declare class WeightedPathfinder { + static search(graph: IWeightedGraph, start: T, goal: T): T[]; + private static hasKey; + private static getKey; + static recontructPath(cameFrom: Map, start: T, goal: T): T[]; +} declare abstract class Component { entity: Entity; displayRender: egret.DisplayObject; @@ -266,6 +329,7 @@ declare class Mesh extends Component { setVertPosition(positions: Vector2[]): this; setTriangles(triangles: number[]): this; recalculateBounds(): this; + render(): void; } declare class VertexPosition { position: Vector2; @@ -422,11 +486,6 @@ declare class Matrix2D { static createRotation(radians: number, result?: Matrix2D): Matrix2D; static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; } -declare class Point { - x: number; - y: number; - constructor(x: number, y: number); -} declare class Rectangle { x: number; y: number; diff --git a/source/bin/framework.js b/source/bin/framework.js index 3b04efe7..df0ead62 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -343,7 +343,7 @@ var AstarGridGraph = (function () { return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; }; AstarGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.contains(node); + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); }; AstarGridGraph.prototype.search = function (start, goal) { return AStarPathfinder.search(this, start, goal); @@ -494,6 +494,242 @@ var PriorityQueue = (function () { }; return PriorityQueue; }()); +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 ? 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; +}()); +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; +}()); +var Point = (function () { + function Point(x, y) { + this.x = x; + this.y = y; + } + return Point; +}()); +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 Point(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 BreadthFirstPathfinder.search(this, start, goal); + }; + UnweightedGridGraph.CARDINAL_DIRS = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, -1) + ]; + UnweightedGridGraph.COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + return UnweightedGridGraph; +}()); +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 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 Point(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 Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, 1) + ]; + WeightedGridGraph.COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + return WeightedGridGraph; +}()); +var WeightedNode = (function (_super) { + __extends(WeightedNode, _super); + function WeightedNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; + } + return WeightedNode; +}(PriorityQueueNode)); +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 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.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; + }; + 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; + }; + return WeightedPathfinder; +}()); var Component = (function () { function Component() { this._enabled = true; @@ -1403,6 +1639,8 @@ var Mesh = (function (_super) { this._height = max.y - this._topLeftVertPosition.y; return this; }; + Mesh.prototype.render = function () { + }; return Mesh; }(Component)); var VertexPosition = (function () { @@ -2129,13 +2367,6 @@ var Matrix2D = (function () { Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); return Matrix2D; }()); -var Point = (function () { - function Point(x, y) { - this.x = x; - this.y = y; - } - return Point; -}()); var Rectangle = (function () { function Rectangle(x, y, width, height) { this.x = x; diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 0abf54ea..7c8e3a59 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var 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)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var n=0,i=t.length;n-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,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=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,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.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},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,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 o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];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.priority=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var n=t.call(this)||this;return e.stage.addChild(n),n._projectionMatrix=new Matrix2D(0,0,0,0,0,0),n.entityProcessors=new EntityProcessorList,n.entities=new EntityList(n),n.addEventListener(egret.Event.ACTIVATE,n.onActive,n),n.addEventListener(egret.Event.DEACTIVATE,n.onDeactive,n),n.addEventListener(egret.Event.ENTER_FRAME,n.update,n),n}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){var t=this;SceneManager.getActiveScene().entities.buffer.forEach(function(e){return e.components.buffer.forEach(function(e){e.displayRender&&(-1==t.entity.scene.$children.indexOf(e.displayRender)&&t.entity.scene.stage.addChild(e.displayRender))})})},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areMatrixesDirty=!1)},e.prototype.destory=function(){},e}(Component),Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&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<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._lastTime=t},t.timeScale=1,t._lastTime=0,t}(),MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t.map=function(t,e,n,i,o){return i+(t-e)*(o-i)/(n-e)},t.clamp=function(t,e,n){return tn?n:t},t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=o,this.m32=r}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(t,e){var n=t.m11*e.m11+t.m12*e.m21,i=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=n,t.m12=i,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=t.identity);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n,i){return void 0===i&&(i=t.identity),i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=t.identity;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=t.identity),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t._identity=new t(1,0,0,1,0,0),t}(),Point=function(){return function(t,e){this.x=t,this.y=e}}(),Rectangle=function(){return function(t,e,n,i){this.x=t,this.y=e,this.width=n,this.height=i}}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t,this.y=e}return Object.defineProperty(t,"One",{get:function(){return this.unitVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"Zero",{get:function(){return this.zeroVector},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.x+=e.x,t.y+=e.y,t},t.divide=function(t,e){return t.x/=e.x,t.y/=e.y,t},t.multiply=function(t,e){return t.x*=e.x,t.y*=e.y,t},t.subtract=function(t,e){return t.x-=e.x,t.y-=e.y,t},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.zeroVector=new t(0,0),t.unitVector=new t(1,1),t}();!function(t){t[t.center=0]="center",t[t.top=1]="top",t[t.bottom=2]="bottom",t[t.topLeft=9]="topLeft",t[t.topRight=5]="topRight",t[t.left=8]="left",t[t.right=4]="right",t[t.bottomLeft=10]="bottomLeft",t[t.bottomRight=6]="bottomRight"}(PointSectors||(PointSectors={}));var Collisions=function(){function t(){}return t.isLineToLine=function(t,e,n,i){var o=Vector2.subtract(e,t),r=Vector2.subtract(i,n),s=o.x*r.y-o.y*r.x;if(0==s)return!1;var a=Vector2.subtract(n,t),h=(a.x*r.y-a.y*r.x)/s;if(h<0||h>1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,n,i){var o=Vector2.Zero,r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(n,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.length-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,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=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,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.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},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,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 o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];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"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.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},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t,this.y=e}}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.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},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.bind=function(t){return this.displayRender=t,this},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var n=t.call(this)||this;return e.stage.addChild(n),n._projectionMatrix=new Matrix2D(0,0,0,0,0,0),n.entityProcessors=new EntityProcessorList,n.entities=new EntityList(n),n.addEventListener(egret.Event.ACTIVATE,n.onActive,n),n.addEventListener(egret.Event.DEACTIVATE,n.onDeactive,n),n.addEventListener(egret.Event.ENTER_FRAME,n.update,n),n}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){var t=this;SceneManager.getActiveScene().entities.buffer.forEach(function(e){return e.components.buffer.forEach(function(e){e.displayRender&&(-1==t.entity.scene.$children.indexOf(e.displayRender)&&t.entity.scene.stage.addChild(e.displayRender))})})},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areMatrixesDirty=!1)},e.prototype.destory=function(){},e}(Component),Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&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<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._lastTime=t},t.timeScale=1,t._lastTime=0,t}(),MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t.map=function(t,e,n,i,o){return i+(t-e)*(o-i)/(n-e)},t.clamp=function(t,e,n){return tn?n:t},t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=o,this.m32=r}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(t,e){var n=t.m11*e.m11+t.m12*e.m21,i=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=n,t.m12=i,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=t.identity);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n,i){return void 0===i&&(i=t.identity),i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=t.identity;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=t.identity),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){return function(t,e,n,i){this.x=t,this.y=e,this.width=n,this.height=i}}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t,this.y=e}return Object.defineProperty(t,"One",{get:function(){return this.unitVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"Zero",{get:function(){return this.zeroVector},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.x+=e.x,t.y+=e.y,t},t.divide=function(t,e){return t.x/=e.x,t.y/=e.y,t},t.multiply=function(t,e){return t.x*=e.x,t.y*=e.y,t},t.subtract=function(t,e){return t.x-=e.x,t.y-=e.y,t},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.zeroVector=new t(0,0),t.unitVector=new t(1,1),t}();!function(t){t[t.center=0]="center",t[t.top=1]="top",t[t.bottom=2]="bottom",t[t.topLeft=9]="topLeft",t[t.topRight=5]="topRight",t[t.left=8]="left",t[t.right=4]="right",t[t.bottomLeft=10]="bottomLeft",t[t.bottomRight=6]="bottomRight"}(PointSectors||(PointSectors={}));var Collisions=function(){function t(){}return t.isLineToLine=function(t,e,n,i){var o=Vector2.subtract(e,t),r=Vector2.subtract(i,n),s=o.x*r.y-o.y*r.x;if(0==s)return!1;var a=Vector2.subtract(n,t),h=(a.x*r.y-a.y*r.x)/s;if(h<0||h>1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,n,i){var o=Vector2.Zero,r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(n,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.length { * @param node */ public isNodePassable(node: Point): boolean { - return !this.walls.contains(node); + return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); } public search(start: Point, goal: Point){ diff --git a/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts b/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts new file mode 100644 index 00000000..429af42c --- /dev/null +++ b/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts @@ -0,0 +1,41 @@ +/** + * 计算路径给定的IUnweightedGraph和开始/目标位置 + */ +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; + } +} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts new file mode 100644 index 00000000..26a6af36 --- /dev/null +++ b/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts @@ -0,0 +1,7 @@ +interface IUnweightedGraph{ + /** + * getNeighbors方法应该返回从传入的节点可以到达的任何相邻节点。 + * @param node + */ + getNeighbors(node: T): T[]; +} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts new file mode 100644 index 00000000..e37120bc --- /dev/null +++ b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts @@ -0,0 +1,16 @@ +/** + * 一个未加权图的基本实现。所有的边都被缓存。这种类型的图最适合于非基于网格的图。 + * 作为边添加的任何节点都必须在边字典中有一个条目作为键。 + */ +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); + } +} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts new file mode 100644 index 00000000..9715df36 --- /dev/null +++ b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts @@ -0,0 +1,61 @@ +/// +/** + * 基本的未加权网格图形用于BreadthFirstPathfinder + */ +class UnweightedGridGraph implements IUnweightedGraph { + private static readonly CARDINAL_DIRS: Point[] = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, -1) + ]; + + private static readonly COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + + public walls: Point[] = []; + + private _width: number; + private _hegiht: number; + + private _dirs: Point[]; + private _neighbors: Point[] = 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: Point): boolean { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; + } + + public isNodePassable(node: Point): boolean { + return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); + } + + public getNeighbors(node: Point) { + this._neighbors.length = 0; + + this._dirs.forEach(dir => { + let next = new Point(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: Point, goal: Point): Point[] { + return BreadthFirstPathfinder.search(this, start, goal); + } +} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts b/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts new file mode 100644 index 00000000..7ce1e30e --- /dev/null +++ b/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts @@ -0,0 +1,14 @@ +interface IWeightedGraph{ + /** + * + * @param node + */ + getNeighbors(node: T): T[]; + + /** + * + * @param from + * @param to + */ + cost(from: T, to: T): number; +} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts b/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts new file mode 100644 index 00000000..7b289deb --- /dev/null +++ b/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts @@ -0,0 +1,67 @@ +/// +/** + * 支持一种加权节点的基本网格图 + */ +class WeightedGridGraph implements IWeightedGraph { + public static readonly CARDINAL_DIRS = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, 1) + ]; + + private static readonly COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + + public walls: Point[] = []; + public weightedNodes: Point[] = []; + public defaultWeight = 1; + public weightedNodeWeight = 5; + + private _width: number; + private _height: number; + private _dirs: Point[]; + private _neighbors: Point[] = 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: Point){ + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + } + + public isNodePassable(node: Point): boolean { + return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); + } + + public search(start: Point, goal: Point){ + return WeightedPathfinder.search(this, start, goal); + } + + public getNeighbors(node: Point): Point[]{ + this._neighbors.length = 0; + + this._dirs.forEach(dir => { + let next = new Point(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: Point, to: Point): number{ + return this.weightedNodes.find(t => JSON.stringify(t) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight; + } +} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts b/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts new file mode 100644 index 00000000..03cfbc13 --- /dev/null +++ b/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts @@ -0,0 +1,83 @@ +class WeightedNode extends PriorityQueueNode { + public data: T; + + constructor(data: T){ + super(); + this.data = data; + } +} + +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; + } + + 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; + } + + 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; + } +} \ No newline at end of file diff --git a/source/src/ECS/Components/Mesh.ts b/source/src/ECS/Components/Mesh.ts index c91ab0c0..f68d134b 100644 --- a/source/src/ECS/Components/Mesh.ts +++ b/source/src/ECS/Components/Mesh.ts @@ -43,6 +43,9 @@ class Mesh extends Component { return this; } + + public render(){ + } } class VertexPosition{