From a4f1ae351f29a5bfd19ffefd79bd8012b9df8f44 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Mon, 29 Jun 2020 15:41:02 +0800 Subject: [PATCH] =?UTF-8?q?ecs=E9=80=82=E9=85=8Degret?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + demo/index.html | 2 +- demo/libs/framework/framework.d.ts | 81 ++-- demo/libs/framework/framework.js | 431 +++++++----------- demo/libs/framework/framework.min.js | 2 +- demo/src/game/MainScene.ts | 65 ++- source/bin/framework.d.ts | 81 ++-- source/bin/framework.js | 431 +++++++----------- source/bin/framework.min.js | 2 +- source/lib/egret.d.ts | 4 +- source/src/ECS/Component.ts | 6 +- source/src/ECS/Components/Camera.ts | 17 +- source/src/ECS/Components/FollowCamera.ts | 8 +- .../Components/Physics/Colliders/Collider.ts | 6 +- source/src/ECS/Components/Physics/Mover.ts | 2 +- .../src/ECS/Components/RenderableComponent.ts | 8 +- source/src/ECS/Components/SpriteRenderer.ts | 58 +-- source/src/ECS/Entity.ts | 111 +---- source/src/ECS/Scene.ts | 14 +- source/src/ECS/SceneManager.ts | 2 +- source/src/ECS/Utils/ComponentList.ts | 3 + .../src/Graphics/Batcher/GraphicsResource.ts | 3 + source/src/Graphics/GraphicsCapabilities.ts | 33 ++ source/src/Graphics/GraphicsDevice.ts | 10 + .../Renderers/PolygonLight/PolyLight.ts | 2 +- source/src/Graphics/Renderers/Renderer.ts | 5 - source/src/Graphics/Viewport.ts | 34 ++ source/src/Math/Matrix2D.ts | 5 + source/src/Math/Vector3.ts | 11 + source/src/Physics/Shapes/Circle.ts | 10 +- source/src/Physics/Shapes/Polygon.ts | 18 +- source/src/Utils/Vector2Ext.ts | 4 + source/src/Utils/WebGLUtils.ts | 48 -- 33 files changed, 647 insertions(+), 871 deletions(-) create mode 100644 source/src/Graphics/Batcher/GraphicsResource.ts create mode 100644 source/src/Graphics/GraphicsCapabilities.ts create mode 100644 source/src/Graphics/GraphicsDevice.ts create mode 100644 source/src/Graphics/Viewport.ts create mode 100644 source/src/Math/Vector3.ts delete mode 100644 source/src/Utils/WebGLUtils.ts diff --git a/.gitignore b/.gitignore index aa99bf68..8e249491 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /source/node_modules /demo/bin-debug +/demo/bin-release diff --git a/demo/index.html b/demo/index.html index fea0ecce..f740eccf 100644 --- a/demo/index.html +++ b/demo/index.html @@ -77,7 +77,7 @@ * "calculateCanvasScaleFactor": //a function return canvas scale factor * } **/ - egret.runEgret({ renderMode: "webgl", audioType: 0, calculateCanvasScaleFactor:function(context) { + egret.runEgret({ renderMode: "canvas", audioType: 0, calculateCanvasScaleFactor:function(context) { var backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index 048196ad..d5682de4 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -139,11 +139,10 @@ declare class DebugDefaults { static verletParticle: number; static verletConstraintEdge: number; } -declare abstract class Component { +declare abstract class Component extends egret.DisplayObjectContainer { entity: Entity; private _enabled; updateInterval: number; - readonly transform: Transform; enabled: boolean; setEnabled(isEnabled: boolean): this; readonly stage: egret.Stage; @@ -159,37 +158,27 @@ declare abstract class Component { registerComponent(): void; deregisterComponent(): void; } -declare class Entity { +declare class Entity extends egret.DisplayObjectContainer { private static _idGenerator; name: string; readonly id: number; scene: Scene; - readonly transform: Transform; readonly components: ComponentList; private _updateOrder; private _enabled; _isDestoryed: boolean; private _tag; componentBits: BitSet; - parent: Transform; - position: Vector2; - localPosition: Vector2; - rotation: number; - rotationDegrees: number; - localRotation: number; - localRotationDegrees: number; - scale: Vector2; - localScale: Vector2; - readonly worldInverseTransform: Matrix2D; - readonly localToWorldTransform: Matrix2D; - readonly worldToLocalTransform: Matrix2D; readonly isDestoryed: boolean; + position: Vector2; + scale: Vector2; enabled: boolean; setEnabled(isEnabled: boolean): this; tag: number; readonly stage: egret.Stage; constructor(name: string); updateOrder: number; + roundPosition(): void; setUpdateOrder(updateOrder: number): this; setTag(tag: number): Entity; attachToScene(newScene: Scene): void; @@ -206,7 +195,7 @@ declare class Entity { onAddedToScene(): void; onRemovedFromScene(): void; onTransformChanged(comp: ComponentTransform): void; - destory(): void; + destroy(): void; } declare class Scene extends egret.DisplayObjectContainer { camera: Camera; @@ -214,9 +203,6 @@ declare class Scene extends egret.DisplayObjectContainer { readonly renderableComponents: RenderableComponentList; readonly content: ContentManager; enablePostProcessing: boolean; - private _projectionMatrix; - private _transformMatrix; - private _matrixTransformMatrix; private _renderers; private _postProcessors; private _didSceneBegin; @@ -324,14 +310,12 @@ declare class Camera extends Component { private _origin; private _transformMatrix; private _inverseTransformMatrix; - private _projectionMatrix; private _minimumZoom; private _maximumZoom; private _areMatrixesDirty; private _inset; private _bounds; private _areBoundsDirty; - private _isProjectionMatrixDirty; readonly bounds: Rectangle; zoom: number; minimumZoom: number; @@ -432,14 +416,10 @@ declare class Sprite { constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2); } declare class SpriteRenderer extends RenderableComponent { - private _sprite; private _origin; - private _bitmap; - readonly bounds: Rectangle; - sprite: Sprite; - setSprite(sprite: Sprite): SpriteRenderer; origin: Vector2; setOrigin(origin: Vector2): this; + setSprite(sprite: Sprite): void; setColor(color: number): void; isVisibleFromCamera(camera: Camera): boolean; render(camera: Camera): void; @@ -619,6 +599,39 @@ declare class Time { private static _lastTime; static update(currentTime: number): void; } +declare class GraphicsCapabilities { + supportsTextureFilterAnisotropic: boolean; + supportsNonPowerOfTwo: boolean; + supportsDepth24: boolean; + supportsPackedDepthStencil: boolean; + supportsDepthNonLinear: boolean; + supportsTextureMaxLevel: boolean; + supportsS3tc: boolean; + supportsDxt1: boolean; + supportsPvrtc: boolean; + supportsAtitc: boolean; + supportsFramebufferObjectARB: boolean; + initialize(device: GraphicsDevice): void; + private platformInitialize; +} +declare class GraphicsDevice { + private viewport; + graphicsCapabilities: GraphicsCapabilities; + constructor(); +} +declare class Viewport { + private _x; + private _y; + private _width; + private _height; + private _minDepth; + private _maxDepth; + readonly aspectRatio: number; + bounds: Rectangle; + constructor(x: number, y: number, width: number, height: number); +} +declare abstract class GraphicsResource { +} declare class GaussianBlurEffect extends egret.CustomFilter { private static blur_frag; constructor(); @@ -767,6 +780,7 @@ declare class Matrix2D { static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D): Matrix2D; static createRotation(radians: number, result?: Matrix2D): Matrix2D; static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; + toEgretMatrix(): egret.Matrix; } declare class Rectangle { x: number; @@ -823,6 +837,12 @@ declare class Vector2 { static distance(value1: Vector2, value2: Vector2): number; static negate(value: Vector2): Vector2; } +declare class Vector3 { + x: number; + y: number; + z: number; + constructor(x: number, y: number, z: number); +} declare class ColliderTriggerHelper { private _entity; private _activeTriggerIntersections; @@ -1060,10 +1080,5 @@ declare class Vector2Ext { static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void; static transformR(position: Vector2, matrix: Matrix2D): Vector2; static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void; -} -declare class WebGLUtils { - static getWebGL(): WebGLRenderingContext; - static drawUserIndexPrimitives(primitiveType: number, vertexData: T[], vertexOffset: number, numVertices: number, indexData: number[], indexOffset: number, primitiveCount: number): void; - private static getElementCountArray; - static checkGLError(): void; + static round(vec: Vector2): Vector2; } diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index f108b064..899137d6 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -737,18 +737,14 @@ var DebugDefaults = (function () { DebugDefaults.verletConstraintEdge = 0x433E36; return DebugDefaults; }()); -var Component = (function () { +var Component = (function (_super) { + __extends(Component, _super); function Component() { - this._enabled = true; - this.updateInterval = 1; + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._enabled = true; + _this.updateInterval = 1; + return _this; } - Object.defineProperty(Component.prototype, "transform", { - get: function () { - return this.entity.transform; - }, - enumerable: true, - configurable: true - }); Object.defineProperty(Component.prototype, "enabled", { get: function () { return this.entity ? this.entity.enabled && this._enabled : this._enabled; @@ -814,132 +810,45 @@ var Component = (function () { this.entity.scene.entityProcessors.onComponentRemoved(this.entity); }; return Component; -}()); -var Entity = (function () { +}(egret.DisplayObjectContainer)); +var Entity = (function (_super) { + __extends(Entity, _super); function Entity(name) { - this._updateOrder = 0; - this._enabled = true; - this._tag = 0; - this.name = name; - this.transform = new Transform(this); - this.components = new ComponentList(this); - this.id = Entity._idGenerator++; - this.componentBits = new BitSet(); + var _this = _super.call(this) || this; + _this._updateOrder = 0; + _this._enabled = true; + _this._tag = 0; + _this.name = name; + _this.components = new ComponentList(_this); + _this.id = Entity._idGenerator++; + _this.componentBits = new BitSet(); + return _this; } - Object.defineProperty(Entity.prototype, "parent", { + Object.defineProperty(Entity.prototype, "isDestoryed", { get: function () { - return this.transform.parent; - }, - set: function (value) { - this.transform.setParent(value); + return this._isDestoryed; }, enumerable: true, configurable: true }); Object.defineProperty(Entity.prototype, "position", { get: function () { - return this.transform.position; + return new Vector2(this.x, this.y); }, set: function (value) { - this.transform.setPosition(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localPosition", { - get: function () { - return this.transform.localPosition; - }, - set: function (value) { - this.transform.setLocalPosition(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "rotation", { - get: function () { - return this.transform.rotation; - }, - set: function (value) { - this.transform.setRotation(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "rotationDegrees", { - get: function () { - return this.transform.rotationDegrees; - }, - set: function (value) { - this.transform.setRotationDegrees(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localRotation", { - get: function () { - return this.transform.localRotation; - }, - set: function (value) { - this.transform.setLocalRotation(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localRotationDegrees", { - get: function () { - return this.transform.localRotationDegrees; - }, - set: function (value) { - this.transform.setLocalRotationDegrees(value); + this.x = value.x; + this.y = value.y; }, enumerable: true, configurable: true }); Object.defineProperty(Entity.prototype, "scale", { get: function () { - return this.transform.scale; + return new Vector2(this.scaleX, this.scaleY); }, set: function (value) { - this.transform.setScale(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localScale", { - get: function () { - return this.transform.scale; - }, - set: function (value) { - this.transform.setScale(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "worldInverseTransform", { - get: function () { - return this.transform.worldInverseTransform; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localToWorldTransform", { - get: function () { - return this.transform.localToWorldTransform; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "worldToLocalTransform", { - get: function () { - return this.transform.worldToLocalTransform; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "isDestoryed", { - get: function () { - return this._isDestoryed; + this.scaleX = value.x; + this.scaleY = value.y; }, enumerable: true, configurable: true @@ -989,6 +898,9 @@ var Entity = (function () { enumerable: true, configurable: true }); + Entity.prototype.roundPosition = function () { + this.position = Vector2Ext.round(this.position); + }; Entity.prototype.setUpdateOrder = function (updateOrder) { if (this._updateOrder != updateOrder) { this._updateOrder = updateOrder; @@ -1013,19 +925,20 @@ var Entity = (function () { this.scene = newScene; newScene.entities.add(this); this.components.registerAllComponents(); - for (var i = 0; i < this.transform.childCount; i++) { - this.transform.getChild(i).entity.attachToScene(newScene); + for (var i = 0; i < this.numChildren; i++) { + this.getChildAt(i).entity.attachToScene(newScene); } }; Entity.prototype.detachFromScene = function () { this.scene.entities.remove(this); this.components.deregisterAllComponents(); - for (var i = 0; i < this.transform.childCount; i++) - this.transform.getChild(i).entity.detachFromScene(); + for (var i = 0; i < this.numChildren; i++) + this.getChildAt(i).entity.detachFromScene(); }; Entity.prototype.addComponent = function (component) { component.entity = this; this.components.add(component); + this.addChild(component); component.initialize(); return component; }; @@ -1073,17 +986,17 @@ var Entity = (function () { Entity.prototype.onTransformChanged = function (comp) { this.components.onEntityTransformChanged(comp); }; - Entity.prototype.destory = function () { + Entity.prototype.destroy = function () { this._isDestoryed = true; this.scene.entities.remove(this); - this.transform.parent = null; - for (var i = this.transform.childCount - 1; i >= 0; i--) { - var child = this.transform.getChild(i); - child.entity.destory(); + this.removeChildren(); + for (var i = this.numChildren - 1; i >= 0; i--) { + var child = this.getChildAt(i); + child.entity.destroy(); } }; return Entity; -}()); +}(egret.DisplayObjectContainer)); var Scene = (function (_super) { __extends(Scene, _super); function Scene() { @@ -1091,7 +1004,6 @@ var Scene = (function (_super) { _this.enablePostProcessing = true; _this._renderers = []; _this._postProcessors = []; - _this._projectionMatrix = new Matrix2D(0, 0, 0, 0, 0, 0); _this.entityProcessors = new EntityProcessorList(); _this.renderableComponents = new RenderableComponentList(); _this.entities = new EntityList(_this); @@ -1102,19 +1014,20 @@ var Scene = (function (_super) { } Scene.prototype.createEntity = function (name) { var entity = new Entity(name); - entity.transform.position = new Vector2(0, 0); + entity.position = new Vector2(0, 0); return this.addEntity(entity); }; Scene.prototype.addEntity = function (entity) { this.entities.add(entity); entity.scene = this; - for (var i = 0; i < entity.transform.childCount; i++) - this.addEntity(entity.transform.getChild(i).entity); + this.addChild(entity); + for (var i = 0; i < entity.numChildren; i++) + this.addEntity(entity.getChildAt(i).entity); return entity; }; Scene.prototype.destroyAllEntities = function () { for (var i = 0; i < this.entities.count; i++) { - this.entities.buffer[i].destory(); + this.entities.buffer[i].destroy(); } }; Scene.prototype.findEntity = function (name) { @@ -1178,6 +1091,7 @@ var Scene = (function (_super) { this._postProcessors[i].unload(); } this.entities.removeAllEntities(); + this.removeChildren(); Physics.clear(); this.camera.destory(); this.camera = null; @@ -1275,7 +1189,7 @@ var SceneManager = (function () { SceneManager._scene.end(); for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) { var entity = SceneManager._scene.entities.buffer[i]; - entity.destory(); + entity.destroy(); } SceneManager._scene = SceneManager._nextScene; SceneManager._nextScene = null; @@ -1632,14 +1546,12 @@ var Camera = (function (_super) { _this._origin = Vector2.zero; _this._transformMatrix = new Matrix2D(); _this._inverseTransformMatrix = new Matrix2D(); - _this._projectionMatrix = new Matrix2D(); _this._minimumZoom = 0.3; _this._maximumZoom = 3; _this._areMatrixesDirty = true; _this._inset = new CameraInset(); _this._bounds = new Rectangle(); _this._areBoundsDirty = true; - _this._isProjectionMatrixDirty = true; _this.setZoom(0); return _this; } @@ -1651,7 +1563,7 @@ var Camera = (function (_super) { var stage = this.stage; var topLeft = this.screenToWorldPoint(new Vector2(this._inset.left, this._inset.top)); var bottomRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, stage.stageHeight - this._inset.bottom)); - if (this.entity.transform.rotation != 0) { + if (this.entity.rotation != 0) { var topRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, this._inset.top)); var bottomLeft = this.screenToWorldPoint(new Vector2(this._inset.left, stage.stageHeight - this._inset.bottom)); var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); @@ -1723,10 +1635,10 @@ var Camera = (function (_super) { }); Object.defineProperty(Camera.prototype, "position", { get: function () { - return this.entity.transform.position; + return this.entity.position; }, set: function (value) { - this.entity.transform.position = value; + this.entity.position = value; }, enumerable: true, configurable: true @@ -1750,10 +1662,9 @@ var Camera = (function (_super) { configurable: true }); Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { - this._isProjectionMatrixDirty = true; var oldOrigin = this._origin; this.origin = new Vector2(newWidth / 2, newHeight / 2); - this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin)); + this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); }; Camera.prototype.setMinimumZoom = function (minZoom) { if (this._zoom < minZoom) @@ -1782,7 +1693,7 @@ var Camera = (function (_super) { return this; }; Camera.prototype.setPosition = function (position) { - this.entity.transform.setPosition(position); + this.entity.position = position; return this; }; Camera.prototype.forceMatrixUpdate = function () { @@ -1792,12 +1703,12 @@ var Camera = (function (_super) { if (!this._areMatrixesDirty) return; var tempMat; - this._transformMatrix = Matrix2D.createTranslation(-this.entity.transform.position.x, -this.entity.transform.position.y); + this._transformMatrix = Matrix2D.createTranslation(-this.entity.position.x, -this.entity.position.y); if (this._zoom != 1) { tempMat = Matrix2D.createScale(this._zoom, this._zoom); this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat); } - if (this.entity.transform.rotation != 0) { + if (this.entity.rotation != 0) { tempMat = Matrix2D.createRotation(this.entity.rotation); this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat); } @@ -1877,10 +1788,10 @@ var FollowCamera = (function (_super) { if (this._targetEntity) this.updateFollow(); this.camera.position = Vector2.lerp(this.camera.position, Vector2.add(this.camera.position, this._desiredPositionDelta), this.followLerp); - this.camera.entity.transform.roundPosition(); + this.camera.entity.roundPosition(); if (this.mapLockEnabled) { this.camera.position = this.clampToMapSize(this.camera.position); - this.camera.entity.transform.roundPosition(); + this.camera.entity.roundPosition(); } }; FollowCamera.prototype.clampToMapSize = function (position) { @@ -1891,8 +1802,8 @@ var FollowCamera = (function (_super) { FollowCamera.prototype.updateFollow = function () { this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; if (this._cameraStyle == CameraStyle.lockOn) { - var targetX = this._targetEntity.transform.position.x; - var targetY = this._targetEntity.transform.position.y; + var targetX = this._targetEntity.position.x; + var targetY = this._targetEntity.position.y; if (this._worldSpaceDeadZone.x > targetX) this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; else if (this._worldSpaceDeadZone.x < targetX) @@ -2026,11 +1937,7 @@ var RenderableComponent = (function (_super) { }); Object.defineProperty(RenderableComponent.prototype, "bounds", { get: function () { - if (this._areBoundsDirty) { - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0), this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height); - this._areBoundsDirty = false; - } - return this._bounds; + return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height); }, enumerable: true, configurable: true @@ -2084,37 +1991,6 @@ var SpriteRenderer = (function (_super) { function SpriteRenderer() { return _super !== null && _super.apply(this, arguments) || this; } - Object.defineProperty(SpriteRenderer.prototype, "bounds", { - get: function () { - if (this._areBoundsDirty) { - if (this._sprite) { - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.texture2D.textureWidth, this._sprite.texture2D.textureHeight); - this._areBoundsDirty = false; - } - } - return this._bounds; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SpriteRenderer.prototype, "sprite", { - get: function () { - return this._sprite; - }, - set: function (value) { - this.setSprite(value); - }, - enumerable: true, - configurable: true - }); - SpriteRenderer.prototype.setSprite = function (sprite) { - this._sprite = sprite; - if (this._sprite) - this._origin = sprite.origin; - this._bitmap = new egret.Bitmap(sprite.texture2D); - this.scene.addChild(this._bitmap); - return this; - }; Object.defineProperty(SpriteRenderer.prototype, "origin", { get: function () { return this._origin; @@ -2132,6 +2008,10 @@ var SpriteRenderer = (function (_super) { } return this; }; + SpriteRenderer.prototype.setSprite = function (sprite) { + this.removeChildren(); + this.addChild(new egret.Bitmap(sprite.texture2D)); + }; SpriteRenderer.prototype.setColor = function (color) { var colorMatrix = [ 1, 0, 0, 0, 0, @@ -2143,28 +2023,19 @@ var SpriteRenderer = (function (_super) { colorMatrix[6] = Math.floor(color / 256 % 256) / 255; colorMatrix[12] = color % 256 / 255; var colorFilter = new egret.ColorMatrixFilter(colorMatrix); - this._bitmap.filters = [colorFilter]; + this.filters = [colorFilter]; }; SpriteRenderer.prototype.isVisibleFromCamera = function (camera) { var topLeft = camera.screenToWorldPoint(new Vector2(0, 0)); this.isVisible = new Rectangle(topLeft.x, topLeft.y, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); - this._bitmap.visible = this.isVisible; + this.visible = this.isVisible; return this.isVisible; }; SpriteRenderer.prototype.render = function (camera) { - if (!this.sprite) - return; - this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x; - this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y; - this._bitmap.rotation = this.entity.transform.rotation + camera.transform.rotation; - this._bitmap.anchorOffsetX = this._origin.x; - this._bitmap.anchorOffsetY = this._origin.y; - this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x; - this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y; }; SpriteRenderer.prototype.onRemovedFromEntity = function () { - if (this._bitmap) - this.scene.removeChild(this._bitmap); + if (this.parent) + this.parent.removeChild(this); }; return SpriteRenderer; }(RenderableComponent)); @@ -2207,7 +2078,7 @@ var Mover = (function (_super) { return collisionResult; }; Mover.prototype.applyMovement = function (motion) { - this.entity.transform.position = Vector2.add(this.entity.transform.position, motion); + this.entity.position = Vector2.add(this.entity.position, motion); if (this._triggerHelper) this._triggerHelper.update(); }; @@ -2292,13 +2163,13 @@ var Collider = (function (_super) { var renderable = this.entity.getComponent(RenderableComponent); if (renderable) { var renderbaleBounds = renderable.bounds; - var width = renderbaleBounds.width / this.entity.transform.scale.x; - var height = renderbaleBounds.height / this.entity.transform.scale.y; + var width = renderbaleBounds.width / this.entity.scale.x; + var height = renderbaleBounds.height / this.entity.scale.y; if (this instanceof BoxCollider) { var boxCollider = this; boxCollider.width = width; boxCollider.height = height; - this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.transform.position); + this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position); } } } @@ -2672,6 +2543,8 @@ var ComponentList = (function () { } }; ComponentList.prototype.handleRemove = function (component) { + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.remove(component); this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); component.onRemovedFromEntity(); @@ -3004,6 +2877,74 @@ var Time = (function () { Time._lastTime = 0; return Time; }()); +var GraphicsCapabilities = (function () { + function GraphicsCapabilities() { + } + GraphicsCapabilities.prototype.initialize = function (device) { + this.platformInitialize(device); + }; + GraphicsCapabilities.prototype.platformInitialize = function (device) { + var gl = new egret.sys.RenderBuffer().context.getInstance(); + this.supportsNonPowerOfTwo = false; + this.supportsTextureFilterAnisotropic = gl.getExtension("EXT_texture_filter_anisotropic") != null; + this.supportsDepth24 = true; + this.supportsPackedDepthStencil = true; + this.supportsDepthNonLinear = false; + this.supportsTextureMaxLevel = true; + this.supportsS3tc = gl.getExtension("WEBGL_compressed_texture_s3tc") != null || + gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") != null; + this.supportsDxt1 = this.supportsS3tc; + this.supportsPvrtc = false; + this.supportsAtitc = gl.getExtension("WEBGL_compressed_texture_astc") != null; + this.supportsFramebufferObjectARB = false; + }; + return GraphicsCapabilities; +}()); +var GraphicsDevice = (function () { + function GraphicsDevice() { + this.graphicsCapabilities = new GraphicsCapabilities(); + this.graphicsCapabilities.initialize(this); + } + return GraphicsDevice; +}()); +var Viewport = (function () { + function Viewport(x, y, width, height) { + this._x = x; + this._y = y; + this._width = width; + this._height = height; + this._minDepth = 0; + this._maxDepth = 1; + } + Object.defineProperty(Viewport.prototype, "aspectRatio", { + get: function () { + if ((this._height != 0) && (this._width != 0)) + return (this._width / this._height); + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Viewport.prototype, "bounds", { + get: function () { + return new Rectangle(this._x, this._y, this._width, this._height); + }, + set: function (value) { + this._x = value.x; + this._y = value.y; + this._width = value.width; + this._height = value.height; + }, + enumerable: true, + configurable: true + }); + return Viewport; +}()); +var GraphicsResource = (function () { + function GraphicsResource() { + } + return GraphicsResource; +}()); var GaussianBlurEffect = (function (_super) { __extends(GaussianBlurEffect, _super); function GaussianBlurEffect() { @@ -3152,11 +3093,6 @@ var Renderer = (function () { } Renderer.prototype.onAddedToScene = function (scene) { }; Renderer.prototype.beginRender = function (cam) { - cam.transform.updateTransform(); - var entities = SceneManager.scene.entities; - for (var i = 0; i < entities.buffer.length; i++) { - entities.buffer[i].transform.updateTransform(); - } }; Renderer.prototype.unload = function () { }; Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { @@ -3203,7 +3139,7 @@ var PolyLight = (function (_super) { Object.defineProperty(PolyLight.prototype, "bounds", { get: function () { if (this._areBoundsDirty) { - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(this._radius), Vector2.one, 0, this._radius * 2, this._radius * 2); + this._bounds.calculateBounds(this.entity.position, this._localOffset, new Vector2(this._radius), Vector2.one, 0, this._radius * 2, this._radius * 2); this._areBoundsDirty = false; } return this._bounds; @@ -3602,6 +3538,10 @@ var Matrix2D = (function () { result.m32 = 0; return result; }; + Matrix2D.prototype.toEgretMatrix = function () { + var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); + return matrix; + }; Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); return Matrix2D; }()); @@ -3901,6 +3841,14 @@ var Vector2 = (function () { Vector2.zeroVector2 = new Vector2(0, 0); return Vector2; }()); +var Vector3 = (function () { + function Vector3(x, y, z) { + this.x = x; + this.y = y; + this.z = z; + } + return Vector3; +}()); var ColliderTriggerHelper = (function () { function ColliderTriggerHelper(entity) { this._activeTriggerIntersections = []; @@ -4292,28 +4240,28 @@ var Polygon = (function (_super) { var hasUnitScale = true; var tempMat = void 0; var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); - if (collider.entity.transform.scale != Vector2.one) { - tempMat = Matrix2D.createScale(collider.entity.transform.scale.x, collider.entity.transform.scale.y); + if (collider.entity.scale != Vector2.one) { + tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); hasUnitScale = false; - var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.transform.scale); + var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale); this.center = scaledOffset; } - if (collider.entity.transform.rotation != 0) { - tempMat = Matrix2D.createRotation(collider.entity.transform.rotation); + if (collider.entity.rotation != 0) { + tempMat = Matrix2D.createRotation(collider.entity.rotation); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.transform.scale)).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); } tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); - this.isUnrotated = collider.entity.transform.rotation == 0; + this.isUnrotated = collider.entity.rotation == 0; if (collider._isRotationDirty) this._areEdgeNormalsDirty = true; } - this.position = Vector2.add(collider.entity.transform.position, this.center); + this.position = Vector2.add(collider.entity.position, this.center); this.bounds = Rectangle.rectEncompassingPoints(this.points); this.bounds.location = Vector2.add(this.bounds.location, this.position); }; @@ -4382,17 +4330,17 @@ var Circle = (function (_super) { Circle.prototype.recalculateBounds = function (collider) { this.center = collider.localOffset; if (collider.shouldColliderScaleAndRotationWithTransform) { - var scale = collider.entity.transform.scale; + var scale = collider.entity.scale; var hasUnitScale = scale.x == 1 && scale.y == 1; var maxScale = Math.max(scale.x, scale.y); this.radius = this._originalRadius * maxScale; - if (collider.entity.transform.rotation != 0) { + if (collider.entity.rotation != 0) { var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.transform.scale)).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); } } - this.position = Vector2.add(collider.entity.transform.position, this.center); + this.position = Vector2.add(collider.entity.position, this.center); this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); }; Circle.prototype.overlaps = function (other) { @@ -5166,45 +5114,8 @@ var Vector2Ext = (function () { Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); }; + Vector2Ext.round = function (vec) { + return new Vector2(Math.round(vec.x), Math.round(vec.y)); + }; return Vector2Ext; }()); -var WebGLUtils = (function () { - function WebGLUtils() { - } - WebGLUtils.getWebGL = function () { - if (egret.WebGLUtils.checkCanUseWebGL()) - return document.querySelector("canvas").getContext("webgl"); - throw new Error("cannot get webgl"); - }; - WebGLUtils.drawUserIndexPrimitives = function (primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount) { - var GL = this.getWebGL(); - GL.bindBuffer(GL.ARRAY_BUFFER, 0); - this.checkGLError(); - GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0); - this.checkGLError(); - GL.drawElements(primitiveType, this.getElementCountArray(primitiveType, primitiveCount), GL.UNSIGNED_SHORT, indexOffset * 2); - this.checkGLError(); - }; - WebGLUtils.getElementCountArray = function (primitiveType, primitiveCount) { - var GL = this.getWebGL(); - switch (primitiveType) { - case GL.LINES: - return primitiveCount * 2; - case GL.LINE_STRIP: - return primitiveCount + 1; - case GL.TRIANGLES: - return primitiveCount * 3; - case GL.TRIANGLE_STRIP: - return primitiveCount + 2; - } - throw new Error("not support"); - }; - WebGLUtils.checkGLError = function () { - var GL = this.getWebGL(); - var error = GL.getError(); - if (error != GL.NO_ERROR) { - throw new Error("GL.GetError() returned" + error); - } - }; - return WebGLUtils; -}()); diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 085e8758..c15671ff 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.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||0,this.y=e||this.x}}(),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}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(t.prototype,"stage",{get:function(){return this.entity?this.entity.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scene",{get:function(){return this.entity?this.entity.scene:null},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},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(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e._projectionMatrix=new Matrix2D(0,0,0,0,0,0),e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}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;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(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.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.forceMatrixUpdate=function(){this._areMatrixesDirty=!0},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)),0!=this.entity.transform.rotation&&(t=Matrix2D.createRotation(this.entity.rotation),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._transformMatrix)},e.prototype.onEntityTransformChanged=function(t){this._areMatrixesDirty=!0},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){this.left=0,this.right=0,this.top=0,this.bottom=0}}(),FollowCamera=function(t){function e(e,n){void 0===n&&(n=CameraStyle.lockOn);var i=t.call(this)||this;return i.followLerp=.1,i.deadzone=new Rectangle,i.focusOffset=new Vector2,i.mapSize=new Vector2,i._worldSpaceDeadZone=new Rectangle,i._desiredPositionDelta=new Vector2,i._targetEntity=e,i._cameraStyle=n,i.camera=null,i}return __extends(e,t),e.prototype.onAddedToEntity=function(){this.camera||(this.camera=this.entity.scene.camera),this.follow(this._targetEntity,this._cameraStyle)},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this._targetEntity=t,this._cameraStyle=e;var n=this.camera.bounds;switch(this._cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=Vector2.multiply(this.camera.bounds.size,new Vector2(.5));this._worldSpaceDeadZone.x=this.camera.position.x-t.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.camera.position.y-t.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.camera.position=Vector2.lerp(this.camera.position,Vector2.add(this.camera.position,this._desiredPositionDelta),this.followLerp),this.camera.entity.transform.roundPosition(),this.mapLockEnabled&&(this.camera.position=this.clampToMapSize(this.camera.position),this.camera.entity.transform.roundPosition())},e.prototype.clampToMapSize=function(t){var e=Vector2.multiply(new Vector2(this.camera.bounds.width,this.camera.bounds.height),new Vector2(.5)),n=new Vector2(this.mapSize.x-e.x,this.mapSize.y-e.y);return Vector2.clamp(t,e,n)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==CameraStyle.lockOn){var t=this._targetEntity.transform.position.x,e=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this._targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var PointSectors,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.contains(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}(),RenderableComponentList=function(){function t(){this._components=[]}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._components.push(t)},t.prototype.remove=function(t){this._components.remove(t)},t.prototype.updateList=function(){},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enable=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),BloomSettings=function(){function t(t,e,n,i,o,r){this.threshold=t,this.blurAmount=e,this.intensity=n,this.baseIntensity=i,this.saturation=o,this.baseStaturation=r}return t.presetSettings=[new t(.1,.6,2,1,1,0),new t(0,3,1,1,1,1),new t(.5,8,2,1,0,1),new t(.25,8,1.3,1,1,0),new t(0,2,1,.1,1,1),new t(.5,2,1,1,1,1)],t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){t.transform.updateTransform();for(var e=SceneManager.scene.entities,n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,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||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}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(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,h=e.m31*n.m11+e.m32*n.m21+n.m31,c=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=h,i.m32=c,i},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=new t);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(i=i||new t).m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=new t;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=new t),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(){function t(t,e,n,i){this.x=t||0,this.y=e||0,this.width=n||0,this.height=i||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,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.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),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}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(y=Math.abs(y))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/c))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.load=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},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.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var i=t.findIndex(e);return-1==i?null:t[i]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;nr?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"stage",{get:function(){return this.entity?this.entity.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scene",{get:function(){return this.entity?this.entity.scene:null},enumerable:!0,configurable:!0}),e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(i){var n=t.call(this)||this;return n._updateOrder=0,n._enabled=!0,n._tag=0,n.name=i,n.components=new ComponentList(n),n.id=e._idGenerator++,n.componentBits=new BitSet,n}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.scaleX=t.x,this.scaleY=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer),Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(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.setPosition=function(t){return this.entity.position=t,this},e.prototype.forceMatrixUpdate=function(){this._areMatrixesDirty=!0},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.position.x,-this.entity.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),0!=this.entity.rotation&&(t=Matrix2D.createRotation(this.entity.rotation),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._transformMatrix)},e.prototype.onEntityTransformChanged=function(t){this._areMatrixesDirty=!0},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){this.left=0,this.right=0,this.top=0,this.bottom=0}}(),FollowCamera=function(t){function e(e,i){void 0===i&&(i=CameraStyle.lockOn);var n=t.call(this)||this;return n.followLerp=.1,n.deadzone=new Rectangle,n.focusOffset=new Vector2,n.mapSize=new Vector2,n._worldSpaceDeadZone=new Rectangle,n._desiredPositionDelta=new Vector2,n._targetEntity=e,n._cameraStyle=i,n.camera=null,n}return __extends(e,t),e.prototype.onAddedToEntity=function(){this.camera||(this.camera=this.entity.scene.camera),this.follow(this._targetEntity,this._cameraStyle)},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this._targetEntity=t,this._cameraStyle=e;var i=this.camera.bounds;switch(this._cameraStyle){case CameraStyle.cameraWindow:var n=i.width/6,o=i.height/3;this.deadzone=new Rectangle((i.width-n)/2,(i.height-o)/2,n,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(i.width/2,i.height/2,10,10)}},e.prototype.update=function(){var t=Vector2.multiply(this.camera.bounds.size,new Vector2(.5));this._worldSpaceDeadZone.x=this.camera.position.x-t.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.camera.position.y-t.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.camera.position=Vector2.lerp(this.camera.position,Vector2.add(this.camera.position,this._desiredPositionDelta),this.followLerp),this.camera.entity.roundPosition(),this.mapLockEnabled&&(this.camera.position=this.clampToMapSize(this.camera.position),this.camera.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=Vector2.multiply(new Vector2(this.camera.bounds.width,this.camera.bounds.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-e.x,this.mapSize.y-e.y);return Vector2.clamp(t,e,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==CameraStyle.lockOn){var t=this._targetEntity.position.x,e=this._targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(Collider),!this._targetCollider))return;var i=this._targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(i)||(this._worldSpaceDeadZone.left>i.left?this._desiredPositionDelta.x=i.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.righti.top&&(this._desiredPositionDelta.y=i.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var PointSectors,Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,i=1<>6;this.ensure(i),this._bits[i]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(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}(),RenderableComponentList=function(){function t(){this._components=[]}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._components.push(t)},t.prototype.remove=function(t){this._components.remove(t)},t.prototype.updateList=function(){},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),GraphicsCapabilities=function(){function t(){}return t.prototype.initialize=function(t){this.platformInitialize(t)},t.prototype.platformInitialize=function(t){var e=(new egret.sys.RenderBuffer).context.getInstance();this.supportsNonPowerOfTwo=!1,this.supportsTextureFilterAnisotropic=null!=e.getExtension("EXT_texture_filter_anisotropic"),this.supportsDepth24=!0,this.supportsPackedDepthStencil=!0,this.supportsDepthNonLinear=!1,this.supportsTextureMaxLevel=!0,this.supportsS3tc=null!=e.getExtension("WEBGL_compressed_texture_s3tc")||null!=e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),this.supportsDxt1=this.supportsS3tc,this.supportsPvrtc=!1,this.supportsAtitc=null!=e.getExtension("WEBGL_compressed_texture_astc"),this.supportsFramebufferObjectARB=!1},t}(),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,i,n){this._x=t,this._y=e,this._width=i,this._height=n,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GraphicsResource=function(){return function(){}}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enable=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),BloomSettings=function(){function t(t,e,i,n,o,r){this.threshold=t,this.blurAmount=e,this.intensity=i,this.baseIntensity=n,this.saturation=o,this.baseStaturation=r}return t.presetSettings=[new t(.1,.6,2,1,1,0),new t(0,3,1,1,1,1),new t(.5,8,2,1,0,1),new t(.25,8,1.3,1,1,0),new t(0,2,1,.1,1,1),new t(.5,2,1,1,1,1)],t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var i=0;ii?i:t},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=i||0,this.m22=n||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,i){var n=new t,o=e.m11*i.m11+e.m12*i.m21,r=e.m11*i.m12+e.m12*i.m22,s=e.m21*i.m11+e.m22*i.m21,a=e.m21*i.m12+e.m22*i.m22,h=e.m31*i.m11+e.m32*i.m21+i.m31,c=e.m31*i.m12+e.m32*i.m22+i.m32;return n.m11=o,n.m12=r,n.m21=s,n.m22=a,n.m31=h,n.m32=c,n},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=new t);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return(n=n||new t).m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=new t;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=new t),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.leftn&&(n=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,i,n,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,n},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,n},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.clamp=function(e,i,n){return new t(MathHelper.clamp(e.x,i.x,n.x),MathHelper.clamp(e.y,i.y,n.y))},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),Vector3=function(){return function(t,e,i){this.x=t,this.y=e,this.z=i}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))=t&&o.y>=e&&o.x=t+i&&(r|=PointSectors.right),o.y=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,i){var n=t.call(this)||this;return n.isUnrotated=!0,n._areEdgeNormalsDirty=!0,n.setPoints(e),n.isBox=i,n}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var i=0;i=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n0&&(o=!1),!o)return null;(y=Math.abs(y))n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/c))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n=0?t:4294967296+t},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.load=function(t,e){var i=this;return void 0===e&&(e=!0),new Promise(function(n,o){var r=i.loadedAssets.get(t);r?n(r):e?RES.getResAsync(t).then(function(e){i.loadedAssets.set(t,e),n(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){i.loadedAssets.set(t,e),n(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,i,n,o,r){for(var s=0;s{ + public onStart() { + this.content.load("http://www.hyuan.org/123.jpeg", false).then((data) => { console.log(data); + let bgSprite = new Sprite(data); + let bg = this.createEntity("bg"); + bg.position = new Vector2(0, 0); + bg.addComponent(new SpriteRenderer()).setSprite(bgSprite); + + for (let i = 0; i < 20; i++) { + let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); + let player2 = this.createEntity("player2"); + player2.addComponent(new SpriteRenderer()).setSprite(sprite); + player2.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i); + player2.addComponent(new BoxCollider()); + } + + let button = new eui.Button(); + button.label = "切换场景"; + this.addChild(button); + button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { + SceneManager.startSceneTransition(new FadeTransition(() => { + return new MainScene(); + })); + }, this); }); - - this.camera.setZoom(0.5); - - let bgSprite = new Sprite(RES.getRes("bg_jpg")); - let bg = this.createEntity("bg"); - bg.position = new Vector2(0, 0); - bg.addComponent(new SpriteRenderer()).setSprite(bgSprite); - - for (let i = 0; i < 20; i ++){ - let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); - let player2 = this.createEntity("player2"); - player2.addComponent(new SpriteRenderer()).setSprite(sprite); - player2.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i); - player2.addComponent(new BoxCollider()); - } - - let button = new eui.Button(); - button.label = "切换场景"; - this.addChild(button); - button.addEventListener(egret.TouchEvent.TOUCH_TAP, ()=>{ - SceneManager.startSceneTransition(new WindTransition(()=>{ - return new MainScene(); - })); - }, this); - - let cancel = new eui.Button(); - cancel.label = "打开高斯模糊"; - cancel.y = 100; - this.addChild(cancel); - cancel.addEventListener(egret.TouchEvent.TOUCH_TAP, ()=>{ - this.addPostProcessor(new GaussianBlurPostProcessor()); - }, this); } - public breadthfirstTest(){ + public breadthfirstTest() { let graph = new UnweightedGraph(); graph.addEdgesForNode("a", ["b"]); // a->b @@ -60,7 +49,7 @@ class MainScene extends Scene { console.log(path); } - public dijkstraTest(){ + public dijkstraTest() { let graph = new WeightedGridGraph(20, 20); graph.weightedNodes.push(new Point(3, 3)); @@ -72,7 +61,7 @@ class MainScene extends Scene { console.log(path); } - public astarTest(){ + public astarTest() { let graph = new AstarGridGraph(20, 20); graph.weightedNodes.push(new Point(3, 3)); diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 048196ad..d5682de4 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -139,11 +139,10 @@ declare class DebugDefaults { static verletParticle: number; static verletConstraintEdge: number; } -declare abstract class Component { +declare abstract class Component extends egret.DisplayObjectContainer { entity: Entity; private _enabled; updateInterval: number; - readonly transform: Transform; enabled: boolean; setEnabled(isEnabled: boolean): this; readonly stage: egret.Stage; @@ -159,37 +158,27 @@ declare abstract class Component { registerComponent(): void; deregisterComponent(): void; } -declare class Entity { +declare class Entity extends egret.DisplayObjectContainer { private static _idGenerator; name: string; readonly id: number; scene: Scene; - readonly transform: Transform; readonly components: ComponentList; private _updateOrder; private _enabled; _isDestoryed: boolean; private _tag; componentBits: BitSet; - parent: Transform; - position: Vector2; - localPosition: Vector2; - rotation: number; - rotationDegrees: number; - localRotation: number; - localRotationDegrees: number; - scale: Vector2; - localScale: Vector2; - readonly worldInverseTransform: Matrix2D; - readonly localToWorldTransform: Matrix2D; - readonly worldToLocalTransform: Matrix2D; readonly isDestoryed: boolean; + position: Vector2; + scale: Vector2; enabled: boolean; setEnabled(isEnabled: boolean): this; tag: number; readonly stage: egret.Stage; constructor(name: string); updateOrder: number; + roundPosition(): void; setUpdateOrder(updateOrder: number): this; setTag(tag: number): Entity; attachToScene(newScene: Scene): void; @@ -206,7 +195,7 @@ declare class Entity { onAddedToScene(): void; onRemovedFromScene(): void; onTransformChanged(comp: ComponentTransform): void; - destory(): void; + destroy(): void; } declare class Scene extends egret.DisplayObjectContainer { camera: Camera; @@ -214,9 +203,6 @@ declare class Scene extends egret.DisplayObjectContainer { readonly renderableComponents: RenderableComponentList; readonly content: ContentManager; enablePostProcessing: boolean; - private _projectionMatrix; - private _transformMatrix; - private _matrixTransformMatrix; private _renderers; private _postProcessors; private _didSceneBegin; @@ -324,14 +310,12 @@ declare class Camera extends Component { private _origin; private _transformMatrix; private _inverseTransformMatrix; - private _projectionMatrix; private _minimumZoom; private _maximumZoom; private _areMatrixesDirty; private _inset; private _bounds; private _areBoundsDirty; - private _isProjectionMatrixDirty; readonly bounds: Rectangle; zoom: number; minimumZoom: number; @@ -432,14 +416,10 @@ declare class Sprite { constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2); } declare class SpriteRenderer extends RenderableComponent { - private _sprite; private _origin; - private _bitmap; - readonly bounds: Rectangle; - sprite: Sprite; - setSprite(sprite: Sprite): SpriteRenderer; origin: Vector2; setOrigin(origin: Vector2): this; + setSprite(sprite: Sprite): void; setColor(color: number): void; isVisibleFromCamera(camera: Camera): boolean; render(camera: Camera): void; @@ -619,6 +599,39 @@ declare class Time { private static _lastTime; static update(currentTime: number): void; } +declare class GraphicsCapabilities { + supportsTextureFilterAnisotropic: boolean; + supportsNonPowerOfTwo: boolean; + supportsDepth24: boolean; + supportsPackedDepthStencil: boolean; + supportsDepthNonLinear: boolean; + supportsTextureMaxLevel: boolean; + supportsS3tc: boolean; + supportsDxt1: boolean; + supportsPvrtc: boolean; + supportsAtitc: boolean; + supportsFramebufferObjectARB: boolean; + initialize(device: GraphicsDevice): void; + private platformInitialize; +} +declare class GraphicsDevice { + private viewport; + graphicsCapabilities: GraphicsCapabilities; + constructor(); +} +declare class Viewport { + private _x; + private _y; + private _width; + private _height; + private _minDepth; + private _maxDepth; + readonly aspectRatio: number; + bounds: Rectangle; + constructor(x: number, y: number, width: number, height: number); +} +declare abstract class GraphicsResource { +} declare class GaussianBlurEffect extends egret.CustomFilter { private static blur_frag; constructor(); @@ -767,6 +780,7 @@ declare class Matrix2D { static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D): Matrix2D; static createRotation(radians: number, result?: Matrix2D): Matrix2D; static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; + toEgretMatrix(): egret.Matrix; } declare class Rectangle { x: number; @@ -823,6 +837,12 @@ declare class Vector2 { static distance(value1: Vector2, value2: Vector2): number; static negate(value: Vector2): Vector2; } +declare class Vector3 { + x: number; + y: number; + z: number; + constructor(x: number, y: number, z: number); +} declare class ColliderTriggerHelper { private _entity; private _activeTriggerIntersections; @@ -1060,10 +1080,5 @@ declare class Vector2Ext { static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void; static transformR(position: Vector2, matrix: Matrix2D): Vector2; static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void; -} -declare class WebGLUtils { - static getWebGL(): WebGLRenderingContext; - static drawUserIndexPrimitives(primitiveType: number, vertexData: T[], vertexOffset: number, numVertices: number, indexData: number[], indexOffset: number, primitiveCount: number): void; - private static getElementCountArray; - static checkGLError(): void; + static round(vec: Vector2): Vector2; } diff --git a/source/bin/framework.js b/source/bin/framework.js index f108b064..899137d6 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -737,18 +737,14 @@ var DebugDefaults = (function () { DebugDefaults.verletConstraintEdge = 0x433E36; return DebugDefaults; }()); -var Component = (function () { +var Component = (function (_super) { + __extends(Component, _super); function Component() { - this._enabled = true; - this.updateInterval = 1; + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._enabled = true; + _this.updateInterval = 1; + return _this; } - Object.defineProperty(Component.prototype, "transform", { - get: function () { - return this.entity.transform; - }, - enumerable: true, - configurable: true - }); Object.defineProperty(Component.prototype, "enabled", { get: function () { return this.entity ? this.entity.enabled && this._enabled : this._enabled; @@ -814,132 +810,45 @@ var Component = (function () { this.entity.scene.entityProcessors.onComponentRemoved(this.entity); }; return Component; -}()); -var Entity = (function () { +}(egret.DisplayObjectContainer)); +var Entity = (function (_super) { + __extends(Entity, _super); function Entity(name) { - this._updateOrder = 0; - this._enabled = true; - this._tag = 0; - this.name = name; - this.transform = new Transform(this); - this.components = new ComponentList(this); - this.id = Entity._idGenerator++; - this.componentBits = new BitSet(); + var _this = _super.call(this) || this; + _this._updateOrder = 0; + _this._enabled = true; + _this._tag = 0; + _this.name = name; + _this.components = new ComponentList(_this); + _this.id = Entity._idGenerator++; + _this.componentBits = new BitSet(); + return _this; } - Object.defineProperty(Entity.prototype, "parent", { + Object.defineProperty(Entity.prototype, "isDestoryed", { get: function () { - return this.transform.parent; - }, - set: function (value) { - this.transform.setParent(value); + return this._isDestoryed; }, enumerable: true, configurable: true }); Object.defineProperty(Entity.prototype, "position", { get: function () { - return this.transform.position; + return new Vector2(this.x, this.y); }, set: function (value) { - this.transform.setPosition(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localPosition", { - get: function () { - return this.transform.localPosition; - }, - set: function (value) { - this.transform.setLocalPosition(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "rotation", { - get: function () { - return this.transform.rotation; - }, - set: function (value) { - this.transform.setRotation(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "rotationDegrees", { - get: function () { - return this.transform.rotationDegrees; - }, - set: function (value) { - this.transform.setRotationDegrees(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localRotation", { - get: function () { - return this.transform.localRotation; - }, - set: function (value) { - this.transform.setLocalRotation(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localRotationDegrees", { - get: function () { - return this.transform.localRotationDegrees; - }, - set: function (value) { - this.transform.setLocalRotationDegrees(value); + this.x = value.x; + this.y = value.y; }, enumerable: true, configurable: true }); Object.defineProperty(Entity.prototype, "scale", { get: function () { - return this.transform.scale; + return new Vector2(this.scaleX, this.scaleY); }, set: function (value) { - this.transform.setScale(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localScale", { - get: function () { - return this.transform.scale; - }, - set: function (value) { - this.transform.setScale(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "worldInverseTransform", { - get: function () { - return this.transform.worldInverseTransform; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "localToWorldTransform", { - get: function () { - return this.transform.localToWorldTransform; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "worldToLocalTransform", { - get: function () { - return this.transform.worldToLocalTransform; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "isDestoryed", { - get: function () { - return this._isDestoryed; + this.scaleX = value.x; + this.scaleY = value.y; }, enumerable: true, configurable: true @@ -989,6 +898,9 @@ var Entity = (function () { enumerable: true, configurable: true }); + Entity.prototype.roundPosition = function () { + this.position = Vector2Ext.round(this.position); + }; Entity.prototype.setUpdateOrder = function (updateOrder) { if (this._updateOrder != updateOrder) { this._updateOrder = updateOrder; @@ -1013,19 +925,20 @@ var Entity = (function () { this.scene = newScene; newScene.entities.add(this); this.components.registerAllComponents(); - for (var i = 0; i < this.transform.childCount; i++) { - this.transform.getChild(i).entity.attachToScene(newScene); + for (var i = 0; i < this.numChildren; i++) { + this.getChildAt(i).entity.attachToScene(newScene); } }; Entity.prototype.detachFromScene = function () { this.scene.entities.remove(this); this.components.deregisterAllComponents(); - for (var i = 0; i < this.transform.childCount; i++) - this.transform.getChild(i).entity.detachFromScene(); + for (var i = 0; i < this.numChildren; i++) + this.getChildAt(i).entity.detachFromScene(); }; Entity.prototype.addComponent = function (component) { component.entity = this; this.components.add(component); + this.addChild(component); component.initialize(); return component; }; @@ -1073,17 +986,17 @@ var Entity = (function () { Entity.prototype.onTransformChanged = function (comp) { this.components.onEntityTransformChanged(comp); }; - Entity.prototype.destory = function () { + Entity.prototype.destroy = function () { this._isDestoryed = true; this.scene.entities.remove(this); - this.transform.parent = null; - for (var i = this.transform.childCount - 1; i >= 0; i--) { - var child = this.transform.getChild(i); - child.entity.destory(); + this.removeChildren(); + for (var i = this.numChildren - 1; i >= 0; i--) { + var child = this.getChildAt(i); + child.entity.destroy(); } }; return Entity; -}()); +}(egret.DisplayObjectContainer)); var Scene = (function (_super) { __extends(Scene, _super); function Scene() { @@ -1091,7 +1004,6 @@ var Scene = (function (_super) { _this.enablePostProcessing = true; _this._renderers = []; _this._postProcessors = []; - _this._projectionMatrix = new Matrix2D(0, 0, 0, 0, 0, 0); _this.entityProcessors = new EntityProcessorList(); _this.renderableComponents = new RenderableComponentList(); _this.entities = new EntityList(_this); @@ -1102,19 +1014,20 @@ var Scene = (function (_super) { } Scene.prototype.createEntity = function (name) { var entity = new Entity(name); - entity.transform.position = new Vector2(0, 0); + entity.position = new Vector2(0, 0); return this.addEntity(entity); }; Scene.prototype.addEntity = function (entity) { this.entities.add(entity); entity.scene = this; - for (var i = 0; i < entity.transform.childCount; i++) - this.addEntity(entity.transform.getChild(i).entity); + this.addChild(entity); + for (var i = 0; i < entity.numChildren; i++) + this.addEntity(entity.getChildAt(i).entity); return entity; }; Scene.prototype.destroyAllEntities = function () { for (var i = 0; i < this.entities.count; i++) { - this.entities.buffer[i].destory(); + this.entities.buffer[i].destroy(); } }; Scene.prototype.findEntity = function (name) { @@ -1178,6 +1091,7 @@ var Scene = (function (_super) { this._postProcessors[i].unload(); } this.entities.removeAllEntities(); + this.removeChildren(); Physics.clear(); this.camera.destory(); this.camera = null; @@ -1275,7 +1189,7 @@ var SceneManager = (function () { SceneManager._scene.end(); for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) { var entity = SceneManager._scene.entities.buffer[i]; - entity.destory(); + entity.destroy(); } SceneManager._scene = SceneManager._nextScene; SceneManager._nextScene = null; @@ -1632,14 +1546,12 @@ var Camera = (function (_super) { _this._origin = Vector2.zero; _this._transformMatrix = new Matrix2D(); _this._inverseTransformMatrix = new Matrix2D(); - _this._projectionMatrix = new Matrix2D(); _this._minimumZoom = 0.3; _this._maximumZoom = 3; _this._areMatrixesDirty = true; _this._inset = new CameraInset(); _this._bounds = new Rectangle(); _this._areBoundsDirty = true; - _this._isProjectionMatrixDirty = true; _this.setZoom(0); return _this; } @@ -1651,7 +1563,7 @@ var Camera = (function (_super) { var stage = this.stage; var topLeft = this.screenToWorldPoint(new Vector2(this._inset.left, this._inset.top)); var bottomRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, stage.stageHeight - this._inset.bottom)); - if (this.entity.transform.rotation != 0) { + if (this.entity.rotation != 0) { var topRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, this._inset.top)); var bottomLeft = this.screenToWorldPoint(new Vector2(this._inset.left, stage.stageHeight - this._inset.bottom)); var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); @@ -1723,10 +1635,10 @@ var Camera = (function (_super) { }); Object.defineProperty(Camera.prototype, "position", { get: function () { - return this.entity.transform.position; + return this.entity.position; }, set: function (value) { - this.entity.transform.position = value; + this.entity.position = value; }, enumerable: true, configurable: true @@ -1750,10 +1662,9 @@ var Camera = (function (_super) { configurable: true }); Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { - this._isProjectionMatrixDirty = true; var oldOrigin = this._origin; this.origin = new Vector2(newWidth / 2, newHeight / 2); - this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin)); + this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); }; Camera.prototype.setMinimumZoom = function (minZoom) { if (this._zoom < minZoom) @@ -1782,7 +1693,7 @@ var Camera = (function (_super) { return this; }; Camera.prototype.setPosition = function (position) { - this.entity.transform.setPosition(position); + this.entity.position = position; return this; }; Camera.prototype.forceMatrixUpdate = function () { @@ -1792,12 +1703,12 @@ var Camera = (function (_super) { if (!this._areMatrixesDirty) return; var tempMat; - this._transformMatrix = Matrix2D.createTranslation(-this.entity.transform.position.x, -this.entity.transform.position.y); + this._transformMatrix = Matrix2D.createTranslation(-this.entity.position.x, -this.entity.position.y); if (this._zoom != 1) { tempMat = Matrix2D.createScale(this._zoom, this._zoom); this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat); } - if (this.entity.transform.rotation != 0) { + if (this.entity.rotation != 0) { tempMat = Matrix2D.createRotation(this.entity.rotation); this._transformMatrix = Matrix2D.multiply(this._transformMatrix, tempMat); } @@ -1877,10 +1788,10 @@ var FollowCamera = (function (_super) { if (this._targetEntity) this.updateFollow(); this.camera.position = Vector2.lerp(this.camera.position, Vector2.add(this.camera.position, this._desiredPositionDelta), this.followLerp); - this.camera.entity.transform.roundPosition(); + this.camera.entity.roundPosition(); if (this.mapLockEnabled) { this.camera.position = this.clampToMapSize(this.camera.position); - this.camera.entity.transform.roundPosition(); + this.camera.entity.roundPosition(); } }; FollowCamera.prototype.clampToMapSize = function (position) { @@ -1891,8 +1802,8 @@ var FollowCamera = (function (_super) { FollowCamera.prototype.updateFollow = function () { this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; if (this._cameraStyle == CameraStyle.lockOn) { - var targetX = this._targetEntity.transform.position.x; - var targetY = this._targetEntity.transform.position.y; + var targetX = this._targetEntity.position.x; + var targetY = this._targetEntity.position.y; if (this._worldSpaceDeadZone.x > targetX) this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; else if (this._worldSpaceDeadZone.x < targetX) @@ -2026,11 +1937,7 @@ var RenderableComponent = (function (_super) { }); Object.defineProperty(RenderableComponent.prototype, "bounds", { get: function () { - if (this._areBoundsDirty) { - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0), this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height); - this._areBoundsDirty = false; - } - return this._bounds; + return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height); }, enumerable: true, configurable: true @@ -2084,37 +1991,6 @@ var SpriteRenderer = (function (_super) { function SpriteRenderer() { return _super !== null && _super.apply(this, arguments) || this; } - Object.defineProperty(SpriteRenderer.prototype, "bounds", { - get: function () { - if (this._areBoundsDirty) { - if (this._sprite) { - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.texture2D.textureWidth, this._sprite.texture2D.textureHeight); - this._areBoundsDirty = false; - } - } - return this._bounds; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SpriteRenderer.prototype, "sprite", { - get: function () { - return this._sprite; - }, - set: function (value) { - this.setSprite(value); - }, - enumerable: true, - configurable: true - }); - SpriteRenderer.prototype.setSprite = function (sprite) { - this._sprite = sprite; - if (this._sprite) - this._origin = sprite.origin; - this._bitmap = new egret.Bitmap(sprite.texture2D); - this.scene.addChild(this._bitmap); - return this; - }; Object.defineProperty(SpriteRenderer.prototype, "origin", { get: function () { return this._origin; @@ -2132,6 +2008,10 @@ var SpriteRenderer = (function (_super) { } return this; }; + SpriteRenderer.prototype.setSprite = function (sprite) { + this.removeChildren(); + this.addChild(new egret.Bitmap(sprite.texture2D)); + }; SpriteRenderer.prototype.setColor = function (color) { var colorMatrix = [ 1, 0, 0, 0, 0, @@ -2143,28 +2023,19 @@ var SpriteRenderer = (function (_super) { colorMatrix[6] = Math.floor(color / 256 % 256) / 255; colorMatrix[12] = color % 256 / 255; var colorFilter = new egret.ColorMatrixFilter(colorMatrix); - this._bitmap.filters = [colorFilter]; + this.filters = [colorFilter]; }; SpriteRenderer.prototype.isVisibleFromCamera = function (camera) { var topLeft = camera.screenToWorldPoint(new Vector2(0, 0)); this.isVisible = new Rectangle(topLeft.x, topLeft.y, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); - this._bitmap.visible = this.isVisible; + this.visible = this.isVisible; return this.isVisible; }; SpriteRenderer.prototype.render = function (camera) { - if (!this.sprite) - return; - this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x; - this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y; - this._bitmap.rotation = this.entity.transform.rotation + camera.transform.rotation; - this._bitmap.anchorOffsetX = this._origin.x; - this._bitmap.anchorOffsetY = this._origin.y; - this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x; - this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y; }; SpriteRenderer.prototype.onRemovedFromEntity = function () { - if (this._bitmap) - this.scene.removeChild(this._bitmap); + if (this.parent) + this.parent.removeChild(this); }; return SpriteRenderer; }(RenderableComponent)); @@ -2207,7 +2078,7 @@ var Mover = (function (_super) { return collisionResult; }; Mover.prototype.applyMovement = function (motion) { - this.entity.transform.position = Vector2.add(this.entity.transform.position, motion); + this.entity.position = Vector2.add(this.entity.position, motion); if (this._triggerHelper) this._triggerHelper.update(); }; @@ -2292,13 +2163,13 @@ var Collider = (function (_super) { var renderable = this.entity.getComponent(RenderableComponent); if (renderable) { var renderbaleBounds = renderable.bounds; - var width = renderbaleBounds.width / this.entity.transform.scale.x; - var height = renderbaleBounds.height / this.entity.transform.scale.y; + var width = renderbaleBounds.width / this.entity.scale.x; + var height = renderbaleBounds.height / this.entity.scale.y; if (this instanceof BoxCollider) { var boxCollider = this; boxCollider.width = width; boxCollider.height = height; - this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.transform.position); + this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position); } } } @@ -2672,6 +2543,8 @@ var ComponentList = (function () { } }; ComponentList.prototype.handleRemove = function (component) { + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.remove(component); this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); component.onRemovedFromEntity(); @@ -3004,6 +2877,74 @@ var Time = (function () { Time._lastTime = 0; return Time; }()); +var GraphicsCapabilities = (function () { + function GraphicsCapabilities() { + } + GraphicsCapabilities.prototype.initialize = function (device) { + this.platformInitialize(device); + }; + GraphicsCapabilities.prototype.platformInitialize = function (device) { + var gl = new egret.sys.RenderBuffer().context.getInstance(); + this.supportsNonPowerOfTwo = false; + this.supportsTextureFilterAnisotropic = gl.getExtension("EXT_texture_filter_anisotropic") != null; + this.supportsDepth24 = true; + this.supportsPackedDepthStencil = true; + this.supportsDepthNonLinear = false; + this.supportsTextureMaxLevel = true; + this.supportsS3tc = gl.getExtension("WEBGL_compressed_texture_s3tc") != null || + gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") != null; + this.supportsDxt1 = this.supportsS3tc; + this.supportsPvrtc = false; + this.supportsAtitc = gl.getExtension("WEBGL_compressed_texture_astc") != null; + this.supportsFramebufferObjectARB = false; + }; + return GraphicsCapabilities; +}()); +var GraphicsDevice = (function () { + function GraphicsDevice() { + this.graphicsCapabilities = new GraphicsCapabilities(); + this.graphicsCapabilities.initialize(this); + } + return GraphicsDevice; +}()); +var Viewport = (function () { + function Viewport(x, y, width, height) { + this._x = x; + this._y = y; + this._width = width; + this._height = height; + this._minDepth = 0; + this._maxDepth = 1; + } + Object.defineProperty(Viewport.prototype, "aspectRatio", { + get: function () { + if ((this._height != 0) && (this._width != 0)) + return (this._width / this._height); + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Viewport.prototype, "bounds", { + get: function () { + return new Rectangle(this._x, this._y, this._width, this._height); + }, + set: function (value) { + this._x = value.x; + this._y = value.y; + this._width = value.width; + this._height = value.height; + }, + enumerable: true, + configurable: true + }); + return Viewport; +}()); +var GraphicsResource = (function () { + function GraphicsResource() { + } + return GraphicsResource; +}()); var GaussianBlurEffect = (function (_super) { __extends(GaussianBlurEffect, _super); function GaussianBlurEffect() { @@ -3152,11 +3093,6 @@ var Renderer = (function () { } Renderer.prototype.onAddedToScene = function (scene) { }; Renderer.prototype.beginRender = function (cam) { - cam.transform.updateTransform(); - var entities = SceneManager.scene.entities; - for (var i = 0; i < entities.buffer.length; i++) { - entities.buffer[i].transform.updateTransform(); - } }; Renderer.prototype.unload = function () { }; Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { @@ -3203,7 +3139,7 @@ var PolyLight = (function (_super) { Object.defineProperty(PolyLight.prototype, "bounds", { get: function () { if (this._areBoundsDirty) { - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(this._radius), Vector2.one, 0, this._radius * 2, this._radius * 2); + this._bounds.calculateBounds(this.entity.position, this._localOffset, new Vector2(this._radius), Vector2.one, 0, this._radius * 2, this._radius * 2); this._areBoundsDirty = false; } return this._bounds; @@ -3602,6 +3538,10 @@ var Matrix2D = (function () { result.m32 = 0; return result; }; + Matrix2D.prototype.toEgretMatrix = function () { + var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); + return matrix; + }; Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); return Matrix2D; }()); @@ -3901,6 +3841,14 @@ var Vector2 = (function () { Vector2.zeroVector2 = new Vector2(0, 0); return Vector2; }()); +var Vector3 = (function () { + function Vector3(x, y, z) { + this.x = x; + this.y = y; + this.z = z; + } + return Vector3; +}()); var ColliderTriggerHelper = (function () { function ColliderTriggerHelper(entity) { this._activeTriggerIntersections = []; @@ -4292,28 +4240,28 @@ var Polygon = (function (_super) { var hasUnitScale = true; var tempMat = void 0; var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); - if (collider.entity.transform.scale != Vector2.one) { - tempMat = Matrix2D.createScale(collider.entity.transform.scale.x, collider.entity.transform.scale.y); + if (collider.entity.scale != Vector2.one) { + tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); hasUnitScale = false; - var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.transform.scale); + var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale); this.center = scaledOffset; } - if (collider.entity.transform.rotation != 0) { - tempMat = Matrix2D.createRotation(collider.entity.transform.rotation); + if (collider.entity.rotation != 0) { + tempMat = Matrix2D.createRotation(collider.entity.rotation); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.transform.scale)).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); } tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); - this.isUnrotated = collider.entity.transform.rotation == 0; + this.isUnrotated = collider.entity.rotation == 0; if (collider._isRotationDirty) this._areEdgeNormalsDirty = true; } - this.position = Vector2.add(collider.entity.transform.position, this.center); + this.position = Vector2.add(collider.entity.position, this.center); this.bounds = Rectangle.rectEncompassingPoints(this.points); this.bounds.location = Vector2.add(this.bounds.location, this.position); }; @@ -4382,17 +4330,17 @@ var Circle = (function (_super) { Circle.prototype.recalculateBounds = function (collider) { this.center = collider.localOffset; if (collider.shouldColliderScaleAndRotationWithTransform) { - var scale = collider.entity.transform.scale; + var scale = collider.entity.scale; var hasUnitScale = scale.x == 1 && scale.y == 1; var maxScale = Math.max(scale.x, scale.y); this.radius = this._originalRadius * maxScale; - if (collider.entity.transform.rotation != 0) { + if (collider.entity.rotation != 0) { var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.transform.scale)).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); } } - this.position = Vector2.add(collider.entity.transform.position, this.center); + this.position = Vector2.add(collider.entity.position, this.center); this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); }; Circle.prototype.overlaps = function (other) { @@ -5166,45 +5114,8 @@ var Vector2Ext = (function () { Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); }; + Vector2Ext.round = function (vec) { + return new Vector2(Math.round(vec.x), Math.round(vec.y)); + }; return Vector2Ext; }()); -var WebGLUtils = (function () { - function WebGLUtils() { - } - WebGLUtils.getWebGL = function () { - if (egret.WebGLUtils.checkCanUseWebGL()) - return document.querySelector("canvas").getContext("webgl"); - throw new Error("cannot get webgl"); - }; - WebGLUtils.drawUserIndexPrimitives = function (primitiveType, vertexData, vertexOffset, numVertices, indexData, indexOffset, primitiveCount) { - var GL = this.getWebGL(); - GL.bindBuffer(GL.ARRAY_BUFFER, 0); - this.checkGLError(); - GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0); - this.checkGLError(); - GL.drawElements(primitiveType, this.getElementCountArray(primitiveType, primitiveCount), GL.UNSIGNED_SHORT, indexOffset * 2); - this.checkGLError(); - }; - WebGLUtils.getElementCountArray = function (primitiveType, primitiveCount) { - var GL = this.getWebGL(); - switch (primitiveType) { - case GL.LINES: - return primitiveCount * 2; - case GL.LINE_STRIP: - return primitiveCount + 1; - case GL.TRIANGLES: - return primitiveCount * 3; - case GL.TRIANGLE_STRIP: - return primitiveCount + 2; - } - throw new Error("not support"); - }; - WebGLUtils.checkGLError = function () { - var GL = this.getWebGL(); - var error = GL.getError(); - if (error != GL.NO_ERROR) { - throw new Error("GL.GetError() returned" + error); - } - }; - return WebGLUtils; -}()); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 085e8758..c15671ff 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.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||0,this.y=e||this.x}}(),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}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(t.prototype,"stage",{get:function(){return this.entity?this.entity.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scene",{get:function(){return this.entity?this.entity.scene:null},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},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(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e._projectionMatrix=new Matrix2D(0,0,0,0,0,0),e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}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;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(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.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.forceMatrixUpdate=function(){this._areMatrixesDirty=!0},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)),0!=this.entity.transform.rotation&&(t=Matrix2D.createRotation(this.entity.rotation),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._transformMatrix)},e.prototype.onEntityTransformChanged=function(t){this._areMatrixesDirty=!0},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){this.left=0,this.right=0,this.top=0,this.bottom=0}}(),FollowCamera=function(t){function e(e,n){void 0===n&&(n=CameraStyle.lockOn);var i=t.call(this)||this;return i.followLerp=.1,i.deadzone=new Rectangle,i.focusOffset=new Vector2,i.mapSize=new Vector2,i._worldSpaceDeadZone=new Rectangle,i._desiredPositionDelta=new Vector2,i._targetEntity=e,i._cameraStyle=n,i.camera=null,i}return __extends(e,t),e.prototype.onAddedToEntity=function(){this.camera||(this.camera=this.entity.scene.camera),this.follow(this._targetEntity,this._cameraStyle)},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this._targetEntity=t,this._cameraStyle=e;var n=this.camera.bounds;switch(this._cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=Vector2.multiply(this.camera.bounds.size,new Vector2(.5));this._worldSpaceDeadZone.x=this.camera.position.x-t.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.camera.position.y-t.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.camera.position=Vector2.lerp(this.camera.position,Vector2.add(this.camera.position,this._desiredPositionDelta),this.followLerp),this.camera.entity.transform.roundPosition(),this.mapLockEnabled&&(this.camera.position=this.clampToMapSize(this.camera.position),this.camera.entity.transform.roundPosition())},e.prototype.clampToMapSize=function(t){var e=Vector2.multiply(new Vector2(this.camera.bounds.width,this.camera.bounds.height),new Vector2(.5)),n=new Vector2(this.mapSize.x-e.x,this.mapSize.y-e.y);return Vector2.clamp(t,e,n)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==CameraStyle.lockOn){var t=this._targetEntity.transform.position.x,e=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this._targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var PointSectors,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.contains(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}(),RenderableComponentList=function(){function t(){this._components=[]}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._components.push(t)},t.prototype.remove=function(t){this._components.remove(t)},t.prototype.updateList=function(){},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enable=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),BloomSettings=function(){function t(t,e,n,i,o,r){this.threshold=t,this.blurAmount=e,this.intensity=n,this.baseIntensity=i,this.saturation=o,this.baseStaturation=r}return t.presetSettings=[new t(.1,.6,2,1,1,0),new t(0,3,1,1,1,1),new t(.5,8,2,1,0,1),new t(.25,8,1.3,1,1,0),new t(0,2,1,.1,1,1),new t(.5,2,1,1,1,1)],t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){t.transform.updateTransform();for(var e=SceneManager.scene.entities,n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,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||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}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(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,h=e.m31*n.m11+e.m32*n.m21+n.m31,c=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=h,i.m32=c,i},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=new t);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(i=i||new t).m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=new t;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=new t),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(){function t(t,e,n,i){this.x=t||0,this.y=e||0,this.width=n||0,this.height=i||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,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.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),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}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(y=Math.abs(y))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/c))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.load=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},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.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var i=t.findIndex(e);return-1==i?null:t[i]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;nr?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"stage",{get:function(){return this.entity?this.entity.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scene",{get:function(){return this.entity?this.entity.scene:null},enumerable:!0,configurable:!0}),e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(i){var n=t.call(this)||this;return n._updateOrder=0,n._enabled=!0,n._tag=0,n.name=i,n.components=new ComponentList(n),n.id=e._idGenerator++,n.componentBits=new BitSet,n}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.scaleX=t.x,this.scaleY=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer),Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(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.setPosition=function(t){return this.entity.position=t,this},e.prototype.forceMatrixUpdate=function(){this._areMatrixesDirty=!0},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.position.x,-this.entity.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),0!=this.entity.rotation&&(t=Matrix2D.createRotation(this.entity.rotation),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._transformMatrix)},e.prototype.onEntityTransformChanged=function(t){this._areMatrixesDirty=!0},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){this.left=0,this.right=0,this.top=0,this.bottom=0}}(),FollowCamera=function(t){function e(e,i){void 0===i&&(i=CameraStyle.lockOn);var n=t.call(this)||this;return n.followLerp=.1,n.deadzone=new Rectangle,n.focusOffset=new Vector2,n.mapSize=new Vector2,n._worldSpaceDeadZone=new Rectangle,n._desiredPositionDelta=new Vector2,n._targetEntity=e,n._cameraStyle=i,n.camera=null,n}return __extends(e,t),e.prototype.onAddedToEntity=function(){this.camera||(this.camera=this.entity.scene.camera),this.follow(this._targetEntity,this._cameraStyle)},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this._targetEntity=t,this._cameraStyle=e;var i=this.camera.bounds;switch(this._cameraStyle){case CameraStyle.cameraWindow:var n=i.width/6,o=i.height/3;this.deadzone=new Rectangle((i.width-n)/2,(i.height-o)/2,n,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(i.width/2,i.height/2,10,10)}},e.prototype.update=function(){var t=Vector2.multiply(this.camera.bounds.size,new Vector2(.5));this._worldSpaceDeadZone.x=this.camera.position.x-t.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.camera.position.y-t.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.camera.position=Vector2.lerp(this.camera.position,Vector2.add(this.camera.position,this._desiredPositionDelta),this.followLerp),this.camera.entity.roundPosition(),this.mapLockEnabled&&(this.camera.position=this.clampToMapSize(this.camera.position),this.camera.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=Vector2.multiply(new Vector2(this.camera.bounds.width,this.camera.bounds.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-e.x,this.mapSize.y-e.y);return Vector2.clamp(t,e,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==CameraStyle.lockOn){var t=this._targetEntity.position.x,e=this._targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(Collider),!this._targetCollider))return;var i=this._targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(i)||(this._worldSpaceDeadZone.left>i.left?this._desiredPositionDelta.x=i.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.righti.top&&(this._desiredPositionDelta.y=i.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var PointSectors,Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,i=1<>6;this.ensure(i),this._bits[i]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(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}(),RenderableComponentList=function(){function t(){this._components=[]}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._components.push(t)},t.prototype.remove=function(t){this._components.remove(t)},t.prototype.updateList=function(){},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),GraphicsCapabilities=function(){function t(){}return t.prototype.initialize=function(t){this.platformInitialize(t)},t.prototype.platformInitialize=function(t){var e=(new egret.sys.RenderBuffer).context.getInstance();this.supportsNonPowerOfTwo=!1,this.supportsTextureFilterAnisotropic=null!=e.getExtension("EXT_texture_filter_anisotropic"),this.supportsDepth24=!0,this.supportsPackedDepthStencil=!0,this.supportsDepthNonLinear=!1,this.supportsTextureMaxLevel=!0,this.supportsS3tc=null!=e.getExtension("WEBGL_compressed_texture_s3tc")||null!=e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),this.supportsDxt1=this.supportsS3tc,this.supportsPvrtc=!1,this.supportsAtitc=null!=e.getExtension("WEBGL_compressed_texture_astc"),this.supportsFramebufferObjectARB=!1},t}(),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,i,n){this._x=t,this._y=e,this._width=i,this._height=n,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GraphicsResource=function(){return function(){}}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enable=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),BloomSettings=function(){function t(t,e,i,n,o,r){this.threshold=t,this.blurAmount=e,this.intensity=i,this.baseIntensity=n,this.saturation=o,this.baseStaturation=r}return t.presetSettings=[new t(.1,.6,2,1,1,0),new t(0,3,1,1,1,1),new t(.5,8,2,1,0,1),new t(.25,8,1.3,1,1,0),new t(0,2,1,.1,1,1),new t(.5,2,1,1,1,1)],t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var i=0;ii?i:t},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=i||0,this.m22=n||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,i){var n=new t,o=e.m11*i.m11+e.m12*i.m21,r=e.m11*i.m12+e.m12*i.m22,s=e.m21*i.m11+e.m22*i.m21,a=e.m21*i.m12+e.m22*i.m22,h=e.m31*i.m11+e.m32*i.m21+i.m31,c=e.m31*i.m12+e.m32*i.m22+i.m32;return n.m11=o,n.m12=r,n.m21=s,n.m22=a,n.m31=h,n.m32=c,n},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=new t);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return(n=n||new t).m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=new t;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=new t),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.leftn&&(n=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,i,n,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,n},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,n},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.clamp=function(e,i,n){return new t(MathHelper.clamp(e.x,i.x,n.x),MathHelper.clamp(e.y,i.y,n.y))},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),Vector3=function(){return function(t,e,i){this.x=t,this.y=e,this.z=i}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))=t&&o.y>=e&&o.x=t+i&&(r|=PointSectors.right),o.y=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,i){var n=t.call(this)||this;return n.isUnrotated=!0,n._areEdgeNormalsDirty=!0,n.setPoints(e),n.isBox=i,n}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var i=0;i=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n0&&(o=!1),!o)return null;(y=Math.abs(y))n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/c))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n=0?t:4294967296+t},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.load=function(t,e){var i=this;return void 0===e&&(e=!0),new Promise(function(n,o){var r=i.loadedAssets.get(t);r?n(r):e?RES.getResAsync(t).then(function(e){i.loadedAssets.set(t,e),n(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){i.loadedAssets.set(t,e),n(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,i,n,o,r){for(var s=0;s targetX) this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index 5d9663d0..9ce3464c 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -82,15 +82,15 @@ abstract class Collider extends Component{ if (renderable){ let renderbaleBounds = renderable.bounds; - let width = renderbaleBounds.width / this.entity.transform.scale.x; - let height = renderbaleBounds.height / this.entity.transform.scale.y; + let width = renderbaleBounds.width / this.entity.scale.x; + let height = renderbaleBounds.height / this.entity.scale.y; if (this instanceof BoxCollider){ let boxCollider = this as BoxCollider; boxCollider.width = width; boxCollider.height = height; - this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.transform.position); + this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position); } } } diff --git a/source/src/ECS/Components/Physics/Mover.ts b/source/src/ECS/Components/Physics/Mover.ts index 434f30dd..90c132f4 100644 --- a/source/src/ECS/Components/Physics/Mover.ts +++ b/source/src/ECS/Components/Physics/Mover.ts @@ -46,7 +46,7 @@ class Mover extends Component { } public applyMovement(motion: Vector2){ - this.entity.transform.position = Vector2.add(this.entity.transform.position, motion); + this.entity.position = Vector2.add(this.entity.position, motion); if (this._triggerHelper) this._triggerHelper.update(); diff --git a/source/src/ECS/Components/RenderableComponent.ts b/source/src/ECS/Components/RenderableComponent.ts index 27d807a8..0da260b9 100644 --- a/source/src/ECS/Components/RenderableComponent.ts +++ b/source/src/ECS/Components/RenderableComponent.ts @@ -31,13 +31,7 @@ abstract class RenderableComponent extends Component implements IRenderable { } public get bounds(): Rectangle{ - if (this._areBoundsDirty){ - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0), - this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height); - this._areBoundsDirty = false; - } - - return this._bounds; + return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height); } protected getWidth(){ diff --git a/source/src/ECS/Components/SpriteRenderer.ts b/source/src/ECS/Components/SpriteRenderer.ts index a9b561bb..57b988a2 100644 --- a/source/src/ECS/Components/SpriteRenderer.ts +++ b/source/src/ECS/Components/SpriteRenderer.ts @@ -1,39 +1,5 @@ class SpriteRenderer extends RenderableComponent { - private _sprite: Sprite; private _origin: Vector2; - private _bitmap: egret.Bitmap; - - public get bounds(){ - if (this._areBoundsDirty){ - if (this._sprite){ - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, - this.entity.transform.scale, this.entity.transform.rotation, this._sprite.texture2D.textureWidth, - this._sprite.texture2D.textureHeight); - this._areBoundsDirty = false; - } - } - - return this._bounds; - } - - public get sprite(){ - return this._sprite; - } - - public set sprite(value: Sprite){ - this.setSprite(value); - } - - public setSprite(sprite: Sprite): SpriteRenderer{ - this._sprite = sprite; - if (this._sprite) - this._origin = sprite.origin; - - this._bitmap = new egret.Bitmap(sprite.texture2D); - this.scene.addChild(this._bitmap); - - return this; - } public get origin(){ return this._origin; @@ -49,6 +15,11 @@ class SpriteRenderer extends RenderableComponent { return this; } + public setSprite(sprite: Sprite){ + this.removeChildren(); + this.addChild(new egret.Bitmap(sprite.texture2D)); + } + public setColor(color: number){ let colorMatrix = [ 1, 0, 0, 0, 0, @@ -60,31 +31,22 @@ class SpriteRenderer extends RenderableComponent { colorMatrix[6] = Math.floor(color / 256 % 256) / 255; colorMatrix[12] = color % 256 / 255; let colorFilter = new egret.ColorMatrixFilter(colorMatrix); - this._bitmap.filters = [colorFilter]; + this.filters = [colorFilter]; } public isVisibleFromCamera(camera: Camera): boolean{ let topLeft = camera.screenToWorldPoint(new Vector2(0, 0)); this.isVisible = new Rectangle(topLeft.x, topLeft.y, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); - this._bitmap.visible = this.isVisible; + this.visible = this.isVisible; return this.isVisible; } public render(camera: Camera){ - if (!this.sprite) - return; - - this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x; - this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y; - this._bitmap.rotation = this.entity.transform.rotation + camera.transform.rotation; - this._bitmap.anchorOffsetX = this._origin.x; - this._bitmap.anchorOffsetY = this._origin.y; - this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x; - this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y; + } public onRemovedFromEntity(){ - if (this._bitmap) - this.scene.removeChild(this._bitmap); + if (this.parent) + this.parent.removeChild(this); } } \ No newline at end of file diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 2b29675e..53a7f2de 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -1,12 +1,10 @@ -class Entity { +class Entity extends egret.DisplayObjectContainer { private static _idGenerator: number; public name: string; public readonly id: number; /** 当前实体所属的场景 */ public scene: Scene; - /** 封装实体的位置/旋转/缩放,并允许设置一个高层结构 */ - public readonly transform: Transform; /** 当前附加到此实体的所有组件的列表 */ public readonly components: ComponentList; private _updateOrder: number = 0; @@ -16,92 +14,26 @@ class Entity { public componentBits: BitSet; - public get parent(){ - return this.transform.parent; - } - - public set parent(value: Transform){ - this.transform.setParent(value); + public get isDestoryed(){ + return this._isDestoryed; } public get position(){ - return this.transform.position; + return new Vector2(this.x, this.y); } public set position(value: Vector2){ - this.transform.setPosition(value); - } - - public get localPosition(){ - return this.transform.localPosition; - } - - public set localPosition(value: Vector2){ - this.transform.setLocalPosition(value); - } - - public get rotation(){ - return this.transform.rotation; - } - - public set rotation(value: number){ - this.transform.setRotation(value); - } - - public get rotationDegrees(){ - return this.transform.rotationDegrees; - } - - public set rotationDegrees(value: number){ - this.transform.setRotationDegrees(value); - } - - public get localRotation(){ - return this.transform.localRotation; - } - - public set localRotation(value: number){ - this.transform.setLocalRotation(value); - } - - public get localRotationDegrees(){ - return this.transform.localRotationDegrees; - } - - public set localRotationDegrees(value: number){ - this.transform.setLocalRotationDegrees(value); + this.x = value.x; + this.y = value.y; } public get scale(){ - return this.transform.scale; + return new Vector2(this.scaleX, this.scaleY); } public set scale(value: Vector2){ - this.transform.setScale(value); - } - - public get localScale(){ - return this.transform.scale; - } - - public set localScale(value: Vector2){ - this.transform.setScale(value); - } - - public get worldInverseTransform(){ - return this.transform.worldInverseTransform; - } - - public get localToWorldTransform(){ - return this.transform.localToWorldTransform; - } - - public get worldToLocalTransform(){ - return this.transform.worldToLocalTransform; - } - - public get isDestoryed(){ - return this._isDestoryed; + this.scaleX = value.x; + this.scaleY = value.y; } public get enabled(){ @@ -136,8 +68,8 @@ class Entity { } constructor(name: string){ + super(); this.name = name; - this.transform = new Transform(this); this.components = new ComponentList(this); this.id = Entity._idGenerator ++; @@ -152,6 +84,10 @@ class Entity { this.setUpdateOrder(value); } + public roundPosition(){ + this.position = Vector2Ext.round(this.position); + } + public setUpdateOrder(updateOrder: number){ if (this._updateOrder != updateOrder){ this._updateOrder = updateOrder; @@ -182,8 +118,8 @@ class Entity { newScene.entities.add(this); this.components.registerAllComponents(); - for (let i = 0; i < this.transform.childCount; i ++){ - this.transform.getChild(i).entity.attachToScene(newScene); + for (let i = 0; i < this.numChildren; i ++){ + (this.getChildAt(i) as Component).entity.attachToScene(newScene); } } @@ -191,13 +127,14 @@ class Entity { this.scene.entities.remove(this); this.components.deregisterAllComponents(); - for (let i = 0; i < this.transform.childCount; i ++) - this.transform.getChild(i).entity.detachFromScene(); + for (let i = 0; i < this.numChildren; i ++) + (this.getChildAt(i) as Component).entity.detachFromScene(); } public addComponent(component: T): T{ component.entity = this; this.components.add(component); + this.addChild(component); component.initialize(); return component; } @@ -260,14 +197,14 @@ class Entity { this.components.onEntityTransformChanged(comp); } - public destory(){ + public destroy(){ this._isDestoryed = true; this.scene.entities.remove(this); - this.transform.parent = null; + this.removeChildren(); - for (let i = this.transform.childCount - 1; i >= 0; i --){ - let child = this.transform.getChild(i); - child.entity.destory(); + for (let i = this.numChildren - 1; i >= 0; i --){ + let child = this.getChildAt(i); + (child as Component).entity.destroy(); } } } \ No newline at end of file diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts index c8ce131a..038845c9 100644 --- a/source/src/ECS/Scene.ts +++ b/source/src/ECS/Scene.ts @@ -6,9 +6,6 @@ class Scene extends egret.DisplayObjectContainer { public readonly content: ContentManager; public enablePostProcessing = true; - private _projectionMatrix: Matrix2D; - private _transformMatrix: Matrix2D; - private _matrixTransformMatrix: Matrix2D; private _renderers: Renderer[] = []; private _postProcessors: PostProcessor[] = []; private _didSceneBegin; @@ -17,7 +14,6 @@ class Scene extends egret.DisplayObjectContainer { constructor() { super(); - this._projectionMatrix = new Matrix2D(0, 0, 0, 0, 0, 0); this.entityProcessors = new EntityProcessorList(); this.renderableComponents = new RenderableComponentList(); this.entities = new EntityList(this); @@ -29,23 +25,24 @@ class Scene extends egret.DisplayObjectContainer { public createEntity(name: string) { let entity = new Entity(name); - entity.transform.position = new Vector2(0, 0); + entity.position = new Vector2(0, 0); return this.addEntity(entity); } public addEntity(entity: Entity) { this.entities.add(entity); entity.scene = this; + this.addChild(entity); - for (let i = 0; i < entity.transform.childCount; i++) - this.addEntity(entity.transform.getChild(i).entity); + for (let i = 0; i < entity.numChildren; i++) + this.addEntity((entity.getChildAt(i) as Component).entity); return entity; } public destroyAllEntities() { for (let i = 0; i < this.entities.count; i++) { - this.entities.buffer[i].destory(); + this.entities.buffer[i].destroy(); } } @@ -134,6 +131,7 @@ class Scene extends egret.DisplayObjectContainer { } this.entities.removeAllEntities(); + this.removeChildren(); Physics.clear(); diff --git a/source/src/ECS/SceneManager.ts b/source/src/ECS/SceneManager.ts index 5c399120..53294375 100644 --- a/source/src/ECS/SceneManager.ts +++ b/source/src/ECS/SceneManager.ts @@ -50,7 +50,7 @@ class SceneManager { for (let i = 0; i < SceneManager._scene.entities.buffer.length; i++) { let entity = SceneManager._scene.entities.buffer[i]; - entity.destory(); + entity.destroy(); } SceneManager._scene = SceneManager._nextScene; diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index 73b99c6c..0a83171f 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -102,6 +102,9 @@ class ComponentList { } private handleRemove(component: Component){ + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); diff --git a/source/src/Graphics/Batcher/GraphicsResource.ts b/source/src/Graphics/Batcher/GraphicsResource.ts new file mode 100644 index 00000000..b57b6ba6 --- /dev/null +++ b/source/src/Graphics/Batcher/GraphicsResource.ts @@ -0,0 +1,3 @@ +abstract class GraphicsResource { + +} \ No newline at end of file diff --git a/source/src/Graphics/GraphicsCapabilities.ts b/source/src/Graphics/GraphicsCapabilities.ts new file mode 100644 index 00000000..f4509bb2 --- /dev/null +++ b/source/src/Graphics/GraphicsCapabilities.ts @@ -0,0 +1,33 @@ +class GraphicsCapabilities { + public supportsTextureFilterAnisotropic: boolean; + public supportsNonPowerOfTwo: boolean; + public supportsDepth24: boolean; + public supportsPackedDepthStencil: boolean; + public supportsDepthNonLinear: boolean; + public supportsTextureMaxLevel: boolean; + public supportsS3tc: boolean; + public supportsDxt1: boolean; + public supportsPvrtc: boolean; + public supportsAtitc: boolean; + public supportsFramebufferObjectARB: boolean; + + public initialize(device: GraphicsDevice){ + this.platformInitialize(device); + } + + private platformInitialize(device: GraphicsDevice){ + let gl: WebGLRenderingContext = new egret.sys.RenderBuffer().context.getInstance(); + this.supportsNonPowerOfTwo = false; + this.supportsTextureFilterAnisotropic = gl.getExtension("EXT_texture_filter_anisotropic") != null; + this.supportsDepth24 = true; + this.supportsPackedDepthStencil = true; + this.supportsDepthNonLinear = false; + this.supportsTextureMaxLevel = true; + this.supportsS3tc = gl.getExtension("WEBGL_compressed_texture_s3tc") != null || + gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") != null; + this.supportsDxt1 = this.supportsS3tc; + this.supportsPvrtc = false; + this.supportsAtitc = gl.getExtension("WEBGL_compressed_texture_astc") != null; + this.supportsFramebufferObjectARB = false; + } +} \ No newline at end of file diff --git a/source/src/Graphics/GraphicsDevice.ts b/source/src/Graphics/GraphicsDevice.ts new file mode 100644 index 00000000..6deacb10 --- /dev/null +++ b/source/src/Graphics/GraphicsDevice.ts @@ -0,0 +1,10 @@ +class GraphicsDevice { + private viewport: Viewport; + + public graphicsCapabilities: GraphicsCapabilities; + + constructor(){ + this.graphicsCapabilities = new GraphicsCapabilities(); + this.graphicsCapabilities.initialize(this); + } +} \ No newline at end of file diff --git a/source/src/Graphics/Renderers/PolygonLight/PolyLight.ts b/source/src/Graphics/Renderers/PolygonLight/PolyLight.ts index bf0964a0..8702cbfa 100644 --- a/source/src/Graphics/Renderers/PolygonLight/PolyLight.ts +++ b/source/src/Graphics/Renderers/PolygonLight/PolyLight.ts @@ -6,7 +6,7 @@ class PolyLight extends RenderableComponent { public get bounds(){ if (this._areBoundsDirty){ - this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(this._radius), + this._bounds.calculateBounds(this.entity.position, this._localOffset, new Vector2(this._radius), Vector2.one, 0, this._radius * 2, this._radius * 2); this._areBoundsDirty = false; } diff --git a/source/src/Graphics/Renderers/Renderer.ts b/source/src/Graphics/Renderers/Renderer.ts index a46ae8aa..86b5afec 100644 --- a/source/src/Graphics/Renderers/Renderer.ts +++ b/source/src/Graphics/Renderers/Renderer.ts @@ -16,12 +16,7 @@ abstract class Renderer { public onAddedToScene(scene: Scene){} protected beginRender(cam: Camera){ - cam.transform.updateTransform(); - let entities = SceneManager.scene.entities; - for (let i = 0; i < entities.buffer.length; i ++){ - entities.buffer[i].transform.updateTransform(); - } } /** diff --git a/source/src/Graphics/Viewport.ts b/source/src/Graphics/Viewport.ts new file mode 100644 index 00000000..38ebef3f --- /dev/null +++ b/source/src/Graphics/Viewport.ts @@ -0,0 +1,34 @@ +class Viewport { + private _x: number; + private _y: number; + private _width: number; + private _height: number; + private _minDepth: number; + private _maxDepth: number; + + public get aspectRatio(){ + if ((this._height != 0) && (this._width != 0)) + return (this._width / this._height); + return 0; + } + + public get bounds(){ + return new Rectangle(this._x, this._y, this._width, this._height); + } + public set bounds(value: Rectangle){ + this._x = value.x; + this._y = value.y; + this._width = value.width; + this._height = value.height; + } + + constructor(x: number, y: number, width: number, height: number){ + this._x = x; + this._y = y; + this._width = width; + this._height = height; + this._minDepth = 0; + this._maxDepth = 1; + } + +} \ No newline at end of file diff --git a/source/src/Math/Matrix2D.ts b/source/src/Math/Matrix2D.ts index 31cde9ed..b2cc0cab 100644 --- a/source/src/Math/Matrix2D.ts +++ b/source/src/Math/Matrix2D.ts @@ -196,4 +196,9 @@ class Matrix2D { return result; } + + public toEgretMatrix(): egret.Matrix{ + let matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); + return matrix; + } } \ No newline at end of file diff --git a/source/src/Math/Vector3.ts b/source/src/Math/Vector3.ts new file mode 100644 index 00000000..7ef18989 --- /dev/null +++ b/source/src/Math/Vector3.ts @@ -0,0 +1,11 @@ +class Vector3 { + public x: number; + public y: number; + public z: number; + + constructor(x: number, y: number, z: number){ + this.x = x; + this.y = y; + this.z = z; + } +} \ No newline at end of file diff --git a/source/src/Physics/Shapes/Circle.ts b/source/src/Physics/Shapes/Circle.ts index 13d31c90..81593ea7 100644 --- a/source/src/Physics/Shapes/Circle.ts +++ b/source/src/Physics/Shapes/Circle.ts @@ -33,19 +33,19 @@ class Circle extends Shape { this.center = collider.localOffset; if (collider.shouldColliderScaleAndRotationWithTransform) { - let scale = collider.entity.transform.scale; + let scale = collider.entity.scale; let hasUnitScale = scale.x == 1 && scale.y == 1; let maxScale = Math.max(scale.x, scale.y); this.radius = this._originalRadius * maxScale; - if (collider.entity.transform.rotation != 0) { + if (collider.entity.rotation != 0) { let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - let offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.transform.scale)).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + let offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); } } - this.position = Vector2.add(collider.entity.transform.position, this.center); + this.position = Vector2.add(collider.entity.position, this.center); this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); } diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index a9f7c2a2..bd13d41f 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -175,35 +175,35 @@ class Polygon extends Shape { let tempMat: Matrix2D; let combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); - if (collider.entity.transform.scale != Vector2.one){ - tempMat = Matrix2D.createScale(collider.entity.transform.scale.x, collider.entity.transform.scale.y); + if (collider.entity.scale != Vector2.one){ + tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); hasUnitScale = false; - let scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.transform.scale); + let scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale); this.center = scaledOffset; } - if (collider.entity.transform.rotation != 0){ - tempMat = Matrix2D.createRotation(collider.entity.transform.rotation); + if (collider.entity.rotation != 0){ + tempMat = Matrix2D.createRotation(collider.entity.rotation); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - let offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.transform.scale)).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + let offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); } tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); - this.isUnrotated = collider.entity.transform.rotation == 0; + this.isUnrotated = collider.entity.rotation == 0; if (collider._isRotationDirty) this._areEdgeNormalsDirty = true; } - this.position = Vector2.add(collider.entity.transform.position, this.center); + this.position = Vector2.add(collider.entity.position, this.center); this.bounds = Rectangle.rectEncompassingPoints(this.points); this.bounds.location = Vector2.add(this.bounds.location, this.position); } diff --git a/source/src/Utils/Vector2Ext.ts b/source/src/Utils/Vector2Ext.ts index 6a398814..0068be0a 100644 --- a/source/src/Utils/Vector2Ext.ts +++ b/source/src/Utils/Vector2Ext.ts @@ -63,4 +63,8 @@ class Vector2Ext { public static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]) { this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); } + + public static round(vec: Vector2){ + return new Vector2(Math.round(vec.x), Math.round(vec.y)); + } } \ No newline at end of file diff --git a/source/src/Utils/WebGLUtils.ts b/source/src/Utils/WebGLUtils.ts deleted file mode 100644 index abc2cb16..00000000 --- a/source/src/Utils/WebGLUtils.ts +++ /dev/null @@ -1,48 +0,0 @@ -class WebGLUtils { - public static getWebGL(): WebGLRenderingContext { - if (egret.WebGLUtils.checkCanUseWebGL()) - return document.querySelector("canvas").getContext("webgl"); - - throw new Error("cannot get webgl"); - } - - public static drawUserIndexPrimitives(primitiveType: number, vertexData: T[], vertexOffset: number, - numVertices: number, indexData: number[], indexOffset: number, primitiveCount: number) { - let GL = this.getWebGL(); - - GL.bindBuffer(GL.ARRAY_BUFFER, 0); - this.checkGLError(); - GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, 0); - this.checkGLError(); - - GL.drawElements(primitiveType, - this.getElementCountArray(primitiveType, primitiveCount), - GL.UNSIGNED_SHORT, - indexOffset * 2); - this.checkGLError(); - } - - private static getElementCountArray(primitiveType: number, primitiveCount: number) { - let GL = this.getWebGL(); - switch (primitiveType) { - case GL.LINES: - return primitiveCount * 2; - case GL.LINE_STRIP: - return primitiveCount + 1; - case GL.TRIANGLES: - return primitiveCount * 3; - case GL.TRIANGLE_STRIP: - return primitiveCount + 2; - } - - throw new Error("not support"); - } - - public static checkGLError() { - let GL = this.getWebGL(); - let error = GL.getError(); - if (error != GL.NO_ERROR) { - throw new Error("GL.GetError() returned" + error); - } - } -} \ No newline at end of file