diff --git a/engine_support/egret b/engine_support/egret index ac5e49f6..05ab4bfb 160000 --- a/engine_support/egret +++ b/engine_support/egret @@ -1 +1 @@ -Subproject commit ac5e49f6e9aad01dabf0ad3f66b06716efe7bc90 +Subproject commit 05ab4bfb0d3d3f0ff7a3d9e5c507c184da03873f diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index ee5cab41..d1d1b63d 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -1,52 +1,96 @@ declare module es { /** - * 用于包装事件的一个小类 + * 全局核心类 */ - class FuncPack { - /** 函数 */ - func: Function; - /** 上下文 */ - context: any; - constructor(func: Function, context: any); - } - /** - * 用于事件管理 - */ - class Emitter { - private _messageTable; - constructor(); - /** - * 开始监听项 - * @param eventType 监听类型 - * @param handler 监听函数 - * @param context 监听上下文 - */ - addObserver(eventType: T, handler: Function, context: any): void; - /** - * 移除监听项 - * @param eventType 事件类型 - * @param handler 事件函数 - */ - removeObserver(eventType: T, handler: Function): void; - /** - * 触发该事件 - * @param eventType 事件类型 - * @param data 事件数据 - */ - emit(eventType: T, ...data: any[]): void; - } -} -declare module es { - /** - * 这里作为框架的核心件 - * 全局函数移动到这 - */ - class Framework { + class Core { /** * 核心发射器。只发出核心级别的事件 */ static emitter: Emitter; - static batcher: IBatcher; + /** + * 启用/禁用焦点丢失时的暂停。如果为真,则不调用更新或渲染方法 + */ + static pauseOnFocusLost: boolean; + /** + * 是否启用调试渲染 + */ + static debugRenderEndabled: boolean; + /** + * 简化对内部类的全局内容实例的访问 + */ + static _instance: Core; + /** + * 用于确定是否应该使用EntitySystems + */ + static entitySystemsEnabled: boolean; + _nextScene: Scene; + /** + * 用于凝聚GraphicsDeviceReset事件 + */ + _graphicsDeviceChangeTimer: ITimer; + /** + * 全局访问系统 + */ + _globalManagers: GlobalManager[]; + _coroutineManager: CoroutineManager; + _timerManager: TimerManager; + width: number; + height: number; + constructor(width: number, height: number, enableEntitySystems?: boolean); + /** + * 提供对单例/游戏实例的访问 + * @constructor + */ + static readonly Instance: Core; + _frameCounterElapsedTime: number; + _frameCounter: number; + _totalMemory: number; + _titleMemory: (totalMemory: number, frameCounter: number) => void; + _scene: Scene; + /** + * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 + */ + /** + * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 + * @param value + */ + static scene: Scene; + /** + * 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。 + * @param manager + */ + static registerGlobalManager(manager: es.GlobalManager): void; + /** + * 删除全局管理器对象 + * @param manager + */ + static unregisterGlobalManager(manager: es.GlobalManager): void; + /** + * 获取类型为T的全局管理器 + * @param type + */ + static getGlobalManager(type: any): T; + /** + * 启动一个coroutine。Coroutine可以将number延时几秒或延时到其他startCoroutine.Yielding + * null将使coroutine在下一帧被执行。 + * @param enumerator + */ + static startCoroutine(enumerator: any): ICoroutine; + /** + * 调度一个一次性或重复的计时器,该计时器将调用已传递的动作 + * @param timeInSeconds + * @param repeats + * @param context + * @param onTime + */ + static schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer; + startDebugDraw(): void; + /** + * 在一个场景结束后,下一个场景开始之前调用 + */ + onSceneChanged(): void; + protected initialize(): void; + protected update(currentTime?: number): Promise; } } declare module es { @@ -129,7 +173,6 @@ declare module es { * @param comp */ onEntityTransformChanged(comp: transform.Component): void; - debugRender(batcher: IBatcher): void; /** *当父实体或此组件启用时调用 */ @@ -144,31 +187,14 @@ declare module es { } declare module es { enum CoreEvents { - /** - * 在图形设备重置时触发。当这种情况发生时,任何渲染目标或其他内容的VRAM将被擦除,需要重新生成 - */ - graphicsDeviceReset = 0, /** * 当场景发生变化时触发 */ - sceneChanged = 1, + sceneChanged = 0, /** - * 当设备方向改变时触发 + * 每帧更新事件 */ - orientationChanged = 2, - /** - * 当Core.useCustomUpdate为true时则派发该事件 - */ - sceneUpdated = 3, - addDefaultRender = 4, - setRenderTarget = 5, - clearGraphics = 6, - disposeRenderTarget = 7, - resolutionScale = 8, - resolutionOffset = 9, - createRenderTarget = 10, - createCamera = 11, - rendererSizeChanged = 12 + frameUpdated = 1 } } declare module es { @@ -305,11 +331,6 @@ declare module es { * 每帧进行调用进行更新组件 */ update(): void; - /** - * 自定义渲染器可以选择是否调用它 - * @param batcher - */ - debugRender(batcher: IBatcher): void; /** * 将组件添加到组件列表中。返回组件。 * @param component @@ -517,69 +538,16 @@ declare module es { } /** 场景 */ class Scene { - /** - * 默认场景 摄像机 - */ - camera: ICamera; /** * 这个场景中的实体列表 */ readonly entities: EntityList; - /** 管理当前在场景中的所有RenderableComponents的列表 Entitys */ - readonly renderableComponents: RenderableComponentList; - /** - * 如果ResolutionPolicy是完美的像素,这将被设置为为它计算的比例 - */ - pixelPerfectScale: number; - /** - * 如果设置了,最终渲染到屏幕上的时间可以推迟到这个委托。 - * 这实际上只在最终渲染可能需要全屏大小效果的情况下有用,即使使用了一个小的后置缓冲区 - */ - finalRenderDelegate: IFinalRenderDelegate; - private _finalRenderDelegate; /** * 管理所有实体处理器 */ readonly entityProcessors: EntityProcessorList; - /** - * 所有场景的默认分辨率大小 - */ - private static _defaultDesignResolutionSize; - private static _defaultDesignBleedSize; - /** - * 用于所有场景的默认分辨率策略 - */ - private static _defaultSceneResolutionPolicy; - /** - * 场景的解析策略 - */ - private _resolutionPolicy; - /** - * 场景使用的设计分辨率大小 - */ - private _designResolutionSize; - private _designBleedSize; - /** - * 这将根据分辨率策略进行设置,并用于RenderTarget的最终输出 - */ - private _finalRenderDestinationRect; - private _sceneRenderTarget; - private _destinationRenderTarget; - private _screenshotRequestCallback; readonly _sceneComponents: SceneComponent[]; - _renderers: IRenderer[]; - readonly _afterPostProcessorRenderers: IRenderer[]; private _didSceneBegin; - private currentRenderId; - /** - * 设置新场景将使用的默认设计尺寸和分辨率策略,水平/垂直Bleed仅与BestFit相关 - * @param width - * @param height - * @param sceneResolutionPolicy - * @param horizontalBleed - * @param vertialcalBleed - */ - static setDefaultDesignResolution(width: number, height: number, sceneResolutionPolicy: SceneResolutionPolicy, horizontalBleed?: number, vertialcalBleed?: number): void; constructor(); /** * 在场景子类中重写这个,然后在这里进行加载。 @@ -597,22 +565,7 @@ declare module es { unload(): void; begin(): void; end(): void; - updateResolutionScaler(): void; - /** - * 下一次绘制完成后,这将克隆回缓冲区,并调用回调与clone。 - * 注意,当使用完Texture后,你必须处理掉它 - * @param callback - */ - requestScreenshot(callback: (texture: any) => void): void; update(): void; - render(): void; - /** - * 任何存在的PostProcessors都可以进行处理,然后我们对RenderTarget进行最后的渲染。 - * 几乎在所有情况下,finalRenderTarget都是空的。 - * 只有在场景转换的第一帧中,如果转换请求渲染,它才会有一个值。 - * @param finalRenderTarget - */ - postRender(finalRenderTarget?: any): void; /** * 向组件列表添加并返回SceneComponent * @param component @@ -633,21 +586,6 @@ declare module es { * @param component */ removeSceneComponent(component: SceneComponent): void; - /** - * 添加一个渲染器到场景中 - * @param renderer - */ - addRenderer(renderer: T): T; - /** - * 得到第一个T型的渲染器 - * @param type - */ - getRenderer(type: any): T; - /** - * 从场景中移除渲染器 - * @param renderer - */ - removeRenderer(renderer: IRenderer): void; /** * 将实体添加到此场景,并返回它 * @param name @@ -1272,7 +1210,6 @@ declare module es { * @param height */ setHeight(height: number): void; - debugRender(batcher: IBatcher): void; toString(): string; } } @@ -1292,7 +1229,6 @@ declare module es { * @param radius */ setRadius(radius: number): CircleCollider; - debugRender(batcher: IBatcher): void; toString(): string; } } @@ -1306,183 +1242,6 @@ declare module es { * @param points */ constructor(points: Vector2[]); - debugRender(batcher: IBatcher): void; - } -} -declare module es { - /** - * 接口,当应用于一个Component时,它将被注册到场景渲染器中。 - * 请仔细实现这个功能 改变像layerDepth/renderLayer/material这样的东西需要更新Scene RenderableComponentList - */ - interface IRenderable { - /** 包裹此对象的AABB。用来进行相机筛选 */ - bounds: Rectangle; - /** 这个IRenderable是否应该被渲染 */ - enabled: boolean; - /** - * 标准的Batcher图层深度,0为前面,1为后面。 - * 改变这个值会触发场景中可渲染组件列表的排序 - */ - layerDepth: number; - /** - * 较低的renderLayers在前面,较高的在後面,就像layerDepth一样,但不是限制在0-1。 - * 请注意,这意味着较高的renderLayers首先被发送到Batcher。在使用模板缓冲区时,这是一个重要的事实 - */ - renderLayer: number; - /** - * 由渲染器使用,用于指定该精灵应如何渲染。 - * 如果非空,当组件从实体中移除时,它会被自动处理。 - */ - material: any; - /** - * 这个Renderable的可见性。 - * 状态的改变最终会调用onBecameVisible/onBecameInvisible方法 - */ - isVisible: boolean; - /** - * 用于检索一个已经铸造的Material子类的帮助程序 - */ - getMaterial(): T; - /** - * 如果Renderables的边界与Camera.bounds相交,则返回true。 - * 处理isVisible标志的状态切换。 - * 在你的渲染方法中使用这个方法来决定你是否应该渲染 - * @param camera - */ - isVisibleFromCamera(camera: ICamera): boolean; - /** - * 被渲染器调用。摄像机可以用来进行裁剪,并使用Batcher实例进行绘制 - * @param batcher - * @param camera - */ - render(batcher: IBatcher, camera: ICamera): any; - /** - * 只有在没有对撞机的情况下才会渲染边界。 - * 始终在原点上渲染一个正方形 - * @param batcher - */ - debugRender(batcher: IBatcher): any; - } - /** - * 对IRenderables进行排序的比较器。 - * 首先按 RenderLayer 排序,然后按 LayerDepth 排序。 - * 如果出现平局,则使用材料作为平局的断定器,以避免渲染状态的改变 - */ - class RenderableComparer implements IComparer { - compare(self: IRenderable, other: IRenderable): number; - } -} -declare module es { - /** - * IRenderable的具体实现。包含方便的方法。 - * 非常重要!子类必须覆盖width/height或bounds! 子类必须覆盖width/height或bounds! - */ - abstract class RenderableComponent extends Component implements IRenderable, IComparer { - static renderIdGenerator: number; - /** - * 不重写bounds属性的子类必须实现这个!RenderableComponent的宽度。 - */ - abstract readonly width: any; - /** - * 不重写bounds属性的子类必须实现这个! - */ - abstract readonly height: any; - /** - * 包裹此对象的AABB。用来进行相机筛选。 - */ - abstract readonly bounds: any; - /** - * 标准的Batcher图层深度,0为前面,1为后面。 - * 改变这个值会触发场景中可渲染组件列表的排序。 - */ - layerDepth: number; - /** - * 较低的renderLayers在前面,较高的在后面,就像layerDepth一樣,但不是限制在0-1。 - * 请注意,这意味着更高的renderLayers首先被发送到Batcher。 - */ - renderLayer: number; - /** - * 渲染时传递给批处理程序的颜色 - */ - color: number; - /** - * 由渲染器使用,用于指定该精灵的渲染方式 - */ - material: IMaterial; - /** - * 偏移。用于将多个Renderables添加到需要特定定位的实体 - */ - localOffset: Vector2; - /** - * 这个Renderable的可见性。 - * 状态的改变最终会调用onBecameVisible/onBecameInvisible方法 - */ - isVisible: boolean; - constructor(); - debugRenderEnabled: boolean; - protected _localOffset: Vector2; - protected _layerDepth: number; - protected _renderLayer: number; - protected _bounds: Rectangle; - protected _isVisble: boolean; - protected _areBoundsDirty: boolean; - onEntityTransformChanged(comp: transform.Component): void; - /** - * 被渲染器调用。摄像机可以用来进行裁剪,并使用Batcher实例进行绘制 - * @param batcher - * @param camera - */ - abstract render(batcher: IBatcher, camera: ICamera): any; - /** - * 只有在没有对撞机的情况下才会渲染边界。始终在原点上渲染一个正方形 - * @param batcher - */ - debugRender(batcher: IBatcher): void; - /** - * 当Renderable进入相机帧时被调用。 - * 请注意,如果您的Renderer没有使用isVisibleFromCamera来进行裁剪检查,这些方法将不会被调用。 - * 所有默认的Renderer都会这样做 - */ - protected onBecameVisible(): void; - /** - * 当渲染器退出相机帧时,将调用这些方法。 - * 请注意,如果你的Renderer没有使用isVisibleFromCamera来进行Culling检查,这些方法将不会被调用。 - * 所有默认的Renderer都会这样做 - */ - protected onBecameInvisible(): void; - onRemovedFromEntity(): void; - /** - * 如果Renderables的边界与Camera.bounds相交,则返回true。 - * 处理isVisible标志的状态切换。在你的渲染方法中使用这个方法来决定你是否应该渲染 - * @param camera - */ - isVisibleFromCamera(camera: ICamera): boolean; - setMaterial(material: IMaterial): this; - /** - * 标准的Batcher图层深度,0为前面,1为后面。 - * 改变这个值会触发一种类似于renderableComponents的方法 - * @param layerDepth - */ - setLayerDepth(layerDepth: number): RenderableComponent; - /** - * 较低的渲染层在前面,较高的在后面 - * @param renderLayer - */ - setRenderLayer(renderLayer: number): RenderableComponent; - /** - * 偏移。用于将多个Renderables添加到需要特定定位的实体 - * @param offset - */ - setLocalOffset(offset: Vector2): RenderableComponent; - /** - * 用于检索一个已经铸造的Material子类的帮助程序 - */ - getMaterial(): T; - /** - * 先按renderLayer排序,再按layerDepth排序,最后按材质排序 - * @param other - */ - compare(other: RenderableComponent): 1 | -1 | 0; } } declare module es { @@ -1633,7 +1392,6 @@ declare module es { onEntityTransformChanged(comp: transform.Component): void; onEntityEnabled(): void; onEntityDisabled(): void; - debugRender(batcher: IBatcher): void; } } declare module es { @@ -1788,39 +1546,6 @@ declare module es { one(...types: any[]): this; } } -declare module es { - class RenderableComponentList { - static compareUpdatableOrder: IComparer; - /** - * 添加到实体的组件列表 - */ - private _components; - /** - * 通过renderLayer跟踪组件,便于检索 - */ - private _componentsByRenderLayer; - private _unsortedRenderLayers; - private _componentsNeedSort; - readonly count: number; - readonly buffer: IRenderable[]; - get(index: number): IRenderable; - add(component: IRenderable): void; - remove(component: IRenderable): void; - updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number): void; - /** - * 弄脏RenderLayers排序标志,导致所有组件的重新排序 - * @param renderLayer - */ - setRenderLayerNeedsComponentSort(renderLayer: number): void; - private addToRenderLayerList; - /** - * 获取所有给定renderLayer的组件。组件列表是预先排序的。 - * @param renderLayer - */ - componentsWithRenderLayer(renderLayer: number): IRenderable[]; - updateList(): void; - } -} declare class StringUtils { /** * 特殊符号字符串 @@ -2001,166 +1726,6 @@ declare class TimeUtils { */ static timeToMillisecond(time: string, partition?: string): string; } -declare module es { - interface IBatcher { - /** - * 创建投影矩阵时要使用的矩阵 - */ - transformMatrix: Matrix; - /** - * 如果为true,则将在绘制目标位置之前将其四舍五入 - */ - shouldRoundDestinations: boolean; - disposed(): any; - begin(id: Ref, effect: any, transformationMatrix?: Matrix, disableBatching?: boolean): any; - end(): any; - prepRenderState(): any; - /** - * 设置是否应忽略位置舍入。在为调试绘制基元时很有用 - */ - setIgnoreRoundingDestinations(shouldIgnore: boolean): any; - drawHollowRect(rect: Rectangle, color: number, thickness?: number): any; - drawHollowBounds(x: number, y: number, width: number, height: number, color: number, thickness: number): any; - drawLine(start: Vector2, end: Vector2, color: number, thickness: any): any; - draw(texture: any, position: Vector2, color?: number, rotation?: number, origin?: Vector2, scale?: Vector2, effects?: any): any; - drawPixel(position: Vector2, color: number, size?: number): any; - drawPolygon(position: Vector2, points: Vector2[], color: number, closePoly?: boolean, thickness?: number): any; - drawCircle(position: Vector2, radius: number, color: number, thickness?: number, resolution?: number): any; - } -} -declare module es { - interface ICamera extends Component { - position: Vector2; - rotation: number; - rawZoom: number; - zoom: number; - minimumZoom: number; - maximumZoom: number; - bounds: Rectangle; - transformMatrix: Matrix2D; - inverseTransformMatrix: Matrix2D; - projectionMatrix: Matrix; - viewprojectionMatrix: Matrix; - origin: Vector2; - setInset(left: number, right: number, top: number, bottom: number): ICamera; - setPosition(position: Vector2): ICamera; - setRotation(rotation: number): ICamera; - setZoom(zoom: number): ICamera; - setMinimumZoom(minZoom: number): ICamera; - setMaximumZoom(maxZoom: number): ICamera; - forceMatrixUpdate(): any; - onEntityTransformChanged(comp: transform.Component): any; - zoomIn(deltaZoom: number): any; - zoomOut(deltaZoom: number): any; - worldToScreenPoint(worldPosition: Vector2): Vector2; - screenToWorldPoint(screenPosition: Vector2): Vector2; - onSceneRenderTargetSizeChanged(newWidth: number, newHeight: number): any; - } -} -declare module es { - /** - * 可选接口,可以添加到任何对象中,用于特殊情况下需要覆盖最终渲染到屏幕。 - * 请注意,如果有IFinalRenderDelegate存在,Scene.screenshotRequestCallback将不会像预期的那样工作。 - */ - interface IFinalRenderDelegate { - /** - * 在添加到场景中时调用 - * @param scene - */ - onAddedToScene(scene: Scene): any; - /** - * 当后置缓冲区大小改变时调用 - * @param newWidth - * @param newHeight - */ - onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): any; - /** - * 这个被场景调用,这样就可以处理最终的渲染。渲染应该在finalRenderTarget中完成。 - * 在大多数情况下,finalRenderTarget将是空的,所以渲染将只是到回缓冲区。 - * finalRenderTarget只有在场景转换的第一帧时才会被设置,其中转换已经请求了上一个场景的渲染 - * @param finalRenderTarget - * @param source - * @param finalRenderDestinationRect - */ - handleFinalRender(finalRenderTarget: any, source: any, finalRenderDestinationRect: Rectangle): any; - /** - * 场景结束时调用。在这里释放任何资源 - */ - unload(): any; - } -} -declare module es { - /** - * 便利的子类,有一个单一的属性,可以投递Effect,使配置更简单 - */ - interface IMaterial { - /** - * Batcher为当前RenderableComponent使用的效果 - */ - effect: any; - dispose(): any; - onPreRender(camera: ICamera): any; - compareTo(other: IMaterial): number; - clone(): IMaterial; - } -} -declare module es { - interface IRenderer { - /** - * Batcher使用的材料。任何RenderableComponent都可以覆盖它 - */ - material: IMaterial; - /** - * 渲染器用于渲染的Camera(实际上是它的transformMatrix和culling的边界)。 - * 这是一个方便的字段,不是必需的。 - * 渲染器子类可以在调用beginRender时选择使用的摄像机 - */ - camera: ICamera; - /** - * 指定场景调用渲染器的顺序 - */ - renderOrder: number; - /** - * 如果renderTarget不是空的,这个渲染器将渲染到RenderTarget中,而不是渲染到屏幕上 - */ - renderTexture: any; - /** - * 标志,决定是否要调试渲染。 - * 渲染方法接收一个bool(debugRenderEnabled)让渲染器知道全局调试渲染是否开启/关闭。 - * 然后渲染器使用本地的bool来决定是否应该调试渲染 - */ - shouldDebugRender: boolean; - /** - * 如果为true,场景将使用场景RenderTarget调用SetRenderTarget。 - * 如果Renderer有一个renderTexture,默认的实现会返回true - */ - wantsToRenderToSceneRenderTarget: boolean; - /** - * 如果为true,场景将在所有后处理器完成后调用渲染方法。 - * 这必须在调用Scene.addRenderer生效之前设置为true,并且Renderer不应该有renderTexture。 - * 使用这种类型的渲染器的主要原因是为了让你可以在不进行后期处理的情况下,在Scene的其余部分上渲染你的UI。 - * ScreenSpaceRenderer是一个将此设置为真的Renderer例子 - */ - wantsToRenderAfterPostProcessors: boolean; - /** - * 当Renderer被添加到场景中时被调用 - * @param scene - */ - onAddedToScene(scene: Scene): any; - /** - * 当场景结束或该渲染器从场景中移除时,调用该函数,用于清理 - */ - unload(): any; - render(scene: Scene): any; - /** - * 当默认的场景RenderTarget被调整大小时,以及在场景已经开始的情况下添加一个Renderer时,会被调用。 - * @param newWidth - * @param newHeight - */ - onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): any; - compare(other: IRenderer): number; - } -} declare module es { /** * 三次方和二次方贝塞尔帮助器(cubic and quadratic bezier helper) @@ -3449,6 +3014,44 @@ declare module es { static boxToBoxCast(first: Box, second: Box, movement: Vector2, hit: RaycastHit): boolean; } } +declare module es { + /** + * 用于包装事件的一个小类 + */ + class FuncPack { + /** 函数 */ + func: Function; + /** 上下文 */ + context: any; + constructor(func: Function, context: any); + } + /** + * 用于事件管理 + */ + class Emitter { + private _messageTable; + constructor(); + /** + * 开始监听项 + * @param eventType 监听类型 + * @param handler 监听函数 + * @param context 监听上下文 + */ + addObserver(eventType: T, handler: Function, context: any): void; + /** + * 移除监听项 + * @param eventType 事件类型 + * @param handler 事件函数 + */ + removeObserver(eventType: T, handler: Function): void; + /** + * 触发该事件 + * @param eventType 事件类型 + * @param data 事件数据 + */ + emit(eventType: T, ...data: any[]): void; + } +} declare module es { enum Edge { top = 0, @@ -4773,7 +4376,7 @@ declare module es { * @param a * @param b */ - compare(a: EndPoint, b: EndPoint): 1 | -1 | 0; + compare(a: EndPoint, b: EndPoint): 0 | 1 | -1; } } declare module es { diff --git a/source/bin/framework.js b/source/bin/framework.js index b8fc58f4..2a369f48 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -1,23 +1,38 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); }; -var __spread = (this && this.__spread) || function () { - for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); - return ar; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } }; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || @@ -39,92 +54,199 @@ var __values = (this && this.__values) || function (o) { } }; }; +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +var __spread = (this && this.__spread) || function () { + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); + return ar; +}; var es; (function (es) { /** - * 用于包装事件的一个小类 + * 全局核心类 */ - var FuncPack = /** @class */ (function () { - function FuncPack(func, context) { - this.func = func; - this.context = context; - } - return FuncPack; - }()); - es.FuncPack = FuncPack; - /** - * 用于事件管理 - */ - var Emitter = /** @class */ (function () { - function Emitter() { - this._messageTable = new Map(); + var Core = /** @class */ (function () { + function Core(width, height, enableEntitySystems) { + if (enableEntitySystems === void 0) { enableEntitySystems = true; } + /** + * 全局访问系统 + */ + this._globalManagers = []; + this._coroutineManager = new es.CoroutineManager(); + this._timerManager = new es.TimerManager(); + this._frameCounterElapsedTime = 0; + this._frameCounter = 0; + this._totalMemory = 0; + this.width = width; + this.height = height; + Core._instance = this; + Core.emitter = new es.Emitter(); + Core.emitter.addObserver(es.CoreEvents.frameUpdated, this.update, this); + Core.registerGlobalManager(this._coroutineManager); + Core.registerGlobalManager(this._timerManager); + Core.entitySystemsEnabled = enableEntitySystems; + this.initialize(); } + Object.defineProperty(Core, "Instance", { + /** + * 提供对单例/游戏实例的访问 + * @constructor + */ + get: function () { + return this._instance; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Core, "scene", { + /** + * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 + */ + get: function () { + if (!this._instance) + return null; + return this._instance._scene; + }, + /** + * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 + * @param value + */ + set: function (value) { + if (!value) { + console.error("场景不能为空"); + return; + } + if (this._instance._scene == null) { + this._instance._scene = value; + this._instance.onSceneChanged(); + this._instance._scene.begin(); + } + else { + this._instance._nextScene = value; + } + }, + enumerable: true, + configurable: true + }); /** - * 开始监听项 - * @param eventType 监听类型 - * @param handler 监听函数 - * @param context 监听上下文 + * 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。 + * @param manager */ - Emitter.prototype.addObserver = function (eventType, handler, context) { - var list = this._messageTable.get(eventType); - if (!list) { - list = []; - this._messageTable.set(eventType, list); - } - if (list.findIndex(function (funcPack) { return funcPack.func == handler; }) != -1) - console.warn("您试图添加相同的观察者两次"); - list.push(new FuncPack(handler, context)); + Core.registerGlobalManager = function (manager) { + this._instance._globalManagers.push(manager); + manager.enabled = true; }; /** - * 移除监听项 - * @param eventType 事件类型 - * @param handler 事件函数 + * 删除全局管理器对象 + * @param manager */ - Emitter.prototype.removeObserver = function (eventType, handler) { - var messageData = this._messageTable.get(eventType); - var index = messageData.findIndex(function (data) { return data.func == handler; }); - if (index != -1) - new linq.List(messageData).removeAt(index); + Core.unregisterGlobalManager = function (manager) { + new linq.List(this._instance._globalManagers).remove(manager); + manager.enabled = false; }; /** - * 触发该事件 - * @param eventType 事件类型 - * @param data 事件数据 + * 获取类型为T的全局管理器 + * @param type */ - Emitter.prototype.emit = function (eventType) { - var data = []; - for (var _i = 1; _i < arguments.length; _i++) { - data[_i - 1] = arguments[_i]; + Core.getGlobalManager = function (type) { + for (var i = 0; i < this._instance._globalManagers.length; i++) { + if (this._instance._globalManagers[i] instanceof type) + return this._instance._globalManagers[i]; } - var _a; - var list = this._messageTable.get(eventType); - if (list) { - for (var i = list.length - 1; i >= 0; i--) - (_a = list[i].func).call.apply(_a, __spread([list[i].context], data)); + return null; + }; + /** + * 启动一个coroutine。Coroutine可以将number延时几秒或延时到其他startCoroutine.Yielding + * null将使coroutine在下一帧被执行。 + * @param enumerator + */ + Core.startCoroutine = function (enumerator) { + return this._instance._coroutineManager.startCoroutine(enumerator); + }; + /** + * 调度一个一次性或重复的计时器,该计时器将调用已传递的动作 + * @param timeInSeconds + * @param repeats + * @param context + * @param onTime + */ + Core.schedule = function (timeInSeconds, repeats, context, onTime) { + if (repeats === void 0) { repeats = false; } + if (context === void 0) { context = null; } + return this._instance._timerManager.schedule(timeInSeconds, repeats, context, onTime); + }; + Core.prototype.startDebugDraw = function () { + this._frameCounter++; + this._frameCounterElapsedTime += es.Time.deltaTime; + if (this._frameCounterElapsedTime >= 1) { + var memoryInfo = window.performance["memory"]; + if (memoryInfo != null) { + this._totalMemory = Number((memoryInfo.totalJSHeapSize / 1048576).toFixed(2)); + } + if (this._titleMemory) + this._titleMemory(this._totalMemory, this._frameCounter); + this._frameCounter = 0; + this._frameCounterElapsedTime -= 1; } }; - return Emitter; - }()); - es.Emitter = Emitter; -})(es || (es = {})); -/// -var es; -/// -(function (es) { - /** - * 这里作为框架的核心件 - * 全局函数移动到这 - */ - var Framework = /** @class */ (function () { - function Framework() { - } /** - * 核心发射器。只发出核心级别的事件 + * 在一个场景结束后,下一个场景开始之前调用 */ - Framework.emitter = new es.Emitter(); - return Framework; + Core.prototype.onSceneChanged = function () { + es.Time.sceneChanged(); + }; + Core.prototype.initialize = function () { + }; + Core.prototype.update = function (currentTime) { + return __awaiter(this, void 0, void 0, function () { + var i; + return __generator(this, function (_a) { + if (currentTime != null) + es.Time.update(currentTime); + if (this._scene != null) { + for (i = this._globalManagers.length - 1; i >= 0; i--) { + if (this._globalManagers[i].enabled) + this._globalManagers[i].update(); + } + this._scene.update(); + if (this._nextScene != null) { + this._scene.end(); + this._scene = this._nextScene; + this._nextScene = null; + this.onSceneChanged(); + this._scene.begin(); + } + } + this.startDebugDraw(); + return [2 /*return*/]; + }); + }); + }; + /** + * 启用/禁用焦点丢失时的暂停。如果为真,则不调用更新或渲染方法 + */ + Core.pauseOnFocusLost = true; + /** + * 是否启用调试渲染 + */ + Core.debugRenderEndabled = false; + return Core; }()); - es.Framework = Framework; + es.Core = Core; })(es || (es = {})); var es; (function (es) { @@ -319,8 +441,6 @@ var es; */ Component.prototype.onEntityTransformChanged = function (comp) { }; - Component.prototype.debugRender = function (batcher) { - }; /** *当父实体或此组件启用时调用 */ @@ -357,31 +477,14 @@ var es; (function (es) { var CoreEvents; (function (CoreEvents) { - /** - * 在图形设备重置时触发。当这种情况发生时,任何渲染目标或其他内容的VRAM将被擦除,需要重新生成 - */ - CoreEvents[CoreEvents["graphicsDeviceReset"] = 0] = "graphicsDeviceReset"; /** * 当场景发生变化时触发 */ - CoreEvents[CoreEvents["sceneChanged"] = 1] = "sceneChanged"; + CoreEvents[CoreEvents["sceneChanged"] = 0] = "sceneChanged"; /** - * 当设备方向改变时触发 + * 每帧更新事件 */ - CoreEvents[CoreEvents["orientationChanged"] = 2] = "orientationChanged"; - /** - * 当Core.useCustomUpdate为true时则派发该事件 - */ - CoreEvents[CoreEvents["sceneUpdated"] = 3] = "sceneUpdated"; - CoreEvents[CoreEvents["addDefaultRender"] = 4] = "addDefaultRender"; - CoreEvents[CoreEvents["setRenderTarget"] = 5] = "setRenderTarget"; - CoreEvents[CoreEvents["clearGraphics"] = 6] = "clearGraphics"; - CoreEvents[CoreEvents["disposeRenderTarget"] = 7] = "disposeRenderTarget"; - CoreEvents[CoreEvents["resolutionScale"] = 8] = "resolutionScale"; - CoreEvents[CoreEvents["resolutionOffset"] = 9] = "resolutionOffset"; - CoreEvents[CoreEvents["createRenderTarget"] = 10] = "createRenderTarget"; - CoreEvents[CoreEvents["createCamera"] = 11] = "createCamera"; - CoreEvents[CoreEvents["rendererSizeChanged"] = 12] = "rendererSizeChanged"; + CoreEvents[CoreEvents["frameUpdated"] = 1] = "frameUpdated"; })(CoreEvents = es.CoreEvents || (es.CoreEvents = {})); })(es || (es = {})); var es; @@ -743,13 +846,6 @@ var es; Entity.prototype.update = function () { this.components.update(); }; - /** - * 自定义渲染器可以选择是否调用它 - * @param batcher - */ - Entity.prototype.debugRender = function (batcher) { - this.components.debugRender(batcher); - }; /** * 将组件添加到组件列表中。返回组件。 * @param component @@ -1122,68 +1218,11 @@ var es; /** 场景 */ var Scene = /** @class */ (function () { function Scene() { - /** - * 如果ResolutionPolicy是完美的像素,这将被设置为为它计算的比例 - */ - this.pixelPerfectScale = 1; - /** - * 场景使用的设计分辨率大小 - */ - this._designResolutionSize = es.Vector2.zero; - this._designBleedSize = es.Vector2.zero; - /** - * 这将根据分辨率策略进行设置,并用于RenderTarget的最终输出 - */ - this._finalRenderDestinationRect = es.Rectangle.empty; - this._sceneRenderTarget = new es.Ref(null); - this._destinationRenderTarget = new es.Ref(null); this._sceneComponents = []; - this._renderers = []; - this._afterPostProcessorRenderers = []; - this.currentRenderId = new es.Ref(null); this.entities = new es.EntityList(this); - this.renderableComponents = new es.RenderableComponentList(); this.entityProcessors = new es.EntityProcessorList(); - es.Framework.emitter.emit(es.CoreEvents.createCamera, this); - this._resolutionPolicy = Scene._defaultSceneResolutionPolicy; - this._designResolutionSize = Scene._defaultDesignResolutionSize; - this._designBleedSize = Scene._defaultDesignBleedSize; this.initialize(); } - Object.defineProperty(Scene.prototype, "finalRenderDelegate", { - get: function () { - return this._finalRenderDelegate; - }, - /** - * 如果设置了,最终渲染到屏幕上的时间可以推迟到这个委托。 - * 这实际上只在最终渲染可能需要全屏大小效果的情况下有用,即使使用了一个小的后置缓冲区 - */ - set: function (value) { - if (this._finalRenderDelegate != null) - this._finalRenderDelegate.unload(); - this._finalRenderDelegate = value; - if (this._finalRenderDelegate != null) - this._finalRenderDelegate.onAddedToScene(this); - }, - enumerable: true, - configurable: true - }); - /** - * 设置新场景将使用的默认设计尺寸和分辨率策略,水平/垂直Bleed仅与BestFit相关 - * @param width - * @param height - * @param sceneResolutionPolicy - * @param horizontalBleed - * @param vertialcalBleed - */ - Scene.setDefaultDesignResolution = function (width, height, sceneResolutionPolicy, horizontalBleed, vertialcalBleed) { - if (horizontalBleed === void 0) { horizontalBleed = 0; } - if (vertialcalBleed === void 0) { vertialcalBleed = 0; } - this._defaultDesignBleedSize = new es.Vector2(width, height); - this._defaultSceneResolutionPolicy = sceneResolutionPolicy; - if (this._defaultSceneResolutionPolicy == SceneResolutionPolicy.bestFit) - this._defaultDesignBleedSize = new es.Vector2(horizontalBleed, vertialcalBleed); - }; /** * 在场景子类中重写这个,然后在这里进行加载。 * 在场景设置好之后,但在调用begin之前,从contructor中调用这个函数 @@ -1202,15 +1241,7 @@ var es; Scene.prototype.unload = function () { }; Scene.prototype.begin = function () { - if (this._renderers.length == 0) { - es.Framework.emitter.emit(es.CoreEvents.addDefaultRender); - console.warn("场景开始时没有渲染器"); - } es.Physics.reset(); - this.updateResolutionScaler(); - es.Framework.emitter.emit(es.CoreEvents.setRenderTarget, this._sceneRenderTarget); - es.Framework.emitter.addObserver(es.CoreEvents.graphicsDeviceReset, this.updateResolutionScaler, this); - es.Framework.emitter.addObserver(es.CoreEvents.orientationChanged, this.updateResolutionScaler, this); if (this.entityProcessors != null) this.entityProcessors.begin(); this._didSceneBegin = true; @@ -1218,99 +1249,17 @@ var es; }; Scene.prototype.end = function () { this._didSceneBegin = false; - for (var i = 0; i < this._renderers.length; i++) - this._renderers[i].unload(); - es.Framework.emitter.removeObserver(es.CoreEvents.graphicsDeviceReset, this.updateResolutionScaler); this.entities.removeAllEntities(); for (var i = 0; i < this._sceneComponents.length; i++) { this._sceneComponents[i].onRemovedFromScene(); } this._sceneComponents.length = 0; - this.camera = null; - es.Framework.emitter.emit(es.CoreEvents.disposeRenderTarget, this._sceneRenderTarget); - es.Framework.emitter.emit(es.CoreEvents.disposeRenderTarget, this._destinationRenderTarget); es.Physics.clear(); if (this.entityProcessors) this.entityProcessors.end(); this.unload(); }; - Scene.prototype.updateResolutionScaler = function () { - var designSize = this._designResolutionSize; - var screenSize = new es.Vector2(es.Screen.width, es.Screen.height); - var screenAspectRatio = screenSize.x / screenSize.y; - var renderTargetWidth = screenSize.x; - var renderTargetHeight = screenSize.y; - var resolutionScaleX = screenSize.x / designSize.x; - var resolutionScaleY = screenSize.y / designSize.y; - var rectCalculated = false; - // 计算PixelPerfect变体所使用的比例 - this.pixelPerfectScale = 1; - if (this._resolutionPolicy != SceneResolutionPolicy.none) { - if (designSize.x / designSize.y > screenAspectRatio) - this.pixelPerfectScale = screenSize.x / designSize.x; - else - this.pixelPerfectScale = screenSize.y / designSize.y; - if (this.pixelPerfectScale == 0) - this.pixelPerfectScale = 1; - } - switch (this._resolutionPolicy) { - case SceneResolutionPolicy.none: - this._finalRenderDestinationRect.x = this._finalRenderDestinationRect.y = 0; - this._finalRenderDestinationRect.width = screenSize.x; - this._finalRenderDestinationRect.height = screenSize.y; - rectCalculated = true; - break; - case SceneResolutionPolicy.bestFit: - var safeScaleX = screenSize.x / (designSize.x - this._designBleedSize.x); - var safeScaleY = screenSize.y / (designSize.y - this._designBleedSize.y); - var resolutionScale = Math.max(resolutionScaleX, resolutionScaleY); - var safeScale = Math.min(safeScaleX, safeScaleY); - resolutionScaleX = resolutionScaleY = Math.min(resolutionScale, safeScale); - renderTargetWidth = designSize.x; - renderTargetHeight = designSize.y; - break; - } - // 如果我们还没有计算出一个矩形 - if (!rectCalculated) { - // 计算RenderTarget的显示矩形 - var renderWidth = designSize.x * resolutionScaleX; - var renderHeight = designSize.y * resolutionScaleY; - this._finalRenderDestinationRect = new es.Rectangle((screenSize.x - renderWidth) / 2, (screenSize.y - renderHeight) / 2, renderWidth, renderHeight); - } - // 在Input类中设置一些值,将鼠标位置转换为我们的缩放分辨率 - var scaleX = renderTargetWidth / this._finalRenderDestinationRect.width; - var scaleY = renderTargetHeight / this._finalRenderDestinationRect.height; - es.Framework.emitter.emit(es.CoreEvents.resolutionScale, new es.Vector2(scaleX, scaleY)); - es.Framework.emitter.emit(es.CoreEvents.resolutionOffset, this._finalRenderDestinationRect.location); - // 调整我们的RenderTargets大小 - if (this._sceneRenderTarget != null) - es.Framework.emitter.emit(es.CoreEvents.disposeRenderTarget, this._sceneRenderTarget); - es.Framework.emitter.emit(es.CoreEvents.createRenderTarget, this._sceneRenderTarget, renderTargetWidth, renderTargetHeight); - // 只有在已经存在的情况下才会创建 destinationRenderTarget - if (this._destinationRenderTarget != null) { - es.Framework.emitter.emit(es.CoreEvents.disposeRenderTarget, this._destinationRenderTarget); - es.Framework.emitter.emit(es.CoreEvents.createRenderTarget, this._destinationRenderTarget, renderTargetWidth, renderTargetHeight); - } - // 通知渲染器、后处理器和FinalRenderDelegate渲染纹理尺寸的变化 - for (var i = 0; i < this._renderers.length; i++) - this._renderers[i].onSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight); - for (var i = 0; i < this._afterPostProcessorRenderers.length; i++) - this._afterPostProcessorRenderers[i].onSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight); - if (this._finalRenderDelegate != null) - this._finalRenderDelegate.onSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight); - this.camera.onSceneRenderTargetSizeChanged(renderTargetWidth, renderTargetHeight); - }; - /** - * 下一次绘制完成后,这将克隆回缓冲区,并调用回调与clone。 - * 注意,当使用完Texture后,你必须处理掉它 - * @param callback - */ - Scene.prototype.requestScreenshot = function (callback) { - this._screenshotRequestCallback = callback; - }; Scene.prototype.update = function () { - // 我们在这里设置RenderTarget,这样Viewport就会与RenderTarget正确匹配 - es.Framework.emitter.emit(es.CoreEvents.setRenderTarget, this._sceneRenderTarget); // 更新我们的列表,以防它们有任何变化 this.entities.updateLists(); for (var i = this._sceneComponents.length - 1; i >= 0; i--) { @@ -1322,76 +1271,9 @@ var es; this.entityProcessors.update(); // 更新我们的实体组 this.entities.update(); - // 我们在entity.update之后更新我们的renderables,以防止任何新的Renderables被添加 - this.renderableComponents.updateList(); if (this.entityProcessors != null) this.entityProcessors.lateUpdate(); }; - Scene.prototype.render = function () { - if (this._renderers.length == 0) { - console.error("场景中没有渲染器!"); - return; - } - // 渲染器应该总是先有那些需要RenderTarget的。 - // 他们在渲染的时候会自己清空并设置自己为当前的RenderTarget。 - // 如果第一个Renderer想要sceneRenderTarget,我们现在就设置并清除它 - if (this._renderers[0].wantsToRenderToSceneRenderTarget) { - es.Framework.emitter.emit(es.CoreEvents.setRenderTarget, this._sceneRenderTarget); - es.Framework.emitter.emit(es.CoreEvents.clearGraphics); - } - var lastRendererHadRenderTarget = false; - for (var i = 0; i < this._renderers.length; i++) { - if (lastRendererHadRenderTarget && this._renderers[i].wantsToRenderToSceneRenderTarget) { - es.Framework.emitter.emit(es.CoreEvents.setRenderTarget, this._sceneRenderTarget); - es.Framework.emitter.emit(es.CoreEvents.clearGraphics); - // 强制更新相机矩阵,以考虑到新的视口尺寸 - if (this._renderers[i].camera != null) - this._renderers[i].camera.forceMatrixUpdate(); - this.camera && this.camera.forceMatrixUpdate(); - } - this._renderers[i].render(this); - lastRendererHadRenderTarget = this._renderers[i].renderTexture != null; - } - }; - /** - * 任何存在的PostProcessors都可以进行处理,然后我们对RenderTarget进行最后的渲染。 - * 几乎在所有情况下,finalRenderTarget都是空的。 - * 只有在场景转换的第一帧中,如果转换请求渲染,它才会有一个值。 - * @param finalRenderTarget - */ - Scene.prototype.postRender = function (finalRenderTarget) { - if (finalRenderTarget === void 0) { finalRenderTarget = null; } - var enabledCounter = 0; - for (var i = 0; i < this._afterPostProcessorRenderers.length; i++) { - if (i == 0) { - // 我们需要在这里设置正确的RenderTarget - var currentRenderTarget = es.MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget; - es.Framework.emitter.emit(es.CoreEvents.setRenderTarget, currentRenderTarget); - } - if (this._afterPostProcessorRenderers[i].camera != null) - this._afterPostProcessorRenderers[i].camera.forceMatrixUpdate(); - this._afterPostProcessorRenderers[i].render(this); - } - // 如果我们有一个截图请求,在最终渲染到回缓冲区之前处理它 - if (this._screenshotRequestCallback != null) { - var currentRenderTarget = es.MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget; - this._screenshotRequestCallback(currentRenderTarget.value); - this._screenshotRequestCallback = null; - } - // 将我们的最终结果渲染到后置缓冲区,或者让我们的委托来做 - if (this._finalRenderDelegate != null) { - var currentRenderTarget = es.MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget; - this._finalRenderDelegate.handleFinalRender(finalRenderTarget, currentRenderTarget, this._finalRenderDestinationRect); - } - else { - var currentRenderTarget = es.MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget; - es.Framework.emitter.emit(es.CoreEvents.setRenderTarget, finalRenderTarget); - es.Framework.emitter.emit(es.CoreEvents.clearGraphics); - es.Framework.batcher.begin(this.currentRenderId, null); - es.Framework.batcher.draw(currentRenderTarget.value, new es.Vector2(this._finalRenderDestinationRect.x, this._finalRenderDestinationRect.y), 0xffffff, 0, es.Vector2.zero, new es.Vector2(this._finalRenderDestinationRect.width, this._finalRenderDestinationRect.height)); - es.Framework.batcher.end(); - } - }; /** * 向组件列表添加并返回SceneComponent * @param component @@ -1437,58 +1319,6 @@ var es; new linq.List(this._sceneComponents).remove(component); component.onRemovedFromScene(); }; - /** - * 添加一个渲染器到场景中 - * @param renderer - */ - Scene.prototype.addRenderer = function (renderer) { - if (renderer.wantsToRenderAfterPostProcessors) { - this._afterPostProcessorRenderers.push(renderer); - this._afterPostProcessorRenderers.sort(function (a, b) { - return a.compare(b); - }); - } - else { - this._renderers.push(renderer); - this._renderers.sort(function (a, b) { - return a.compare(b); - }); - } - renderer.onAddedToScene(this); - if (this._didSceneBegin) - es.Framework.emitter.emit(es.CoreEvents.rendererSizeChanged, this._sceneRenderTarget.value); - return renderer; - }; - /** - * 得到第一个T型的渲染器 - * @param type - */ - Scene.prototype.getRenderer = function (type) { - for (var i = 0; i < this._renderers.length; i++) { - if (this._renderers[i] instanceof type) - return this._renderers[i]; - } - for (var i = 0; i < this._afterPostProcessorRenderers.length; i++) { - if (this._afterPostProcessorRenderers[i] instanceof type) - return this._afterPostProcessorRenderers[i]; - } - return null; - }; - /** - * 从场景中移除渲染器 - * @param renderer - */ - Scene.prototype.removeRenderer = function (renderer) { - var afterProcessLinqList = new linq.List(this._afterPostProcessorRenderers); - var rendererLinqList = new linq.List(this._renderers); - es.Insist.isTrue(rendererLinqList.contains(renderer) || - afterProcessLinqList.contains(renderer)); - if (renderer.wantsToRenderAfterPostProcessors) - afterProcessLinqList.remove(renderer); - else - rendererLinqList.remove(renderer); - renderer.unload(); - }; /** * 将实体添加到此场景,并返回它 * @param name @@ -1574,15 +1404,6 @@ var es; Scene.prototype.getEntityProcessor = function () { return this.entityProcessors.getProcessor(); }; - /** - * 所有场景的默认分辨率大小 - */ - Scene._defaultDesignResolutionSize = es.Vector2.zero; - Scene._defaultDesignBleedSize = es.Vector2.zero; - /** - * 用于所有场景的默认分辨率策略 - */ - Scene._defaultSceneResolutionPolicy = SceneResolutionPolicy.none; return Scene; }()); es.Scene = Scene; @@ -2742,28 +2563,6 @@ var es; return this; }; Collider.prototype.onAddedToEntity = function () { - if (this._colliderRequiresAutoSizing) { - es.Insist.isTrue(this instanceof es.BoxCollider || this instanceof es.CircleCollider, "只有框和圆的碰撞器可以自动创建"); - var renderable = this.entity.getComponent(es.RenderableComponent); - if (renderable == null) - console.warn("Collider没有形状,也没有RenderableComponent。不知道如何确定它的大小。"); - if (renderable != null) { - var renderableBounds = renderable.bounds.clone(); - // 我们在这里需要大小*反比例,因为当我们自动调整Collider的大小时,它需要没有一个缩放的Renderable - var width = renderableBounds.width / this.entity.transform.scale.x; - var height = renderableBounds.height / this.entity.transform.scale.y; - if (this instanceof es.CircleCollider) { - this.radius = Math.max(width, height) * 0.5; - // 获取Renderable的中心,将其转移到本地坐标,并将其作为我们碰撞器的localOffset - this.localOffset = es.Vector2.subtract(renderableBounds.center, this.entity.transform.position); - } - else if (this instanceof es.BoxCollider) { - this.width = width; - this.height = height; - this.localOffset = es.Vector2.subtract(renderableBounds.center, this.entity.transform.position); - } - } - } this._isParentEntityAddedToScene = true; this.registerColliderWithPhysicsSystem(); }; @@ -2941,13 +2740,6 @@ var es; es.Physics.updateCollider(this); } }; - BoxCollider.prototype.debugRender = function (batcher) { - var poly = this.shape; - batcher.drawHollowRect(this.bounds, es.Debug.colliderBounds, 1); - batcher.drawPolygon(this.shape.position, poly.points, es.Debug.colliderEdge, true, 1); - batcher.drawPixel(this.entity.transform.position, es.Debug.colliderPosition, 4); - batcher.drawPixel(es.Vector2.add(this.entity.transform.position, this.shape.center), es.Debug.colliderCenter, 2); - }; BoxCollider.prototype.toString = function () { return "[BoxCollider: bounds: " + this.bounds + "]"; }; @@ -2997,12 +2789,6 @@ var es; } return this; }; - CircleCollider.prototype.debugRender = function (batcher) { - batcher.drawHollowRect(this.bounds, es.Debug.colliderBounds, 1); - batcher.drawCircle(this.shape.position, this.shape.radius, es.Debug.colliderEdge, 1); - batcher.drawPixel(this.entity.transform.position, es.Debug.colliderPosition, 4); - batcher.drawPixel(this.shape.position, es.Debug.colliderCenter, 2); - }; CircleCollider.prototype.toString = function () { return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]"; }; @@ -3035,237 +2821,11 @@ var es; _this.shape = new es.Polygon(points); return _this; } - PolygonCollider.prototype.debugRender = function (batcher) { - var poly = this.shape; - batcher.drawHollowRect(this.bounds, es.Debug.colliderBounds, 1); - batcher.drawPolygon(this.shape.position, poly.points, es.Debug.colliderEdge, true, 1); - batcher.drawPixel(this.entity.transform.position, es.Debug.colliderPosition, 4); - batcher.drawPixel(this.shape.position, es.Debug.colliderCenter, 2); - }; return PolygonCollider; }(es.Collider)); es.PolygonCollider = PolygonCollider; })(es || (es = {})); var es; -(function (es) { - /** - * 对IRenderables进行排序的比较器。 - * 首先按 RenderLayer 排序,然后按 LayerDepth 排序。 - * 如果出现平局,则使用材料作为平局的断定器,以避免渲染状态的改变 - */ - var RenderableComparer = /** @class */ (function () { - function RenderableComparer() { - } - RenderableComparer.prototype.compare = function (self, other) { - var res = other.renderLayer - self.renderLayer; - if (res == 0) { - res = other.layerDepth - self.layerDepth; - if (res == 0) { - if (self.material == other.material) - return 0; - if (other.material == null) - return -1; - return 1; - } - } - return res; - }; - return RenderableComparer; - }()); - es.RenderableComparer = RenderableComparer; -})(es || (es = {})); -var es; -(function (es) { - /** - * IRenderable的具体实现。包含方便的方法。 - * 非常重要!子类必须覆盖width/height或bounds! 子类必须覆盖width/height或bounds! - */ - var RenderableComponent = /** @class */ (function (_super) { - __extends(RenderableComponent, _super); - function RenderableComponent() { - var _this = _super.call(this) || this; - /** - * 渲染时传递给批处理程序的颜色 - */ - _this.color = 0xffffff; - _this.debugRenderEnabled = true; - _this._localOffset = es.Vector2.zero; - _this._bounds = es.Rectangle.empty; - _this._areBoundsDirty = true; - return _this; - } - Object.defineProperty(RenderableComponent.prototype, "layerDepth", { - /** - * 标准的Batcher图层深度,0为前面,1为后面。 - * 改变这个值会触发场景中可渲染组件列表的排序。 - */ - get: function () { - return this._layerDepth; - }, - set: function (value) { - this.setLayerDepth(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "renderLayer", { - /** - * 较低的renderLayers在前面,较高的在后面,就像layerDepth一樣,但不是限制在0-1。 - * 请注意,这意味着更高的renderLayers首先被发送到Batcher。 - */ - get: function () { - return this._renderLayer; - }, - set: function (value) { - this.setRenderLayer(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "localOffset", { - /** - * 偏移。用于将多个Renderables添加到需要特定定位的实体 - */ - get: function () { - return this._localOffset; - }, - set: function (value) { - this.setLocalOffset(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "isVisible", { - /** - * 这个Renderable的可见性。 - * 状态的改变最终会调用onBecameVisible/onBecameInvisible方法 - */ - get: function () { - return this._isVisble; - }, - set: function (value) { - if (this._isVisble != value) { - this._isVisble = value; - if (this._isVisble) - this.onBecameVisible(); - else - this.onBecameInvisible(); - } - }, - enumerable: true, - configurable: true - }); - RenderableComponent.prototype.onEntityTransformChanged = function (comp) { - this._areBoundsDirty = true; - }; - /** - * 只有在没有对撞机的情况下才会渲染边界。始终在原点上渲染一个正方形 - * @param batcher - */ - RenderableComponent.prototype.debugRender = function (batcher) { - if (!this.debugRenderEnabled) - return; - // 如果我们没有对撞机,我们就画出我们的范围 - if (this.entity.getComponent(es.Collider) == null) - batcher.drawHollowRect(this.bounds, 0xFFFF00); - batcher.drawPixel(this.entity.transform.position.add(this._localOffset), 0xcc3299, 4); - }; - /** - * 当Renderable进入相机帧时被调用。 - * 请注意,如果您的Renderer没有使用isVisibleFromCamera来进行裁剪检查,这些方法将不会被调用。 - * 所有默认的Renderer都会这样做 - */ - RenderableComponent.prototype.onBecameVisible = function () { - }; - /** - * 当渲染器退出相机帧时,将调用这些方法。 - * 请注意,如果你的Renderer没有使用isVisibleFromCamera来进行Culling检查,这些方法将不会被调用。 - * 所有默认的Renderer都会这样做 - */ - RenderableComponent.prototype.onBecameInvisible = function () { - }; - RenderableComponent.prototype.onRemovedFromEntity = function () { - }; - /** - * 如果Renderables的边界与Camera.bounds相交,则返回true。 - * 处理isVisible标志的状态切换。在你的渲染方法中使用这个方法来决定你是否应该渲染 - * @param camera - */ - RenderableComponent.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = camera.bounds.intersects(this.bounds); - return this.isVisible; - }; - RenderableComponent.prototype.setMaterial = function (material) { - this.material = material; - if (this.entity != null && this.entity.scene != null) - this.entity.scene.renderableComponents.setRenderLayerNeedsComponentSort(this.renderLayer); - return this; - }; - /** - * 标准的Batcher图层深度,0为前面,1为后面。 - * 改变这个值会触发一种类似于renderableComponents的方法 - * @param layerDepth - */ - RenderableComponent.prototype.setLayerDepth = function (layerDepth) { - this._layerDepth = es.MathHelper.clamp01(layerDepth); - if (this.entity != null && this.entity.scene != null) - this.entity.scene.renderableComponents.setRenderLayerNeedsComponentSort(this.renderLayer); - return this; - }; - /** - * 较低的渲染层在前面,较高的在后面 - * @param renderLayer - */ - RenderableComponent.prototype.setRenderLayer = function (renderLayer) { - if (renderLayer != this._renderLayer) { - var oldRenderLayer = this._renderLayer; - this._renderLayer = renderLayer; - // 如果该组件拥有一个实体,那么是由ComponentList管理,需要通知它改变了渲染层 - if (this.entity && this.entity.scene) - this.entity.scene.renderableComponents.updateRenderableRenderLayer(this, oldRenderLayer, this._renderLayer); - } - return this; - }; - /** - * 偏移。用于将多个Renderables添加到需要特定定位的实体 - * @param offset - */ - RenderableComponent.prototype.setLocalOffset = function (offset) { - if (!this._localOffset.equals(offset)) { - this._localOffset = offset; - this._areBoundsDirty = true; - } - return this; - }; - /** - * 用于检索一个已经铸造的Material子类的帮助程序 - */ - RenderableComponent.prototype.getMaterial = function () { - return this.material; - }; - /** - * 先按renderLayer排序,再按layerDepth排序,最后按材质排序 - * @param other - */ - RenderableComponent.prototype.compare = function (other) { - var res = other.renderLayer - this.renderLayer; - if (res == 0) { - res = other.layerDepth - this.layerDepth; - if (res == 0) { - if (this.material == other.material) - return 0; - if (other.material == null) - return -1; - return 1; - } - } - }; - RenderableComponent.renderIdGenerator = 0; - return RenderableComponent; - }(es.Component)); - es.RenderableComponent = RenderableComponent; -})(es || (es = {})); -var es; (function (es) { /** * 追踪实体的子集,但不实现任何排序或迭代。 @@ -3601,8 +3161,6 @@ var es; var component = _c.value; if (!component) continue; - if (component instanceof es.RenderableComponent) - new linq.List(this._entity.scene.renderableComponents.buffer).remove(component); // 处理IUpdatable if (es.isIUpdatable(component)) new linq.List(this._updatableComponents).remove(component); @@ -3623,8 +3181,6 @@ var es; try { for (var _b = __values(this._components), _c = _b.next(); !_c.done; _c = _b.next()) { var component = _c.value; - if (component instanceof es.RenderableComponent) - this._entity.scene.renderableComponents.buffer.push(component); if (es.isIUpdatable(component)) this._updatableComponents.push(component); this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component))); @@ -3653,8 +3209,6 @@ var es; if (this._componentsToAdd.length > 0) { for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { var component = this._componentsToAdd[i]; - if (component instanceof es.RenderableComponent) - this._entity.scene.renderableComponents.buffer.push(component); if (es.isIUpdatable(component)) this._updatableComponents.push(component); this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component))); @@ -3682,8 +3236,6 @@ var es; } }; ComponentList.prototype.handleRemove = function (component) { - if (component instanceof es.RenderableComponent) - new linq.List(this._entity.scene.renderableComponents.buffer).remove(component); if (es.isIUpdatable(component)) new linq.List(this._updatableComponents).remove(component); this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)), false); @@ -3800,12 +3352,6 @@ var es; for (var i = 0; i < this._components.length; i++) this._components[i].onDisabled(); }; - ComponentList.prototype.debugRender = function (batcher) { - for (var i = 0; i < this._components.length; i++) { - if (this._components[i].enabled) - this._components[i].debugRender(batcher); - } - }; /** * 组件列表的全局updateOrder排序 */ @@ -4320,98 +3866,6 @@ var es; }()); es.Matcher = Matcher; })(es || (es = {})); -var es; -(function (es) { - var RenderableComponentList = /** @class */ (function () { - function RenderableComponentList() { - /** - * 添加到实体的组件列表 - */ - this._components = []; - /** - * 通过renderLayer跟踪组件,便于检索 - */ - this._componentsByRenderLayer = new Map(); - this._unsortedRenderLayers = []; - this._componentsNeedSort = true; - } - Object.defineProperty(RenderableComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true - }); - RenderableComponentList.prototype.get = function (index) { - return this._components[index]; - }; - RenderableComponentList.prototype.add = function (component) { - this._components.push(component); - this.addToRenderLayerList(component, component.renderLayer); - }; - RenderableComponentList.prototype.remove = function (component) { - new linq.List(this._components).remove(component); - new linq.List(this._componentsByRenderLayer.get(component.renderLayer)).remove(component); - }; - RenderableComponentList.prototype.updateRenderableRenderLayer = function (component, oldRenderLayer, newRenderLayer) { - // 需要注意的是,在组件 "上线 "之前,renderLayer可能会发生变化 - if (this._componentsByRenderLayer.has(oldRenderLayer) && - new linq.List(this._componentsByRenderLayer.get(oldRenderLayer)).contains(component)) { - new linq.List(this._componentsByRenderLayer.get(oldRenderLayer)).remove(component); - this.addToRenderLayerList(component, newRenderLayer); - } - }; - /** - * 弄脏RenderLayers排序标志,导致所有组件的重新排序 - * @param renderLayer - */ - RenderableComponentList.prototype.setRenderLayerNeedsComponentSort = function (renderLayer) { - if (!new linq.List(this._unsortedRenderLayers).contains(renderLayer)) - this._unsortedRenderLayers.push(renderLayer); - this._componentsNeedSort = true; - }; - RenderableComponentList.prototype.addToRenderLayerList = function (component, renderLayer) { - var list = this.componentsWithRenderLayer(renderLayer); - es.Insist.isFalse(new linq.List(list).contains(component), "组件renderLayer列表已经包含这个组件"); - }; - /** - * 获取所有给定renderLayer的组件。组件列表是预先排序的。 - * @param renderLayer - */ - RenderableComponentList.prototype.componentsWithRenderLayer = function (renderLayer) { - if (!this._componentsByRenderLayer.has(renderLayer)) { - this._componentsByRenderLayer.set(renderLayer, []); - } - return this._componentsByRenderLayer.get(renderLayer); - }; - RenderableComponentList.prototype.updateList = function () { - if (this._componentsNeedSort) { - this._components.sort(RenderableComponentList.compareUpdatableOrder.compare); - this._componentsNeedSort = false; - } - if (this._unsortedRenderLayers.length > 0) { - for (var i = 0, count = this._unsortedRenderLayers.length; i < count; i++) { - var renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]); - if (renderLayerComponents) { - renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare); - } - } - this._unsortedRenderLayers.length = 0; - } - }; - // IRenderable列表的全局updateOrder排序 - RenderableComponentList.compareUpdatableOrder = new es.RenderableComparer(); - return RenderableComponentList; - }()); - es.RenderableComponentList = RenderableComponentList; -})(es || (es = {})); var StringUtils = /** @class */ (function () { function StringUtils() { } @@ -8204,6 +7658,74 @@ var es; es.ShapeCollisions = ShapeCollisions; })(es || (es = {})); var es; +(function (es) { + /** + * 用于包装事件的一个小类 + */ + var FuncPack = /** @class */ (function () { + function FuncPack(func, context) { + this.func = func; + this.context = context; + } + return FuncPack; + }()); + es.FuncPack = FuncPack; + /** + * 用于事件管理 + */ + var Emitter = /** @class */ (function () { + function Emitter() { + this._messageTable = new Map(); + } + /** + * 开始监听项 + * @param eventType 监听类型 + * @param handler 监听函数 + * @param context 监听上下文 + */ + Emitter.prototype.addObserver = function (eventType, handler, context) { + var list = this._messageTable.get(eventType); + if (!list) { + list = []; + this._messageTable.set(eventType, list); + } + if (list.findIndex(function (funcPack) { return funcPack.func == handler; }) != -1) + console.warn("您试图添加相同的观察者两次"); + list.push(new FuncPack(handler, context)); + }; + /** + * 移除监听项 + * @param eventType 事件类型 + * @param handler 事件函数 + */ + Emitter.prototype.removeObserver = function (eventType, handler) { + var messageData = this._messageTable.get(eventType); + var index = messageData.findIndex(function (data) { return data.func == handler; }); + if (index != -1) + new linq.List(messageData).removeAt(index); + }; + /** + * 触发该事件 + * @param eventType 事件类型 + * @param data 事件数据 + */ + Emitter.prototype.emit = function (eventType) { + var data = []; + for (var _i = 1; _i < arguments.length; _i++) { + data[_i - 1] = arguments[_i]; + } + var _a; + var list = this._messageTable.get(eventType); + if (list) { + for (var i = list.length - 1; i >= 0; i--) + (_a = list[i].func).call.apply(_a, __spread([list[i].context], data)); + } + }; + return Emitter; + }()); + es.Emitter = Emitter; +})(es || (es = {})); +var es; (function (es) { var Edge; (function (Edge) { diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index e8e97d19..68fdb10f 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.es={};var __read=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}};!function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&new linq.List(n).removeAt(i)},t.prototype.emit=function(t){for(var e,n=[],i=1;i=0;o--)(e=r[o].func).call.apply(e,__spread([r[o].context],n))},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function e(){}return e.emitter=new t.Emitter,e}();t.Framework=e}(es||(es={})),function(t){var e=function(){function t(){}return t.debugText=16777215,t.colliderBounds=5033164.5,t.colliderEdge=9109504,t.colliderPosition=16776960,t.colliderCenter=16711680,t.renderableBounds=16776960,t.renderableCenter=10040012,t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.fail=function(t){void 0===t&&(t=null);for(var e=[],n=1;n=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;tr?this.pixelPerfectScale=i.x/n.x:this.pixelPerfectScale=i.y/n.y,0==this.pixelPerfectScale&&(this.pixelPerfectScale=1)),this._resolutionPolicy){case e.none:this._finalRenderDestinationRect.x=this._finalRenderDestinationRect.y=0,this._finalRenderDestinationRect.width=i.x,this._finalRenderDestinationRect.height=i.y,h=!0;break;case e.bestFit:var u=i.x/(n.x-this._designBleedSize.x),l=i.y/(n.y-this._designBleedSize.y),p=Math.max(a,c),f=Math.min(u,l);a=c=Math.min(p,f),o=n.x,s=n.y}if(!h){var d=n.x*a,m=n.y*c;this._finalRenderDestinationRect=new t.Rectangle((i.x-d)/2,(i.y-m)/2,d,m)}var y=o/this._finalRenderDestinationRect.width,g=s/this._finalRenderDestinationRect.height;t.Framework.emitter.emit(t.CoreEvents.resolutionScale,new t.Vector2(y,g)),t.Framework.emitter.emit(t.CoreEvents.resolutionOffset,this._finalRenderDestinationRect.location),null!=this._sceneRenderTarget&&t.Framework.emitter.emit(t.CoreEvents.disposeRenderTarget,this._sceneRenderTarget),t.Framework.emitter.emit(t.CoreEvents.createRenderTarget,this._sceneRenderTarget,o,s),null!=this._destinationRenderTarget&&(t.Framework.emitter.emit(t.CoreEvents.disposeRenderTarget,this._destinationRenderTarget),t.Framework.emitter.emit(t.CoreEvents.createRenderTarget,this._destinationRenderTarget,o,s));for(var _=0;_=0;e--)this._sceneComponents[e].enabled&&this._sceneComponents[e].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),this.renderableComponents.updateList(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate()},n.prototype.render=function(){if(0!=this._renderers.length){this._renderers[0].wantsToRenderToSceneRenderTarget&&(t.Framework.emitter.emit(t.CoreEvents.setRenderTarget,this._sceneRenderTarget),t.Framework.emitter.emit(t.CoreEvents.clearGraphics));for(var e=!1,n=0;ne.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(null!=this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.createRotation(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.createScale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(this._translationMatrix),null==this.parent&&(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),null!=this.parent&&(this._worldTransform=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}for(var n=0;n0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e,t.isIUpdatable=function(t){return void 0!==t.update}}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(){function t(){this.updateOrder=0,this._enabled=!0}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onRemovedFromScene=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this.updateOrder!=t&&(this.updateOrder=t),this},t.prototype.compare=function(t){return this.updateOrder-t.updateOrder},t}();t.SceneComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=e.call(this)||this;return n.shouldUseGravity=!0,n.velocity=new t.Vector2,n._mass=10,n._elasticity=.5,n._friction=.5,n._glue=.01,n._inverseMass=0,n._inverseMass=1/n._mass,n}return __extends(n,e),Object.defineProperty(n.prototype,"mass",{get:function(){return this._mass},set:function(t){this.setMass(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"elasticity",{get:function(){return this._elasticity},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"elasticiy",{set:function(t){this.setElasticity(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"friction",{get:function(){return this._friction},set:function(t){this.setFriction(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"glue",{get:function(){return this._glue},set:function(t){this.setGlue(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isImmovable",{get:function(){return this._mass<1e-4},enumerable:!0,configurable:!0}),n.prototype.setMass=function(e){return this._mass=t.MathHelper.clamp(e,0,Number.MAX_VALUE),this._mass>1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},n.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},n.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},n.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},n.prototype.addImpulse=function(e){this.isImmovable||(this.velocity=t.Vector2.add(this.velocity,t.Vector2.multiply(e,new t.Vector2(1e5)).multiply(new t.Vector2(this._inverseMass*t.Time.deltaTime))))},n.prototype.onAddedToEntity=function(){this._collider=this.entity.getComponent(t.Collider),null==this._collider&&console.warn("ArcadeRigidbody 没有 Collider。ArcadeRigidbody需要一个Collider!")},n.prototype.update=function(){var e,i;if(this.isImmovable||null==this._collider)this.velocity=t.Vector2.zero;else{this.shouldUseGravity&&(this.velocity=t.Vector2.add(this.velocity,t.Vector2.multiply(t.Physics.gravity,new t.Vector2(t.Time.deltaTime)))),this.entity.transform.position=t.Vector2.add(this.entity.transform.position,t.Vector2.multiply(this.velocity,new t.Vector2(t.Time.deltaTime)));var r=new t.CollisionResult,o=t.Physics.boxcastBroadphaseExcludingSelfNonRect(this._collider,this._collider.collidesWithLayers.value);try{for(var s=__values(o),a=s.next();!a.done;a=s.next()){var c=a.value;if(!c.entity.equals(this.entity)&&this._collider.collidesWithNonMotion(c,r)){var h=c.entity.getComponent(n);if(null!=h)this.processOverlap(h,r.minimumTranslationVector),this.processCollision(h,r.minimumTranslationVector);else{this.entity.transform.position=t.Vector2.subtract(this.entity.transform.position,r.minimumTranslationVector);var u=this.velocity.clone();this.calculateResponseVelocity(u,r.minimumTranslationVector,u),this.velocity=t.Vector2.add(this.velocity,u)}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(e)throw e.error}}}},n.prototype.processOverlap=function(e,n){this.isImmovable?e.entity.transform.position=t.Vector2.add(e.entity.transform.position,n):e.isImmovable?this.entity.transform.position=t.Vector2.subtract(this.entity.transform.position,n):(this.entity.transform.position=t.Vector2.subtract(this.entity.transform.position,t.Vector2.multiply(n,t.Vector2Ext.halfVector())),e.entity.transform.position=t.Vector2.add(e.entity.transform.position,t.Vector2.multiply(n,t.Vector2Ext.halfVector())))},n.prototype.processCollision=function(e,n){var i=t.Vector2.subtract(this.velocity,e.velocity);this.calculateResponseVelocity(i,n,i);var r=this._inverseMass+e._inverseMass,o=this._inverseMass/r,s=e._inverseMass/r;this.velocity=t.Vector2.add(this.velocity,new t.Vector2(i.x*o,i.y*o)),e.velocity=t.Vector2.subtract(e.velocity,new t.Vector2(i.x*s,i.y*s))},n.prototype.calculateResponseVelocity=function(e,n,i){void 0===i&&(i=new t.Vector2);var r=t.Vector2.multiply(n,new t.Vector2(-1)),o=t.Vector2.normalize(r),s=t.Vector2.dot(e,o),a=new t.Vector2(o.x*s,o.y*s),c=t.Vector2.subtract(e,a);s>0&&(a=t.Vector2.zero);var h=this._friction;c.lengthSquared()>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n),this._bits.fill(0)}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>>>0;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<=this._bits.length){var e=this._bits.length;this._bits.length=t+1,this._bits.fill(0,e,t+1)}},t.LONG_MASK=63,t}();t.BitSet=e}(es||(es={})),function(t){var e=function(){function e(t){this._components=[],this._updatableComponents=[],this._componentsToAdd=[],this._componentsToRemove=[],this._tempBufferList=[],this._entity=t}return Object.defineProperty(e.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),e.prototype.markEntityListUnsorted=function(){this._isComponentListUnsorted=!0},e.prototype.add=function(t){this._componentsToAdd.push(t)},e.prototype.remove=function(t){var e=new linq.List(this._componentsToRemove),n=new linq.List(this._componentsToAdd);e.contains(t)&&console.warn("您正在尝试删除一个您已经删除的组件("+t+")"),n.contains(t)?n.remove(t):e.add(t)},e.prototype.removeAllComponents=function(){for(var t=0;t0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0&&(this._entitiesToRemove.toArray().forEach(function(t){e.removeFromTagList(t),new linq.List(e._entities).remove(t),t.onRemovedFromScene(),t.scene=null,e.scene.entityProcessors.onEntityRemoved(t)}),this._entitiesToRemove.clear()),this._entitiesToAdded.getCount()>0&&(this._entitiesToAdded.toArray().forEach(function(t){e._entities.push(t),t.scene=e.scene,e.addToTagList(t),e.scene.entityProcessors.onEntityAdded(t)}),this._entitiesToAdded.toArray().forEach(function(t){t.onAddedToScene()}),this._entitiesToAdded.clear(),this._isEntityListUnsorted=!0),this._isEntityListUnsorted&&(this._entities.sort(t.Entity.entityComparer.compare),this._isEntityListUnsorted=!1),this._unsortedTags.size>0&&(this._unsortedTags.forEach(function(t){return e._entityDict.get(t).sort(function(t,e){return t.compareTo(e)})}),this._unsortedTags.clear())},e.prototype.findEntity=function(t){for(var e=0;e=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i=0;e=this.allSet.nextSetBit(e+1))if(!t.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.totalTime+=e,this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return this.timeSinceSceneLoad/t>(this.timeSinceSceneLoad-this.deltaTime)/t},t.totalTime=0,t.unscaledDeltaTime=0,t.deltaTime=0,t.timeScale=1,t.frameCount=0,t.timeSinceSceneLoad=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var stopwatch,TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o=1?(e.value=1,n=this._points.length-4):(e.value=t.MathHelper.clamp01(e.value)*this._curveCount,n=~~e,e.value-=n,n*=3),n},e.prototype.setControlPoint=function(e,n){if(e%3==0){var i=t.Vector2.subtract(n,this._points[e]);e>0&&this._points[e-1].add(i),e+1n?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.angleToVector=function(e,n){return new t.Vector2(Math.cos(e)*n,Math.sin(e)*n)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.roundToNearest=function(t,e){return Math.round(t/e)*e},e.withinEpsilon=function(t,e){return void 0===e&&(e=this.Epsilon),Math.abs(t)180&&(n-=360),n},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e.PiOver2=Math.PI/2,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function t(){}return t.createOrthographicOffCenter=function(e,n,i,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(n-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-i),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+n)/(e-n),a.m42=(r+i)/(i-r),a.m43=o/(o-s),a.m44=1},t.multiply=function(e,n,i){void 0===i&&(i=new t);var r=e.m11*n.m11+e.m12*n.m21+e.m13*n.m31+e.m14*n.m41,o=e.m11*n.m12+e.m12*n.m22+e.m13*n.m32+e.m14*n.m42,s=e.m11*n.m13+e.m12*n.m23+e.m13*n.m33+e.m14*n.m43,a=e.m11*n.m14+e.m12*n.m24+e.m13*n.m34+e.m14*n.m44,c=e.m21*n.m11+e.m22*n.m21+e.m23*n.m31+e.m24*n.m41,h=e.m21*n.m12+e.m22*n.m22+e.m23*n.m32+e.m24*n.m42,u=e.m21*n.m13+e.m22*n.m23+e.m23*n.m33+e.m24*n.m43,l=e.m21*n.m14+e.m22*n.m24+e.m23*n.m34+e.m24*n.m44,p=e.m31*n.m11+e.m32*n.m21+e.m33*n.m31+e.m34*n.m41,f=e.m31*n.m12+e.m32*n.m22+e.m33*n.m32+e.m34*n.m42,d=e.m31*n.m13+e.m32*n.m23+e.m33*n.m33+e.m34*n.m43,m=e.m31*n.m14+e.m32*n.m24+e.m33*n.m34+e.m34*n.m44,y=e.m41*n.m11+e.m42*n.m21+e.m43*n.m31+e.m44*n.m41,g=e.m41*n.m12+e.m42*n.m22+e.m43*n.m32+e.m44*n.m42,_=e.m41*n.m13+e.m42*n.m23+e.m43*n.m33+e.m44*n.m43,v=e.m41*n.m14+e.m42*n.m24+e.m43*n.m34+e.m44*n.m44;i.m11=r,i.m12=o,i.m13=s,i.m14=a,i.m21=c,i.m22=h,i.m23=u,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=m,i.m41=y,i.m42=g,i.m43=_,i.m44=v},t}();t.Matrix=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=r,this.m32=o}return Object.defineProperty(e,"identity",{get:function(){return new e(1,0,0,1,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m22=t.y},enumerable:!0,configurable:!0}),e.createRotation=function(t){var e=this.identity,n=Math.cos(t),i=Math.sin(t);return e.m11=n,e.m12=i,e.m21=-i,e.m22=n,e},e.createScale=function(t,e){var n=this.identity;return n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0,n},e.createTranslation=function(t,e){var n=this.identity;return n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=t,n.m32=e,n},e.invert=function(t){var e=1/t.determinant(),n=this.identity;return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,n){return t.m11=t.m11+(e.m11-t.m11)*n,t.m12=t.m12+(e.m12-t.m12)*n,t.m21=t.m21+(e.m21-t.m21)*n,t.m22=t.m22+(e.m22-t.m22)*n,t.m31=t.m31+(e.m31-t.m31)*n,t.m32=t.m32+(e.m32-t.m32)*n,t},e.transpose=function(t){var e=this.identity;return e.m11=t.m11,e.m12=t.m21,e.m21=t.m12,e.m22=t.m22,e.m31=0,e.m32=0,e},e.prototype.mutiplyTranslation=function(n,i){var r=e.createTranslation(n,i);return t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var n=new t.Matrix;return n.m11=e.m11,n.m12=e.m12,n.m13=0,n.m14=0,n.m21=e.m21,n.m22=e.m22,n.m23=0,n.m24=0,n.m31=0,n.m32=0,n.m33=1,n.m34=0,n.m41=e.m31,n.m42=e.m32,n.m43=0,n.m44=1,n},e.prototype.toString=function(){return"{m11:"+this.m11+" m12:"+this.m12+" m21:"+this.m21+" m22:"+this.m22+" m31:"+this.m31+" m32:"+this.m32+"}"},e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(){function e(){}return e.add=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11+n.m11,i.m12=e.m12+n.m12,i.m21=e.m21+n.m21,i.m22=e.m22+n.m22,i.m31=e.m31+n.m31,i.m32=e.m32+n.m32,i},e.divide=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11/n.m11,i.m12=e.m12/n.m12,i.m21=e.m21/n.m21,i.m22=e.m22/n.m22,i.m31=e.m31/n.m31,i.m32=e.m32/n.m32,i},e.mutiply=function(e,n){var i=t.Matrix2D.identity;if(n instanceof t.Matrix2D){var r=e.m11*n.m11+e.m12*n.m21,o=n.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h}else"number"==typeof n&&(i.m11=e.m11*n,i.m12=e.m12*n,i.m21=e.m21*n,i.m22=e.m22*n,i.m31=e.m31*n,i.m32=e.m32*n);return i},e.subtract=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11-n.m11,i.m12=e.m12-n.m12,i.m21=e.m21-n.m21,i.m22=e.m22-n.m22,i.m31=e.m31-n.m31,i.m32=e.m32-n.m32,i},e}();t.MatrixHelper=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.x=0,this.y=0,this.width=0,this.height=0,this.x=t,this.y=e,this.width=n,this.height=i}return Object.defineProperty(e,"empty",{get:function(){return new e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"maxRect",{get:function(){return new e(Number.MIN_VALUE/2,Number.MIN_VALUE/2,Number.MAX_VALUE,Number.MAX_VALUE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.isEmpty=function(){return 0==this.width&&0==this.height&&0==this.x&&0==this.y},Object.defineProperty(e.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),e.fromMinMax=function(t,n,i,r){return new e(t,n,i-t,r-n)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;oi&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return!1}else{var i=1/t.direction.x,r=(this.x-t.start.x)*i,o=(this.x+this.width-t.start.x)*i;if(r>o){var s=r;r=o,o=s}if(e.value=Math.max(r,e.value),n=Math.min(o,n),e.value>n)return!1}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return!1}else{var a=1/t.direction.y,c=(this.y-t.start.y)*a,h=(this.y+this.height-t.start.y)*a;if(c>h){var u=c;c=h,h=u}if(e.value=Math.max(c,e.value),n=Math.max(h,n),e.value>n)return!1}return!0},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,i.y=n>0?this.y:this.y+n,i.width=t>0?t+this.width:this.width-t,i.height=n>0?n+this.height:this.height-n,i},e.prototype.collisionCheck=function(t,e,n){e.value=n.value=0;var i=t.x-(this.x+this.width),r=t.x+t.width-this.x,o=t.y-(this.y+this.height),s=t.y+t.height-this.y;return!(i>0||r<0||o>0||s<0)&&(e.value=Math.abs(i)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=h>0?l-h:-l-h,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return this.x^this.y^this.width^this.height},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.floor(Math.trunc(this.remainder));return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.HashSet,this._previousTriggerIntersections=new t.HashSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r,o){void 0===o&&(o=new t.Vector2),o.x=0,o.y=0;var s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return!1;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return!1;var l=(h.x*s.y-h.y*s.x)/c;if(l<0||l>1)return!1;var p=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y));return o.x=p.x,o.y=p.y,!0},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.circleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setValues=function(t,e,n,i){this.collider=t,this.fraction=e,this.distance=n,this.point=i},e.prototype.setValuesNonCollider=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset(),this._colliderArray[0]=null},e.clear=function(){this._spatialHash.clear()},e.overlapCircle=function(t,n,i){return void 0===i&&(i=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapCircle(t,n,this._colliderArray,i),this._colliderArray[0]},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.warn("传入了一个空的结果数组。不会返回任何结果")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var n=t.bounds.clone();return this._spatialHash.aabbBroadphase(n,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,n,i,r){void 0===r&&(r=e.allLayers);var o=t.bounds.clone().getSweptBroadphaseBounds(n,i);return this._spatialHash.aabbBroadphase(o,t,r)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.linecast=function(t,n,i){return void 0===i&&(i=e.allLayers),this._hitArray[0].reset(),this.linecastAll(t,n,this._hitArray,i),this._hitArray[0]},e.linecastAll=function(t,n,i,r){return void 0===r&&(r=e.allLayers),0==i.length?(console.warn("传入了一个空的hits数组。没有点击会被返回"),0):this._spatialHash.linecast(t,n,i,r)},e.overlapRectangle=function(t,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,n),this._colliderArray[0]},e.overlapRectangleAll=function(t,n,i){return void 0===i&&(i=e.allLayers),0==n.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,n,i)},e.gravity=new t.Vector2(0,300),e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e._hitArray=[new t.RaycastHit],e._colliderArray=[null],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(e,n){this.start=e,this.end=n,this.direction=t.Vector2.subtract(this.end,this.start)}}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestBox=new t.Box(0,0),this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds.clone();e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(t){for(var e=t.registeredPhysicsBounds.clone(),n=this.cellCoords(e.x,e.y),i=this.cellCoords(e.right,e.bottom),r=n.x;r<=i.x;r++)for(var o=n.y;o<=i.y;o++){var s=this.cellAtPosition(r,o);s?new linq.List(s).remove(t):console.log("从不存在碰撞器的单元格中移除碰撞器: ["+t+"]")}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.clear();for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(null!=c)for(var h=0;h>>0},t.prototype.clear=function(){this._store.clear()},t}();t.NumberDictionary=n;var i=function(){function e(){this._tempHit=new t.RaycastHit,this._checkedColliders=[],this._cellHits=[]}return e.prototype.start=function(t,e,n){this._ray=t,this._hits=e,this._layerMask=n,this.hitCounter=0},e.prototype.checkRayIntersection=function(n,i,r){for(var o=new t.Ref(0),s=0;s=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;rr&&(r=s,i=o)}return e[i]},n.getClosestPointOnPolygonToPoint=function(e,n,i,r){i.value=Number.MAX_VALUE,r.x=0,r.y=0;for(var o=t.Vector2.zero,s=0,a=0;at.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o1)return!1;var a,c=t.Vector2.add(s.start,t.Vector2.multiply(s.direction,new t.Vector2(r.value))),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var u=a+h;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,n){var i=new t.Vector2;return i.x=0==(1&n)?e.right:e.left,i.y=0==(1&n)?e.bottom:e.top,i},e.testCircleBox=function(e,n,i){i=n.bounds.getClosestPointOnRectangleToPoint(e.position);var r=t.Vector2.subtract(i,e.position);return t.Vector2.dot(r,r)<=e.radius*e.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.polygonToPolygon=function(e,n,i){for(var r,o=!0,s=e.edgeNormals.slice(),a=n.edgeNormals.slice(),c=Number.POSITIVE_INFINITY,h=new t.Vector2,u=t.Vector2.subtract(e.position,n.position),l=0;l0&&(o=!1),!o)return!1;(y=Math.abs(y))r.value&&(r.value=o)},e.circleToPolygon=function(e,n,i){void 0===i&&(i=new t.CollisionResult);var r,o=t.Vector2.subtract(e.position,n.position),s=new t.Ref(0),a=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,s,i.normal),c=n.containsPoint(e.position);if(s.value>e.radius*e.radius&&!c)return!1;if(c)r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(s.value)-e.radius));else if(0==s.value)r=new t.Vector2(i.normal.x*e.radius,i.normal.y*e.radius);else{var h=Math.sqrt(s.value);r=t.Vector2.subtract(new t.Vector2(-1),t.Vector2.subtract(o,a)).multiply(new t.Vector2((e.radius-h)/h))}return i.minimumTranslationVector=r,i.point=t.Vector2.add(a,n.position),!0},e.circleToBox=function(e,n,i){void 0===i&&(i=new t.CollisionResult);var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r.clone();var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r1)return!1;var l=(h.x*s.y-h.y*s.x)/c;return!(l<0||l>1)&&(t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(u),s)),!0)},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divide(t.Vector2.subtract(n,e),new t.Vector2(o)),a=t.Vector2.subtract(e,i.position),c=t.Vector2.dot(a,s),h=t.Vector2.dot(a,a)-i.radius*i.radius;if(h>0&&c>0)return!1;var u=c*c-h;return!(u<0)&&(r.fraction=-c-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(r.fraction),s)),r.distance=t.Vector2.distance(e,r.point),r.normal=t.Vector2.normalize(t.Vector2.subtract(r.point,i.position)),r.fraction=r.distance/o,!0)},e.boxToBoxCast=function(e,n,i,r){var o=this.minkowskiDifference(e,n);if(o.contains(0,0)){var s=o.getClosestPointOnBoundsToOrigin();return!s.equals(t.Vector2.zero)&&(r.normal=new t.Vector2(-s.x),r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,new t.Vector2(-i.x)),c=new t.Ref(0);return!!(o.rayIntersects(a,c)&&c.value<=1)&&(r.fraction=c.value,r.distance=i.length()*c.value,r.normal=new t.Vector2(-i.x,-i.y),r.normal.normalize(),r.centroid=t.Vector2.add(e.bounds.center,t.Vector2.multiply(i,new t.Vector2(c.value))),!0)},e}();t.ShapeCollisions=e}(es||(es={})),function(t){!function(t){t[t.top=0]="top",t[t.bottom=1]="bottom",t[t.left=2]="left",t[t.right=3]="right"}(t.Edge||(t.Edge={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.repeat=function(t,e){for(var n=[];e--;)n.push(t);return n},t}();t.Enumerable=e}(es||(es={})),function(t){var e=function(){function t(){}return t.default=function(){return new t},t.prototype.equals=function(t,e){return"function"==typeof t.equals?t.equals(e):t===e},t.prototype.getHashCode=function(t){var e=this;if("number"==typeof t)return this._getHashCodeForNumber(t);if("string"==typeof t)return this._getHashCodeForString(t);var n=385229220;return this.forOwn(t,function(t){"number"==typeof t?n+=e._getHashCodeForNumber(t):"string"==typeof t?n+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){n+=e.getHashCode(t)})}),n},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,n=0;n>7,n+=n<<3,n^=n>>17,n+=n<<5},t}();t.Hash=e}(es||(es={})),function(t){var e=function(){return function(t){this.value=t}}();t.Ref=e}(es||(es={})),function(t){var e=function(){function e(){}return Object.defineProperty(e,"size",{get:function(){return new t.Vector2(this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"center",{get:function(){return new t.Vector2(this.width/2,this.height/2)},enumerable:!0,configurable:!0}),e}();t.Screen=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelNumber=e}(es||(es={})),function(t){var e=function(){function e(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return e.testPointTriangle=function(e,n,i,r){return!(t.Vector2Ext.cross(t.Vector2.subtract(e,n),t.Vector2.subtract(i,n))<0)&&(!(t.Vector2Ext.cross(t.Vector2.subtract(e,i),t.Vector2.subtract(r,i))<0)&&!(t.Vector2Ext.cross(t.Vector2.subtract(e,r),t.Vector2.subtract(n,r))<0))},e.prototype.triangulate=function(n,i){void 0===i&&(i=!0);var r=n.length;this.initialize(r);for(var o=0,s=0;r>3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengththis._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){return function(t,e){this.element=t,this.next=e}}();function n(t,e){return t===e}t.Node=e,t.defaultEquals=n;var i=function(){function t(t){void 0===t&&(t=n),this.count=0,this.next=void 0,this.equalsFn=t,this.head=null}return t.prototype.push=function(t){var n,i=new e(t);if(null==this.head)this.head=i;else{for(n=this.head;null!=n.next;)n=n.next;n.next=i}this.count++},t.prototype.removeAt=function(t){if(t>=0&&t=0&&t<=this.count){for(var e=this.head,n=0;n=0&&n<=this.count){var i=new e(t);if(0===n)i.next=this.head,this.head=i;else{var r=this.getElementAt(n-1);i.next=r.next,r.next=i}return this.count++,!0}return!1},t.prototype.indexOf=function(t){for(var e=this.head,n=0;n0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.first=t,this.second=e}return e.prototype.clear=function(){this.first=this.second=null},e.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},e.prototype.getHashCode=function(){return 37*t.EqualityComparer.default().getHashCode(this.first)+t.EqualityComparer.default().getHashCode(this.second)},e}();t.Pair=e}(es||(es={})),function(t){var e=function(){function e(){}return e.warmCache=function(t,e){if((e-=this._objectQueue.length)>0)for(var n=0;nthis._objectQueue.length;)this._objectQueue.shift()},e.clearCache=function(){this._objectQueue.length=0},e.obtain=function(t){return this._objectQueue.length>0?this._objectQueue.shift():new t},e.free=function(e){this._objectQueue.unshift(e),t.isIPoolable(e)&&e.reset()},e._objectQueue=[],e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.getHashCode=function(t){return t.getHashCode()},e.prototype.areEqual=function(t,e){return t.equals(e)},e}(function(){function t(t){var e=this;this.clear(),t&&t.forEach(function(t){e.add(t)})}return t.prototype.add=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i){var r=new Array;return r.push(t),this.buckets[n]=r,this.count=this.count+1,!0}return!i.some(function(n){return e.areEqual(n,t)})&&(i.push(t),this.count=this.count+1,!0)},t.prototype.remove=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i)return!1;var r=!1,o=new Array;return i.forEach(function(n){e.areEqual(n,t)?r=!0:o.push(t)}),this.buckets[n]=o,r&&(this.count=this.count-1),r},t.prototype.contains=function(t){return this.bucketsContains(this.buckets,t)},t.prototype.getCount=function(){return this.count},t.prototype.clear=function(){this.buckets=new Array,this.count=0},t.prototype.toArray=function(){var t=new Array;return this.buckets.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},t.prototype.exceptWith=function(t){var e=this;t&&t.forEach(function(t){e.remove(t)})},t.prototype.intersectWith=function(t){var e=this;if(t){var n=this.buildInternalBuckets(t);this.toArray().forEach(function(t){e.bucketsContains(n.Buckets,t)||e.remove(t)})}else this.clear()},t.prototype.unionWith=function(t){var e=this;t.forEach(function(t){e.add(t)})},t.prototype.isSubsetOf=function(t){var e=this,n=this.buildInternalBuckets(t);return this.toArray().every(function(t){return e.bucketsContains(n.Buckets,t)})},t.prototype.isSupersetOf=function(t){var e=this;return t.every(function(t){return e.contains(t)})},t.prototype.overlaps=function(t){var e=this;return t.some(function(t){return e.contains(t)})},t.prototype.setEquals=function(t){var e=this;return this.buildInternalBuckets(t).Count===this.count&&t.every(function(t){return e.contains(t)})},t.prototype.buildInternalBuckets=function(t){var e=this,n=new Array,i=0;return t.forEach(function(t){var r=e.getHashCode(t),o=n[r];if(void 0===o){var s=new Array;s.push(t),n[r]=s,i+=1}else o.some(function(n){return e.areEqual(n,t)})||(o.push(t),i+=1)}),{Buckets:n,Count:i}},t.prototype.bucketsContains=function(t,e){var n=this,i=t[this.getHashCode(e)];return void 0!==i&&i.some(function(t){return n.areEqual(t,e)})},t}());t.HashSet=e}(es||(es={})),function(t){var e=function(){function t(){}return t.waitForSeconds=function(t){return n.waiter.wait(t)},t}();t.Coroutine=e;var n=function(){function t(){this.waitTime=0}return t.prototype.wait=function(e){return t.waiter.waitTime=e,t.waiter},t.waiter=new t,t}();t.WaitForSeconds=n}(es||(es={})),function(t){var e=function(){function t(){this.waitTimer=0,this.useUnscaledDeltaTime=!1}return t.prototype.stop=function(){this.isDone=!0},t.prototype.setUseUnscaledDeltaTime=function(t){return this.useUnscaledDeltaTime=t,this},t.prototype.prepareForUse=function(){this.isDone=!1},t.prototype.reset=function(){this.isDone=!0,this.waitTimer=0,this.waitForCoroutine=null,this.enumerator=null,this.useUnscaledDeltaTime=!1},t}();t.CoroutineImpl=e;var n=function(n){function i(){var t=null!==n&&n.apply(this,arguments)||this;return t._unblockedCoroutines=[],t._shouldRunNextFrame=[],t}return __extends(i,n),i.prototype.startCoroutine=function(n){var i=t.Pool.obtain(e);return i.prepareForUse(),i.enumerator=n,this.tickCoroutine(i)?(this._isInUpdate?this._shouldRunNextFrame.push(i):this._unblockedCoroutines.push(i),i):null},i.prototype.update=function(){this._isInUpdate=!0;for(var e=0;e0?(n.waitTimer-=n.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime,this._shouldRunNextFrame.push(n)):this.tickCoroutine(n)&&this._shouldRunNextFrame.push(n)}}var i=new linq.List(this._unblockedCoroutines);i.clear(),i.addRange(this._shouldRunNextFrame),this._shouldRunNextFrame.length=0,this._isInUpdate=!1},i.prototype.tickCoroutine=function(n){var i=n.enumerator.next();return i.done||n.isDone?(t.Pool.free(n),!1):null==i.value||(i.value instanceof t.WaitForSeconds?(n.waitTimer=i.value.waitTime,!0):"number"==typeof i.value?(n.waitTimer=i.value,!0):"string"==typeof i.value?"break"!=i.value||(t.Pool.free(n),!1):!(i.value instanceof e)||(n.waitForCoroutine=i.value,!0))},i}(t.GlobalManager);t.CoroutineManager=n}(es||(es={})),function(t){var e=function(){function e(t,e,n){void 0===n&&(n=!0),this.binWidth=0,this.binHeight=0,this.usedRectangles=[],this.freeRectangles=[],this.init(t,e,n)}return e.prototype.init=function(e,n,i){void 0===i&&(i=!0),this.binWidth=e,this.binHeight=n,this.allowRotations=i;var r=new t.Rectangle;r.x=0,r.y=0,r.width=e,r.height=n,this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(r)},e.prototype.insert=function(e,n){var i=new t.Rectangle,r=new t.Ref(0),o=new t.Ref(0);if(0==(i=this.findPositionForNewNodeBestAreaFit(e,n,r,o)).height)return i;for(var s=this.freeRectangles.length,a=0;a=e&&this.freeRectangles[s].height>=n){var c=Math.abs(this.freeRectangles[s].width-e),h=Math.abs(this.freeRectangles[s].height-n),u=Math.min(c,h);(a=n&&this.freeRectangles[s].height>=e){c=Math.abs(this.freeRectangles[s].width-n),h=Math.abs(this.freeRectangles[s].height-e),u=Math.min(c,h);(a=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y)return!1;if(e.xt.x){if(e.y>t.y&&e.yt.y){var n;if(e.x>t.x&&e.x=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height},e}();t.MaxRectsBinPack=e}(es||(es={}));var ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t.shuffle=function(t){for(var e=t.length;e>1;){e--;var n=RandomUtils.randint(0,e+1),i=t[n];t[n]=t[e],t[e]=i}},t.addIfNotPresent=function(t,e){return!new linq.List(t).contains(e)&&(t.push(e),!0)},t.lastItem=function(t){return t[t.length-1]},t.randomItem=function(t){return t[RandomUtils.randint(0,t.length-1)]},t.randomItems=function(t,e){for(var n=new Set;n.size!=e;){var i=this.randomItem(t);n.has(i)||n.add(i)}var r=es.ListPool.obtain();return n.forEach(function(t){return r.push(t)}),r},t}();!function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],c=0;c>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(c++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(c++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(n)),64!==s&&a.push(String.fromCharCode(i));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,n,i,r,o,s,a,c=[],h=0;h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c.push(this._keyStr.charAt(r)),c.push(this._keyStr.charAt(o)),c.push(this._keyStr.charAt(s)),c.push(this._keyStr.charAt(a));return c=c.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random().5?1:-1},t}();!function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,i.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e.boundsFromPolygonVector=function(e){for(var n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,s=0;sr&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(n,i),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,n){return new t.Rectangle(e.x,e.y,n.x-e.x,n.y-e.y)},e.getSweptBroadphaseBounds=function(e,n,i){var r=t.Rectangle.empty;return r.x=n>0?e.x:e.x+n,r.y=i>0?e.y:e.y+i,r.width=n>0?n+e.width:e.width-n,r.height=i>0?i+e.height:e.height-i,r},e.prototype.collisionCheck=function(t,e,n,i){n.value=i.value=0;var r=e.x-(t.x+t.width),o=e.x+e.width-t.x,s=e.y-(t.y+t.height),a=e.y+e.height-t.y;return!(r>0||o<0||s>0||a<0)&&(n.value=Math.abs(r)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=h>0?l-h:-l-h,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function t(){}return t.premultiplyAlpha=function(t){for(var e=t[0],n=0;nt.MathHelper.Epsilon?e.divide(new t.Vector2(n)):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){return this.sum(t)/this.count(t)},e.prototype.cast=function(){return new e(this._elements)},e.prototype.clear=function(){this._elements.length=0},e.prototype.concat=function(t){return new e(this._elements.concat(t.toArray()))},e.prototype.contains=function(t){return this.any(function(e){return e===t})},e.prototype.count=function(t){return t?this.where(t).count():this._elements.length},e.prototype.defaultIfEmpty=function(t){return this.count()?this:new e([t])},e.prototype.distinctBy=function(t){var n=this.groupBy(t);return Object.keys(n).reduce(function(t,e){return t.add(n[e][0]),t},new e)},e.prototype.elementAt=function(t){if(t=0)return this._elements[t];throw new Error("ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.")},e.prototype.elementAtOrDefault=function(t){return t=0?this._elements[t]:void 0},e.prototype.except=function(t){return this.where(function(e){return!t.contains(e)})},e.prototype.first=function(t){if(this.count())return t?this.where(t).first():this._elements[0];throw new Error("InvalidOperationException: The source sequence is empty.")},e.prototype.firstOrDefault=function(t){return this.count(t)?this.first(t):void 0},e.prototype.forEach=function(t){return this._elements.forEach(t)},e.prototype.groupBy=function(t,e){void 0===e&&(e=function(t){return t});return this.aggregate(function(n,i){var r=t(i),o=n[r],s=e(i);return o?o.push(s):n[r]=[s],n},{})},e.prototype.groupJoin=function(t,e,n,i){return this.select(function(r){return i(r,t.where(function(t){return e(r)===n(t)}))})},e.prototype.indexOf=function(t){return this._elements.indexOf(t)},e.prototype.insert=function(t,e){if(t<0||t>this._elements.length)throw new Error("Index is out of range.");this._elements.splice(t,0,e)},e.prototype.intersect=function(t){return this.where(function(e){return t.contains(e)})},e.prototype.join=function(t,e,n,i){return this.selectMany(function(r){return t.where(function(t){return n(t)===e(r)}).select(function(t){return i(r,t)})})},e.prototype.last=function(t){if(this.count())return t?this.where(t).last():this._elements[this.count()-1];throw Error("InvalidOperationException: The source sequence is empty.")},e.prototype.lastOrDefault=function(t){return this.count(t)?this.last(t):void 0},e.prototype.max=function(t){return Math.max.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.min=function(t){return Math.min.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.ofType=function(t){var e;switch(t){case Number:e="number";break;case String:e="string";break;case Boolean:e=typeof!0;break;case Function:e="function";break;default:e=null}return null===e?this.where(function(e){return e instanceof t}).cast():this.where(function(t){return typeof t===e}).cast()},e.prototype.orderBy=function(e,i){return void 0===i&&(i=t.keyComparer(e,!1)),new n(this._elements,i)},e.prototype.orderByDescending=function(e,i){return void 0===i&&(i=t.keyComparer(e,!0)),new n(this._elements,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){return-1!==this.indexOf(t)&&(this.removeAt(this.indexOf(t)),!0)},e.prototype.removeAll=function(e){return this.where(t.negate(e))},e.prototype.removeAt=function(t){this._elements.splice(t,1)},e.prototype.reverse=function(){return new e(this._elements.reverse())},e.prototype.select=function(t){return new e(this._elements.map(t))},e.prototype.selectMany=function(t){var n=this;return this.aggregate(function(e,i,r){return e.addRange(n.select(t).elementAt(r).toArray()),e},new e)},e.prototype.sequenceEqual=function(t){return this.all(function(e){return t.contains(e)})},e.prototype.single=function(t){if(1!==this.count(t))throw new Error("The collection does not contain exactly one element.");return this.first(t)},e.prototype.singleOrDefault=function(t){return this.count(t)?this.single(t):void 0},e.prototype.skip=function(t){return new e(this._elements.slice(Math.max(0,t)))},e.prototype.skipLast=function(t){return new e(this._elements.slice(0,-Math.max(0,t)))},e.prototype.skipWhile=function(t){var e=this;return this.skip(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.sum=function(t){return t?this.select(t).sum():this.aggregate(function(t,e){return t+ +e},0)},e.prototype.take=function(t){return new e(this._elements.slice(0,Math.max(0,t)))},e.prototype.takeLast=function(t){return new e(this._elements.slice(-Math.max(0,t)))},e.prototype.takeWhile=function(t){var e=this;return this.take(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.toArray=function(){return this._elements},e.prototype.toDictionary=function(t,n){var i=this;return this.aggregate(function(e,r,o){return e[i.select(t).elementAt(o).toString()]=n?i.select(n).elementAt(o):r,e.add({Key:i.select(t).elementAt(o),Value:n?i.select(n).elementAt(o):r}),e},new e)},e.prototype.toSet=function(){var t,e,n=new Set;try{for(var i=__values(this._elements),r=i.next();!r.done;r=i.next()){var o=r.value;n.add(o)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return n},e.prototype.toList=function(){return this},e.prototype.toLookup=function(t,e){return this.groupBy(t,e)},e.prototype.where=function(t){return new e(this._elements.filter(t))},e.prototype.zip=function(t,e){var n=this;return t.count()e.angle?1:t.angleMath.PI&&(o-=2*Math.PI),r.p1.begin=o>0,r.p2.begin=!r.p1.begin}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}this._isSpotLight&&(this._spotStartAngle=this._segments[0].p2.angle,this._spotEndAngle=this._segments[1].p2.angle)},e._cornerCache=[],e._openSegments=new t.LinkedList,e}();t.VisibilityComputer=e}(es||(es={})),function(t){var e=function(){function e(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}return e.prototype.getContext=function(){return this.context},e.prototype.reset=function(){this._elapsedTime=0},e.prototype.stop=function(){this._isDone=!0},e.prototype.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=t.Time.deltaTime,this._isDone},e.prototype.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),new linq.List(this._timers).removeAt(t))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file +window.es={};var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}},__read=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e=1){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._titleMemory&&this._titleMemory(this._totalMemory,this._frameCounter),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(e){return __awaiter(this,void 0,void 0,function(){var n;return __generator(this,function(i){if(null!=e&&t.Time.update(e),null!=this._scene){for(n=this._globalManagers.length-1;n>=0;n--)this._globalManagers[n].enabled&&this._globalManagers[n].update();this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}return this.startDebugDraw(),[2]})})},e.pauseOnFocusLost=!0,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){var e=function(){function t(){}return t.debugText=16777215,t.colliderBounds=5033164.5,t.colliderEdge=9109504,t.colliderPosition=16776960,t.colliderCenter=16711680,t.renderableBounds=16776960,t.renderableCenter=10040012,t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.fail=function(t){void 0===t&&(t=null);for(var e=[],n=1;n=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate()},e.prototype.addSceneComponent=function(t){return t.scene=this,t.onEnabled(),this._sceneComponents.push(t),this._sceneComponents.sort(t.compare),t},e.prototype.getSceneComponent=function(t){for(var e=0;ee.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(null!=this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.createRotation(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.createScale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(this._translationMatrix),null==this.parent&&(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),null!=this.parent&&(this._worldTransform=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}for(var n=0;n0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e,t.isIUpdatable=function(t){return void 0!==t.update}}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(){function t(){this.updateOrder=0,this._enabled=!0}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onRemovedFromScene=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this.updateOrder!=t&&(this.updateOrder=t),this},t.prototype.compare=function(t){return this.updateOrder-t.updateOrder},t}();t.SceneComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=e.call(this)||this;return n.shouldUseGravity=!0,n.velocity=new t.Vector2,n._mass=10,n._elasticity=.5,n._friction=.5,n._glue=.01,n._inverseMass=0,n._inverseMass=1/n._mass,n}return __extends(n,e),Object.defineProperty(n.prototype,"mass",{get:function(){return this._mass},set:function(t){this.setMass(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"elasticity",{get:function(){return this._elasticity},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"elasticiy",{set:function(t){this.setElasticity(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"friction",{get:function(){return this._friction},set:function(t){this.setFriction(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"glue",{get:function(){return this._glue},set:function(t){this.setGlue(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isImmovable",{get:function(){return this._mass<1e-4},enumerable:!0,configurable:!0}),n.prototype.setMass=function(e){return this._mass=t.MathHelper.clamp(e,0,Number.MAX_VALUE),this._mass>1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},n.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},n.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},n.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},n.prototype.addImpulse=function(e){this.isImmovable||(this.velocity=t.Vector2.add(this.velocity,t.Vector2.multiply(e,new t.Vector2(1e5)).multiply(new t.Vector2(this._inverseMass*t.Time.deltaTime))))},n.prototype.onAddedToEntity=function(){this._collider=this.entity.getComponent(t.Collider),null==this._collider&&console.warn("ArcadeRigidbody 没有 Collider。ArcadeRigidbody需要一个Collider!")},n.prototype.update=function(){var e,i;if(this.isImmovable||null==this._collider)this.velocity=t.Vector2.zero;else{this.shouldUseGravity&&(this.velocity=t.Vector2.add(this.velocity,t.Vector2.multiply(t.Physics.gravity,new t.Vector2(t.Time.deltaTime)))),this.entity.transform.position=t.Vector2.add(this.entity.transform.position,t.Vector2.multiply(this.velocity,new t.Vector2(t.Time.deltaTime)));var r=new t.CollisionResult,o=t.Physics.boxcastBroadphaseExcludingSelfNonRect(this._collider,this._collider.collidesWithLayers.value);try{for(var s=__values(o),a=s.next();!a.done;a=s.next()){var c=a.value;if(!c.entity.equals(this.entity)&&this._collider.collidesWithNonMotion(c,r)){var h=c.entity.getComponent(n);if(null!=h)this.processOverlap(h,r.minimumTranslationVector),this.processCollision(h,r.minimumTranslationVector);else{this.entity.transform.position=t.Vector2.subtract(this.entity.transform.position,r.minimumTranslationVector);var u=this.velocity.clone();this.calculateResponseVelocity(u,r.minimumTranslationVector,u),this.velocity=t.Vector2.add(this.velocity,u)}}}}catch(t){e={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(e)throw e.error}}}},n.prototype.processOverlap=function(e,n){this.isImmovable?e.entity.transform.position=t.Vector2.add(e.entity.transform.position,n):e.isImmovable?this.entity.transform.position=t.Vector2.subtract(this.entity.transform.position,n):(this.entity.transform.position=t.Vector2.subtract(this.entity.transform.position,t.Vector2.multiply(n,t.Vector2Ext.halfVector())),e.entity.transform.position=t.Vector2.add(e.entity.transform.position,t.Vector2.multiply(n,t.Vector2Ext.halfVector())))},n.prototype.processCollision=function(e,n){var i=t.Vector2.subtract(this.velocity,e.velocity);this.calculateResponseVelocity(i,n,i);var r=this._inverseMass+e._inverseMass,o=this._inverseMass/r,s=e._inverseMass/r;this.velocity=t.Vector2.add(this.velocity,new t.Vector2(i.x*o,i.y*o)),e.velocity=t.Vector2.subtract(e.velocity,new t.Vector2(i.x*s,i.y*s))},n.prototype.calculateResponseVelocity=function(e,n,i){void 0===i&&(i=new t.Vector2);var r=t.Vector2.multiply(n,new t.Vector2(-1)),o=t.Vector2.normalize(r),s=t.Vector2.dot(e,o),a=new t.Vector2(o.x*s,o.y*s),c=t.Vector2.subtract(e,a);s>0&&(a=t.Vector2.zero);var h=this._friction;c.lengthSquared()>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n),this._bits.fill(0)}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>>>0;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<=this._bits.length){var e=this._bits.length;this._bits.length=t+1,this._bits.fill(0,e,t+1)}},t.LONG_MASK=63,t}();t.BitSet=e}(es||(es={})),function(t){var e=function(){function e(t){this._components=[],this._updatableComponents=[],this._componentsToAdd=[],this._componentsToRemove=[],this._tempBufferList=[],this._entity=t}return Object.defineProperty(e.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),e.prototype.markEntityListUnsorted=function(){this._isComponentListUnsorted=!0},e.prototype.add=function(t){this._componentsToAdd.push(t)},e.prototype.remove=function(t){var e=new linq.List(this._componentsToRemove),n=new linq.List(this._componentsToAdd);e.contains(t)&&console.warn("您正在尝试删除一个您已经删除的组件("+t+")"),n.contains(t)?n.remove(t):e.add(t)},e.prototype.removeAllComponents=function(){for(var t=0;t0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0&&(this._entitiesToRemove.toArray().forEach(function(t){e.removeFromTagList(t),new linq.List(e._entities).remove(t),t.onRemovedFromScene(),t.scene=null,e.scene.entityProcessors.onEntityRemoved(t)}),this._entitiesToRemove.clear()),this._entitiesToAdded.getCount()>0&&(this._entitiesToAdded.toArray().forEach(function(t){e._entities.push(t),t.scene=e.scene,e.addToTagList(t),e.scene.entityProcessors.onEntityAdded(t)}),this._entitiesToAdded.toArray().forEach(function(t){t.onAddedToScene()}),this._entitiesToAdded.clear(),this._isEntityListUnsorted=!0),this._isEntityListUnsorted&&(this._entities.sort(t.Entity.entityComparer.compare),this._isEntityListUnsorted=!1),this._unsortedTags.size>0&&(this._unsortedTags.forEach(function(t){return e._entityDict.get(t).sort(function(t,e){return t.compareTo(e)})}),this._unsortedTags.clear())},e.prototype.findEntity=function(t){for(var e=0;e=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i=0;e=this.allSet.nextSetBit(e+1))if(!t.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t))},e.prototype.all=function(){for(var e=this,n=[],i=0;i=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.totalTime+=e,this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return this.timeSinceSceneLoad/t>(this.timeSinceSceneLoad-this.deltaTime)/t},t.totalTime=0,t.unscaledDeltaTime=0,t.deltaTime=0,t.timeScale=1,t.frameCount=0,t.timeSinceSceneLoad=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var stopwatch,TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o=1?(e.value=1,n=this._points.length-4):(e.value=t.MathHelper.clamp01(e.value)*this._curveCount,n=~~e,e.value-=n,n*=3),n},e.prototype.setControlPoint=function(e,n){if(e%3==0){var i=t.Vector2.subtract(n,this._points[e]);e>0&&this._points[e-1].add(i),e+1n?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.angleToVector=function(e,n){return new t.Vector2(Math.cos(e)*n,Math.sin(e)*n)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.roundToNearest=function(t,e){return Math.round(t/e)*e},e.withinEpsilon=function(t,e){return void 0===e&&(e=this.Epsilon),Math.abs(t)180&&(n-=360),n},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e.PiOver2=Math.PI/2,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function t(){}return t.createOrthographicOffCenter=function(e,n,i,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(n-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-i),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+n)/(e-n),a.m42=(r+i)/(i-r),a.m43=o/(o-s),a.m44=1},t.multiply=function(e,n,i){void 0===i&&(i=new t);var r=e.m11*n.m11+e.m12*n.m21+e.m13*n.m31+e.m14*n.m41,o=e.m11*n.m12+e.m12*n.m22+e.m13*n.m32+e.m14*n.m42,s=e.m11*n.m13+e.m12*n.m23+e.m13*n.m33+e.m14*n.m43,a=e.m11*n.m14+e.m12*n.m24+e.m13*n.m34+e.m14*n.m44,c=e.m21*n.m11+e.m22*n.m21+e.m23*n.m31+e.m24*n.m41,h=e.m21*n.m12+e.m22*n.m22+e.m23*n.m32+e.m24*n.m42,u=e.m21*n.m13+e.m22*n.m23+e.m23*n.m33+e.m24*n.m43,l=e.m21*n.m14+e.m22*n.m24+e.m23*n.m34+e.m24*n.m44,p=e.m31*n.m11+e.m32*n.m21+e.m33*n.m31+e.m34*n.m41,f=e.m31*n.m12+e.m32*n.m22+e.m33*n.m32+e.m34*n.m42,d=e.m31*n.m13+e.m32*n.m23+e.m33*n.m33+e.m34*n.m43,m=e.m31*n.m14+e.m32*n.m24+e.m33*n.m34+e.m34*n.m44,y=e.m41*n.m11+e.m42*n.m21+e.m43*n.m31+e.m44*n.m41,g=e.m41*n.m12+e.m42*n.m22+e.m43*n.m32+e.m44*n.m42,_=e.m41*n.m13+e.m42*n.m23+e.m43*n.m33+e.m44*n.m43,v=e.m41*n.m14+e.m42*n.m24+e.m43*n.m34+e.m44*n.m44;i.m11=r,i.m12=o,i.m13=s,i.m14=a,i.m21=c,i.m22=h,i.m23=u,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=m,i.m41=y,i.m42=g,i.m43=_,i.m44=v},t}();t.Matrix=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=r,this.m32=o}return Object.defineProperty(e,"identity",{get:function(){return new e(1,0,0,1,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m22=t.y},enumerable:!0,configurable:!0}),e.createRotation=function(t){var e=this.identity,n=Math.cos(t),i=Math.sin(t);return e.m11=n,e.m12=i,e.m21=-i,e.m22=n,e},e.createScale=function(t,e){var n=this.identity;return n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0,n},e.createTranslation=function(t,e){var n=this.identity;return n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=t,n.m32=e,n},e.invert=function(t){var e=1/t.determinant(),n=this.identity;return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,n){return t.m11=t.m11+(e.m11-t.m11)*n,t.m12=t.m12+(e.m12-t.m12)*n,t.m21=t.m21+(e.m21-t.m21)*n,t.m22=t.m22+(e.m22-t.m22)*n,t.m31=t.m31+(e.m31-t.m31)*n,t.m32=t.m32+(e.m32-t.m32)*n,t},e.transpose=function(t){var e=this.identity;return e.m11=t.m11,e.m12=t.m21,e.m21=t.m12,e.m22=t.m22,e.m31=0,e.m32=0,e},e.prototype.mutiplyTranslation=function(n,i){var r=e.createTranslation(n,i);return t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var n=new t.Matrix;return n.m11=e.m11,n.m12=e.m12,n.m13=0,n.m14=0,n.m21=e.m21,n.m22=e.m22,n.m23=0,n.m24=0,n.m31=0,n.m32=0,n.m33=1,n.m34=0,n.m41=e.m31,n.m42=e.m32,n.m43=0,n.m44=1,n},e.prototype.toString=function(){return"{m11:"+this.m11+" m12:"+this.m12+" m21:"+this.m21+" m22:"+this.m22+" m31:"+this.m31+" m32:"+this.m32+"}"},e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(){function e(){}return e.add=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11+n.m11,i.m12=e.m12+n.m12,i.m21=e.m21+n.m21,i.m22=e.m22+n.m22,i.m31=e.m31+n.m31,i.m32=e.m32+n.m32,i},e.divide=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11/n.m11,i.m12=e.m12/n.m12,i.m21=e.m21/n.m21,i.m22=e.m22/n.m22,i.m31=e.m31/n.m31,i.m32=e.m32/n.m32,i},e.mutiply=function(e,n){var i=t.Matrix2D.identity;if(n instanceof t.Matrix2D){var r=e.m11*n.m11+e.m12*n.m21,o=n.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h}else"number"==typeof n&&(i.m11=e.m11*n,i.m12=e.m12*n,i.m21=e.m21*n,i.m22=e.m22*n,i.m31=e.m31*n,i.m32=e.m32*n);return i},e.subtract=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11-n.m11,i.m12=e.m12-n.m12,i.m21=e.m21-n.m21,i.m22=e.m22-n.m22,i.m31=e.m31-n.m31,i.m32=e.m32-n.m32,i},e}();t.MatrixHelper=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.x=0,this.y=0,this.width=0,this.height=0,this.x=t,this.y=e,this.width=n,this.height=i}return Object.defineProperty(e,"empty",{get:function(){return new e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"maxRect",{get:function(){return new e(Number.MIN_VALUE/2,Number.MIN_VALUE/2,Number.MAX_VALUE,Number.MAX_VALUE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.isEmpty=function(){return 0==this.width&&0==this.height&&0==this.x&&0==this.y},Object.defineProperty(e.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),e.fromMinMax=function(t,n,i,r){return new e(t,n,i-t,r-n)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;oi&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return!1}else{var i=1/t.direction.x,r=(this.x-t.start.x)*i,o=(this.x+this.width-t.start.x)*i;if(r>o){var s=r;r=o,o=s}if(e.value=Math.max(r,e.value),n=Math.min(o,n),e.value>n)return!1}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return!1}else{var a=1/t.direction.y,c=(this.y-t.start.y)*a,h=(this.y+this.height-t.start.y)*a;if(c>h){var u=c;c=h,h=u}if(e.value=Math.max(c,e.value),n=Math.max(h,n),e.value>n)return!1}return!0},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,i.y=n>0?this.y:this.y+n,i.width=t>0?t+this.width:this.width-t,i.height=n>0?n+this.height:this.height-n,i},e.prototype.collisionCheck=function(t,e,n){e.value=n.value=0;var i=t.x-(this.x+this.width),r=t.x+t.width-this.x,o=t.y-(this.y+this.height),s=t.y+t.height-this.y;return!(i>0||r<0||o>0||s<0)&&(e.value=Math.abs(i)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=h>0?l-h:-l-h,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return this.x^this.y^this.width^this.height},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.floor(Math.trunc(this.remainder));return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.HashSet,this._previousTriggerIntersections=new t.HashSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r,o){void 0===o&&(o=new t.Vector2),o.x=0,o.y=0;var s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return!1;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return!1;var l=(h.x*s.y-h.y*s.x)/c;if(l<0||l>1)return!1;var p=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y));return o.x=p.x,o.y=p.y,!0},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.circleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setValues=function(t,e,n,i){this.collider=t,this.fraction=e,this.distance=n,this.point=i},e.prototype.setValuesNonCollider=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset(),this._colliderArray[0]=null},e.clear=function(){this._spatialHash.clear()},e.overlapCircle=function(t,n,i){return void 0===i&&(i=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapCircle(t,n,this._colliderArray,i),this._colliderArray[0]},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.warn("传入了一个空的结果数组。不会返回任何结果")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var n=t.bounds.clone();return this._spatialHash.aabbBroadphase(n,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,n,i,r){void 0===r&&(r=e.allLayers);var o=t.bounds.clone().getSweptBroadphaseBounds(n,i);return this._spatialHash.aabbBroadphase(o,t,r)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.linecast=function(t,n,i){return void 0===i&&(i=e.allLayers),this._hitArray[0].reset(),this.linecastAll(t,n,this._hitArray,i),this._hitArray[0]},e.linecastAll=function(t,n,i,r){return void 0===r&&(r=e.allLayers),0==i.length?(console.warn("传入了一个空的hits数组。没有点击会被返回"),0):this._spatialHash.linecast(t,n,i,r)},e.overlapRectangle=function(t,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,n),this._colliderArray[0]},e.overlapRectangleAll=function(t,n,i){return void 0===i&&(i=e.allLayers),0==n.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,n,i)},e.gravity=new t.Vector2(0,300),e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e._hitArray=[new t.RaycastHit],e._colliderArray=[null],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(e,n){this.start=e,this.end=n,this.direction=t.Vector2.subtract(this.end,this.start)}}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestBox=new t.Box(0,0),this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds.clone();e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(t){for(var e=t.registeredPhysicsBounds.clone(),n=this.cellCoords(e.x,e.y),i=this.cellCoords(e.right,e.bottom),r=n.x;r<=i.x;r++)for(var o=n.y;o<=i.y;o++){var s=this.cellAtPosition(r,o);s?new linq.List(s).remove(t):console.log("从不存在碰撞器的单元格中移除碰撞器: ["+t+"]")}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.clear();for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(null!=c)for(var h=0;h>>0},t.prototype.clear=function(){this._store.clear()},t}();t.NumberDictionary=n;var i=function(){function e(){this._tempHit=new t.RaycastHit,this._checkedColliders=[],this._cellHits=[]}return e.prototype.start=function(t,e,n){this._ray=t,this._hits=e,this._layerMask=n,this.hitCounter=0},e.prototype.checkRayIntersection=function(n,i,r){for(var o=new t.Ref(0),s=0;s=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;rr&&(r=s,i=o)}return e[i]},n.getClosestPointOnPolygonToPoint=function(e,n,i,r){i.value=Number.MAX_VALUE,r.x=0,r.y=0;for(var o=t.Vector2.zero,s=0,a=0;at.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o1)return!1;var a,c=t.Vector2.add(s.start,t.Vector2.multiply(s.direction,new t.Vector2(r.value))),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var u=a+h;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,n){var i=new t.Vector2;return i.x=0==(1&n)?e.right:e.left,i.y=0==(1&n)?e.bottom:e.top,i},e.testCircleBox=function(e,n,i){i=n.bounds.getClosestPointOnRectangleToPoint(e.position);var r=t.Vector2.subtract(i,e.position);return t.Vector2.dot(r,r)<=e.radius*e.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.polygonToPolygon=function(e,n,i){for(var r,o=!0,s=e.edgeNormals.slice(),a=n.edgeNormals.slice(),c=Number.POSITIVE_INFINITY,h=new t.Vector2,u=t.Vector2.subtract(e.position,n.position),l=0;l0&&(o=!1),!o)return!1;(y=Math.abs(y))r.value&&(r.value=o)},e.circleToPolygon=function(e,n,i){void 0===i&&(i=new t.CollisionResult);var r,o=t.Vector2.subtract(e.position,n.position),s=new t.Ref(0),a=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,s,i.normal),c=n.containsPoint(e.position);if(s.value>e.radius*e.radius&&!c)return!1;if(c)r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(s.value)-e.radius));else if(0==s.value)r=new t.Vector2(i.normal.x*e.radius,i.normal.y*e.radius);else{var h=Math.sqrt(s.value);r=t.Vector2.subtract(new t.Vector2(-1),t.Vector2.subtract(o,a)).multiply(new t.Vector2((e.radius-h)/h))}return i.minimumTranslationVector=r,i.point=t.Vector2.add(a,n.position),!0},e.circleToBox=function(e,n,i){void 0===i&&(i=new t.CollisionResult);var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r.clone();var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r1)return!1;var l=(h.x*s.y-h.y*s.x)/c;return!(l<0||l>1)&&(t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(u),s)),!0)},e.lineToCircle=function(e,n,i,r){var o=t.Vector2.distance(e,n),s=t.Vector2.divide(t.Vector2.subtract(n,e),new t.Vector2(o)),a=t.Vector2.subtract(e,i.position),c=t.Vector2.dot(a,s),h=t.Vector2.dot(a,a)-i.radius*i.radius;if(h>0&&c>0)return!1;var u=c*c-h;return!(u<0)&&(r.fraction=-c-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=t.Vector2.add(e,t.Vector2.multiply(new t.Vector2(r.fraction),s)),r.distance=t.Vector2.distance(e,r.point),r.normal=t.Vector2.normalize(t.Vector2.subtract(r.point,i.position)),r.fraction=r.distance/o,!0)},e.boxToBoxCast=function(e,n,i,r){var o=this.minkowskiDifference(e,n);if(o.contains(0,0)){var s=o.getClosestPointOnBoundsToOrigin();return!s.equals(t.Vector2.zero)&&(r.normal=new t.Vector2(-s.x),r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,new t.Vector2(-i.x)),c=new t.Ref(0);return!!(o.rayIntersects(a,c)&&c.value<=1)&&(r.fraction=c.value,r.distance=i.length()*c.value,r.normal=new t.Vector2(-i.x,-i.y),r.normal.normalize(),r.centroid=t.Vector2.add(e.bounds.center,t.Vector2.multiply(i,new t.Vector2(c.value))),!0)},e}();t.ShapeCollisions=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&new linq.List(n).removeAt(i)},t.prototype.emit=function(t){for(var e,n=[],i=1;i=0;o--)(e=r[o].func).call.apply(e,__spread([r[o].context],n))},t}();t.Emitter=n}(es||(es={})),function(t){!function(t){t[t.top=0]="top",t[t.bottom=1]="bottom",t[t.left=2]="left",t[t.right=3]="right"}(t.Edge||(t.Edge={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.repeat=function(t,e){for(var n=[];e--;)n.push(t);return n},t}();t.Enumerable=e}(es||(es={})),function(t){var e=function(){function t(){}return t.default=function(){return new t},t.prototype.equals=function(t,e){return"function"==typeof t.equals?t.equals(e):t===e},t.prototype.getHashCode=function(t){var e=this;if("number"==typeof t)return this._getHashCodeForNumber(t);if("string"==typeof t)return this._getHashCodeForString(t);var n=385229220;return this.forOwn(t,function(t){"number"==typeof t?n+=e._getHashCodeForNumber(t):"string"==typeof t?n+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){n+=e.getHashCode(t)})}),n},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,n=0;n>7,n+=n<<3,n^=n>>17,n+=n<<5},t}();t.Hash=e}(es||(es={})),function(t){var e=function(){return function(t){this.value=t}}();t.Ref=e}(es||(es={})),function(t){var e=function(){function e(){}return Object.defineProperty(e,"size",{get:function(){return new t.Vector2(this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e,"center",{get:function(){return new t.Vector2(this.width/2,this.height/2)},enumerable:!0,configurable:!0}),e}();t.Screen=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelNumber=e}(es||(es={})),function(t){var e=function(){function e(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return e.testPointTriangle=function(e,n,i,r){return!(t.Vector2Ext.cross(t.Vector2.subtract(e,n),t.Vector2.subtract(i,n))<0)&&(!(t.Vector2Ext.cross(t.Vector2.subtract(e,i),t.Vector2.subtract(r,i))<0)&&!(t.Vector2Ext.cross(t.Vector2.subtract(e,r),t.Vector2.subtract(n,r))<0))},e.prototype.triangulate=function(n,i){void 0===i&&(i=!0);var r=n.length;this.initialize(r);for(var o=0,s=0;r>3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengththis._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){return function(t,e){this.element=t,this.next=e}}();function n(t,e){return t===e}t.Node=e,t.defaultEquals=n;var i=function(){function t(t){void 0===t&&(t=n),this.count=0,this.next=void 0,this.equalsFn=t,this.head=null}return t.prototype.push=function(t){var n,i=new e(t);if(null==this.head)this.head=i;else{for(n=this.head;null!=n.next;)n=n.next;n.next=i}this.count++},t.prototype.removeAt=function(t){if(t>=0&&t=0&&t<=this.count){for(var e=this.head,n=0;n=0&&n<=this.count){var i=new e(t);if(0===n)i.next=this.head,this.head=i;else{var r=this.getElementAt(n-1);i.next=r.next,r.next=i}return this.count++,!0}return!1},t.prototype.indexOf=function(t){for(var e=this.head,n=0;n0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.first=t,this.second=e}return e.prototype.clear=function(){this.first=this.second=null},e.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},e.prototype.getHashCode=function(){return 37*t.EqualityComparer.default().getHashCode(this.first)+t.EqualityComparer.default().getHashCode(this.second)},e}();t.Pair=e}(es||(es={})),function(t){var e=function(){function e(){}return e.warmCache=function(t,e){if((e-=this._objectQueue.length)>0)for(var n=0;nthis._objectQueue.length;)this._objectQueue.shift()},e.clearCache=function(){this._objectQueue.length=0},e.obtain=function(t){return this._objectQueue.length>0?this._objectQueue.shift():new t},e.free=function(e){this._objectQueue.unshift(e),t.isIPoolable(e)&&e.reset()},e._objectQueue=[],e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.getHashCode=function(t){return t.getHashCode()},e.prototype.areEqual=function(t,e){return t.equals(e)},e}(function(){function t(t){var e=this;this.clear(),t&&t.forEach(function(t){e.add(t)})}return t.prototype.add=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i){var r=new Array;return r.push(t),this.buckets[n]=r,this.count=this.count+1,!0}return!i.some(function(n){return e.areEqual(n,t)})&&(i.push(t),this.count=this.count+1,!0)},t.prototype.remove=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i)return!1;var r=!1,o=new Array;return i.forEach(function(n){e.areEqual(n,t)?r=!0:o.push(t)}),this.buckets[n]=o,r&&(this.count=this.count-1),r},t.prototype.contains=function(t){return this.bucketsContains(this.buckets,t)},t.prototype.getCount=function(){return this.count},t.prototype.clear=function(){this.buckets=new Array,this.count=0},t.prototype.toArray=function(){var t=new Array;return this.buckets.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},t.prototype.exceptWith=function(t){var e=this;t&&t.forEach(function(t){e.remove(t)})},t.prototype.intersectWith=function(t){var e=this;if(t){var n=this.buildInternalBuckets(t);this.toArray().forEach(function(t){e.bucketsContains(n.Buckets,t)||e.remove(t)})}else this.clear()},t.prototype.unionWith=function(t){var e=this;t.forEach(function(t){e.add(t)})},t.prototype.isSubsetOf=function(t){var e=this,n=this.buildInternalBuckets(t);return this.toArray().every(function(t){return e.bucketsContains(n.Buckets,t)})},t.prototype.isSupersetOf=function(t){var e=this;return t.every(function(t){return e.contains(t)})},t.prototype.overlaps=function(t){var e=this;return t.some(function(t){return e.contains(t)})},t.prototype.setEquals=function(t){var e=this;return this.buildInternalBuckets(t).Count===this.count&&t.every(function(t){return e.contains(t)})},t.prototype.buildInternalBuckets=function(t){var e=this,n=new Array,i=0;return t.forEach(function(t){var r=e.getHashCode(t),o=n[r];if(void 0===o){var s=new Array;s.push(t),n[r]=s,i+=1}else o.some(function(n){return e.areEqual(n,t)})||(o.push(t),i+=1)}),{Buckets:n,Count:i}},t.prototype.bucketsContains=function(t,e){var n=this,i=t[this.getHashCode(e)];return void 0!==i&&i.some(function(t){return n.areEqual(t,e)})},t}());t.HashSet=e}(es||(es={})),function(t){var e=function(){function t(){}return t.waitForSeconds=function(t){return n.waiter.wait(t)},t}();t.Coroutine=e;var n=function(){function t(){this.waitTime=0}return t.prototype.wait=function(e){return t.waiter.waitTime=e,t.waiter},t.waiter=new t,t}();t.WaitForSeconds=n}(es||(es={})),function(t){var e=function(){function t(){this.waitTimer=0,this.useUnscaledDeltaTime=!1}return t.prototype.stop=function(){this.isDone=!0},t.prototype.setUseUnscaledDeltaTime=function(t){return this.useUnscaledDeltaTime=t,this},t.prototype.prepareForUse=function(){this.isDone=!1},t.prototype.reset=function(){this.isDone=!0,this.waitTimer=0,this.waitForCoroutine=null,this.enumerator=null,this.useUnscaledDeltaTime=!1},t}();t.CoroutineImpl=e;var n=function(n){function i(){var t=null!==n&&n.apply(this,arguments)||this;return t._unblockedCoroutines=[],t._shouldRunNextFrame=[],t}return __extends(i,n),i.prototype.startCoroutine=function(n){var i=t.Pool.obtain(e);return i.prepareForUse(),i.enumerator=n,this.tickCoroutine(i)?(this._isInUpdate?this._shouldRunNextFrame.push(i):this._unblockedCoroutines.push(i),i):null},i.prototype.update=function(){this._isInUpdate=!0;for(var e=0;e0?(n.waitTimer-=n.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime,this._shouldRunNextFrame.push(n)):this.tickCoroutine(n)&&this._shouldRunNextFrame.push(n)}}var i=new linq.List(this._unblockedCoroutines);i.clear(),i.addRange(this._shouldRunNextFrame),this._shouldRunNextFrame.length=0,this._isInUpdate=!1},i.prototype.tickCoroutine=function(n){var i=n.enumerator.next();return i.done||n.isDone?(t.Pool.free(n),!1):null==i.value||(i.value instanceof t.WaitForSeconds?(n.waitTimer=i.value.waitTime,!0):"number"==typeof i.value?(n.waitTimer=i.value,!0):"string"==typeof i.value?"break"!=i.value||(t.Pool.free(n),!1):!(i.value instanceof e)||(n.waitForCoroutine=i.value,!0))},i}(t.GlobalManager);t.CoroutineManager=n}(es||(es={})),function(t){var e=function(){function e(t,e,n){void 0===n&&(n=!0),this.binWidth=0,this.binHeight=0,this.usedRectangles=[],this.freeRectangles=[],this.init(t,e,n)}return e.prototype.init=function(e,n,i){void 0===i&&(i=!0),this.binWidth=e,this.binHeight=n,this.allowRotations=i;var r=new t.Rectangle;r.x=0,r.y=0,r.width=e,r.height=n,this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(r)},e.prototype.insert=function(e,n){var i=new t.Rectangle,r=new t.Ref(0),o=new t.Ref(0);if(0==(i=this.findPositionForNewNodeBestAreaFit(e,n,r,o)).height)return i;for(var s=this.freeRectangles.length,a=0;a=e&&this.freeRectangles[s].height>=n){var c=Math.abs(this.freeRectangles[s].width-e),h=Math.abs(this.freeRectangles[s].height-n),u=Math.min(c,h);(a=n&&this.freeRectangles[s].height>=e){c=Math.abs(this.freeRectangles[s].width-n),h=Math.abs(this.freeRectangles[s].height-e),u=Math.min(c,h);(a=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y)return!1;if(e.xt.x){if(e.y>t.y&&e.yt.y){var n;if(e.x>t.x&&e.x=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height},e}();t.MaxRectsBinPack=e}(es||(es={}));var ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t.shuffle=function(t){for(var e=t.length;e>1;){e--;var n=RandomUtils.randint(0,e+1),i=t[n];t[n]=t[e],t[e]=i}},t.addIfNotPresent=function(t,e){return!new linq.List(t).contains(e)&&(t.push(e),!0)},t.lastItem=function(t){return t[t.length-1]},t.randomItem=function(t){return t[RandomUtils.randint(0,t.length-1)]},t.randomItems=function(t,e){for(var n=new Set;n.size!=e;){var i=this.randomItem(t);n.has(i)||n.add(i)}var r=es.ListPool.obtain();return n.forEach(function(t){return r.push(t)}),r},t}();!function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],c=0;c>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(c++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(c++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(n)),64!==s&&a.push(String.fromCharCode(i));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,n,i,r,o,s,a,c=[],h=0;h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c.push(this._keyStr.charAt(r)),c.push(this._keyStr.charAt(o)),c.push(this._keyStr.charAt(s)),c.push(this._keyStr.charAt(a));return c=c.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random().5?1:-1},t}();!function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,i.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e.boundsFromPolygonVector=function(e){for(var n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,s=0;sr&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(n,i),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,n){return new t.Rectangle(e.x,e.y,n.x-e.x,n.y-e.y)},e.getSweptBroadphaseBounds=function(e,n,i){var r=t.Rectangle.empty;return r.x=n>0?e.x:e.x+n,r.y=i>0?e.y:e.y+i,r.width=n>0?n+e.width:e.width-n,r.height=i>0?i+e.height:e.height-i,r},e.prototype.collisionCheck=function(t,e,n,i){n.value=i.value=0;var r=e.x-(t.x+t.width),o=e.x+e.width-t.x,s=e.y-(t.y+t.height),a=e.y+e.height-t.y;return!(r>0||o<0||s>0||a<0)&&(n.value=Math.abs(r)=l||Math.abs(u)>=p)return t.Vector2.zero;var f=h>0?l-h:-l-h,d=u>0?p-u:-p-u;return new t.Vector2(f,d)},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function t(){}return t.premultiplyAlpha=function(t){for(var e=t[0],n=0;nt.MathHelper.Epsilon?e.divide(new t.Vector2(n)):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){return this.sum(t)/this.count(t)},e.prototype.cast=function(){return new e(this._elements)},e.prototype.clear=function(){this._elements.length=0},e.prototype.concat=function(t){return new e(this._elements.concat(t.toArray()))},e.prototype.contains=function(t){return this.any(function(e){return e===t})},e.prototype.count=function(t){return t?this.where(t).count():this._elements.length},e.prototype.defaultIfEmpty=function(t){return this.count()?this:new e([t])},e.prototype.distinctBy=function(t){var n=this.groupBy(t);return Object.keys(n).reduce(function(t,e){return t.add(n[e][0]),t},new e)},e.prototype.elementAt=function(t){if(t=0)return this._elements[t];throw new Error("ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.")},e.prototype.elementAtOrDefault=function(t){return t=0?this._elements[t]:void 0},e.prototype.except=function(t){return this.where(function(e){return!t.contains(e)})},e.prototype.first=function(t){if(this.count())return t?this.where(t).first():this._elements[0];throw new Error("InvalidOperationException: The source sequence is empty.")},e.prototype.firstOrDefault=function(t){return this.count(t)?this.first(t):void 0},e.prototype.forEach=function(t){return this._elements.forEach(t)},e.prototype.groupBy=function(t,e){void 0===e&&(e=function(t){return t});return this.aggregate(function(n,i){var r=t(i),o=n[r],s=e(i);return o?o.push(s):n[r]=[s],n},{})},e.prototype.groupJoin=function(t,e,n,i){return this.select(function(r){return i(r,t.where(function(t){return e(r)===n(t)}))})},e.prototype.indexOf=function(t){return this._elements.indexOf(t)},e.prototype.insert=function(t,e){if(t<0||t>this._elements.length)throw new Error("Index is out of range.");this._elements.splice(t,0,e)},e.prototype.intersect=function(t){return this.where(function(e){return t.contains(e)})},e.prototype.join=function(t,e,n,i){return this.selectMany(function(r){return t.where(function(t){return n(t)===e(r)}).select(function(t){return i(r,t)})})},e.prototype.last=function(t){if(this.count())return t?this.where(t).last():this._elements[this.count()-1];throw Error("InvalidOperationException: The source sequence is empty.")},e.prototype.lastOrDefault=function(t){return this.count(t)?this.last(t):void 0},e.prototype.max=function(t){return Math.max.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.min=function(t){return Math.min.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.ofType=function(t){var e;switch(t){case Number:e="number";break;case String:e="string";break;case Boolean:e=typeof!0;break;case Function:e="function";break;default:e=null}return null===e?this.where(function(e){return e instanceof t}).cast():this.where(function(t){return typeof t===e}).cast()},e.prototype.orderBy=function(e,i){return void 0===i&&(i=t.keyComparer(e,!1)),new n(this._elements,i)},e.prototype.orderByDescending=function(e,i){return void 0===i&&(i=t.keyComparer(e,!0)),new n(this._elements,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){return-1!==this.indexOf(t)&&(this.removeAt(this.indexOf(t)),!0)},e.prototype.removeAll=function(e){return this.where(t.negate(e))},e.prototype.removeAt=function(t){this._elements.splice(t,1)},e.prototype.reverse=function(){return new e(this._elements.reverse())},e.prototype.select=function(t){return new e(this._elements.map(t))},e.prototype.selectMany=function(t){var n=this;return this.aggregate(function(e,i,r){return e.addRange(n.select(t).elementAt(r).toArray()),e},new e)},e.prototype.sequenceEqual=function(t){return this.all(function(e){return t.contains(e)})},e.prototype.single=function(t){if(1!==this.count(t))throw new Error("The collection does not contain exactly one element.");return this.first(t)},e.prototype.singleOrDefault=function(t){return this.count(t)?this.single(t):void 0},e.prototype.skip=function(t){return new e(this._elements.slice(Math.max(0,t)))},e.prototype.skipLast=function(t){return new e(this._elements.slice(0,-Math.max(0,t)))},e.prototype.skipWhile=function(t){var e=this;return this.skip(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.sum=function(t){return t?this.select(t).sum():this.aggregate(function(t,e){return t+ +e},0)},e.prototype.take=function(t){return new e(this._elements.slice(0,Math.max(0,t)))},e.prototype.takeLast=function(t){return new e(this._elements.slice(-Math.max(0,t)))},e.prototype.takeWhile=function(t){var e=this;return this.take(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.toArray=function(){return this._elements},e.prototype.toDictionary=function(t,n){var i=this;return this.aggregate(function(e,r,o){return e[i.select(t).elementAt(o).toString()]=n?i.select(n).elementAt(o):r,e.add({Key:i.select(t).elementAt(o),Value:n?i.select(n).elementAt(o):r}),e},new e)},e.prototype.toSet=function(){var t,e,n=new Set;try{for(var i=__values(this._elements),r=i.next();!r.done;r=i.next()){var o=r.value;n.add(o)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return n},e.prototype.toList=function(){return this},e.prototype.toLookup=function(t,e){return this.groupBy(t,e)},e.prototype.where=function(t){return new e(this._elements.filter(t))},e.prototype.zip=function(t,e){var n=this;return t.count()e.angle?1:t.angleMath.PI&&(o-=2*Math.PI),r.p1.begin=o>0,r.p2.begin=!r.p1.begin}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}this._isSpotLight&&(this._spotStartAngle=this._segments[0].p2.angle,this._spotEndAngle=this._segments[1].p2.angle)},e._cornerCache=[],e._openSegments=new t.LinkedList,e}();t.VisibilityComputer=e}(es||(es={})),function(t){var e=function(){function e(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}return e.prototype.getContext=function(){return this.context},e.prototype.reset=function(){this._elapsedTime=0},e.prototype.stop=function(){this._isDone=!0},e.prototype.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=t.Time.deltaTime,this._isDone},e.prototype.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),new linq.List(this._timers).removeAt(t))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file diff --git a/source/src/Core.ts b/source/src/Core.ts new file mode 100644 index 00000000..c45fcd99 --- /dev/null +++ b/source/src/Core.ts @@ -0,0 +1,197 @@ +module es { + /** + * 全局核心类 + */ + export class Core { + /** + * 核心发射器。只发出核心级别的事件 + */ + public static emitter: Emitter; + /** + * 启用/禁用焦点丢失时的暂停。如果为真,则不调用更新或渲染方法 + */ + public static pauseOnFocusLost = true; + /** + * 是否启用调试渲染 + */ + public static debugRenderEndabled = false; + /** + * 简化对内部类的全局内容实例的访问 + */ + public static _instance: Core; + /** + * 用于确定是否应该使用EntitySystems + */ + public static entitySystemsEnabled: boolean; + + public _nextScene: Scene; + /** + * 用于凝聚GraphicsDeviceReset事件 + */ + public _graphicsDeviceChangeTimer: ITimer; + /** + * 全局访问系统 + */ + public _globalManagers: GlobalManager[] = []; + public _coroutineManager: CoroutineManager = new CoroutineManager(); + public _timerManager: TimerManager = new TimerManager(); + public width: number; + public height: number; + + constructor(width: number, height: number, enableEntitySystems: boolean = true) { + this.width = width; + this.height = height; + + Core._instance = this; + Core.emitter = new Emitter(); + Core.emitter.addObserver(CoreEvents.frameUpdated, this.update, this); + + Core.registerGlobalManager(this._coroutineManager); + Core.registerGlobalManager(this._timerManager); + Core.entitySystemsEnabled = enableEntitySystems; + + this.initialize(); + } + + /** + * 提供对单例/游戏实例的访问 + * @constructor + */ + public static get Instance() { + return this._instance; + } + + public _frameCounterElapsedTime: number = 0; + public _frameCounter: number = 0; + public _totalMemory: number = 0; + public _titleMemory: (totalMemory: number, frameCounter: number) => void; + public _scene: Scene; + + /** + * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 + */ + public static get scene() { + if (!this._instance) + return null; + return this._instance._scene; + } + + /** + * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 + * @param value + */ + public static set scene(value: Scene) { + if (!value) { + console.error("场景不能为空"); + return; + } + + if (this._instance._scene == null) { + this._instance._scene = value; + this._instance.onSceneChanged(); + this._instance._scene.begin(); + } else { + this._instance._nextScene = value; + } + } + + /** + * 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。 + * @param manager + */ + public static registerGlobalManager(manager: es.GlobalManager) { + this._instance._globalManagers.push(manager); + manager.enabled = true; + } + + /** + * 删除全局管理器对象 + * @param manager + */ + public static unregisterGlobalManager(manager: es.GlobalManager) { + new linq.List(this._instance._globalManagers).remove(manager); + manager.enabled = false; + } + + /** + * 获取类型为T的全局管理器 + * @param type + */ + public static getGlobalManager(type): T { + for (let i = 0; i < this._instance._globalManagers.length; i++) { + if (this._instance._globalManagers[i] instanceof type) + return this._instance._globalManagers[i] as T; + } + return null; + } + + /** + * 启动一个coroutine。Coroutine可以将number延时几秒或延时到其他startCoroutine.Yielding + * null将使coroutine在下一帧被执行。 + * @param enumerator + */ + public static startCoroutine(enumerator): ICoroutine { + return this._instance._coroutineManager.startCoroutine(enumerator); + } + + /** + * 调度一个一次性或重复的计时器,该计时器将调用已传递的动作 + * @param timeInSeconds + * @param repeats + * @param context + * @param onTime + */ + public static schedule(timeInSeconds: number, repeats: boolean = false, context: any = null, onTime: (timer: ITimer) => void) { + return this._instance._timerManager.schedule(timeInSeconds, repeats, context, onTime); + } + + public startDebugDraw() { + this._frameCounter++; + this._frameCounterElapsedTime += Time.deltaTime; + if (this._frameCounterElapsedTime >= 1) { + let memoryInfo = window.performance["memory"]; + if (memoryInfo != null) { + this._totalMemory = Number((memoryInfo.totalJSHeapSize / 1048576).toFixed(2)); + } + if (this._titleMemory) this._titleMemory(this._totalMemory, this._frameCounter); + this._frameCounter = 0; + this._frameCounterElapsedTime -= 1; + } + } + + /** + * 在一个场景结束后,下一个场景开始之前调用 + */ + public onSceneChanged() { + Time.sceneChanged(); + } + + protected initialize() { + + } + + protected async update(currentTime?: number) { + if (currentTime != null) Time.update(currentTime); + if (this._scene != null) { + for (let i = this._globalManagers.length - 1; i >= 0; i--) { + if (this._globalManagers[i].enabled) + this._globalManagers[i].update(); + } + + this._scene.update(); + + if (this._nextScene != null) { + this._scene.end(); + + this._scene = this._nextScene; + this._nextScene = null; + this.onSceneChanged(); + + this._scene.begin(); + } + } + + this.startDebugDraw(); + } + } +} diff --git a/source/src/ECS/Component.ts b/source/src/ECS/Component.ts index ea3a8cfd..4f918269 100644 --- a/source/src/ECS/Component.ts +++ b/source/src/ECS/Component.ts @@ -78,9 +78,6 @@ module es { public onEntityTransformChanged(comp: transform.Component) { } - public debugRender(batcher: IBatcher) { - } - /** *当父实体或此组件启用时调用 */ diff --git a/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts b/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts index ce95c4a0..e1738c43 100644 --- a/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts @@ -84,14 +84,6 @@ module es { } } - public debugRender(batcher: IBatcher) { - let poly = this.shape as Polygon; - batcher.drawHollowRect(this.bounds, Debug.colliderBounds, 1); - batcher.drawPolygon(this.shape.position, poly.points, Debug.colliderEdge, true, 1); - batcher.drawPixel(this.entity.transform.position, Debug.colliderPosition, 4); - batcher.drawPixel(Vector2.add(this.entity.transform.position, this.shape.center), Debug.colliderCenter, 2); - } - public toString() { return `[BoxCollider: bounds: ${this.bounds}]`; } diff --git a/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts b/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts index d041da77..b7908563 100644 --- a/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts @@ -40,13 +40,6 @@ module es { return this; } - public debugRender(batcher: IBatcher) { - batcher.drawHollowRect(this.bounds, Debug.colliderBounds, 1); - batcher.drawCircle(this.shape.position, (this.shape as Circle).radius, Debug.colliderEdge, 1); - batcher.drawPixel(this.entity.transform.position, Debug.colliderPosition, 4); - batcher.drawPixel(this.shape.position, Debug.colliderCenter, 2); - } - public toString() { return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]` } diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index fcc9d837..b977e496 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -114,32 +114,6 @@ module es { } public onAddedToEntity() { - if (this._colliderRequiresAutoSizing) { - Insist.isTrue(this instanceof BoxCollider || this instanceof CircleCollider, "只有框和圆的碰撞器可以自动创建"); - - let renderable = this.entity.getComponent(RenderableComponent); - if (renderable == null) - console.warn("Collider没有形状,也没有RenderableComponent。不知道如何确定它的大小。"); - if (renderable != null) { - let renderableBounds = renderable.bounds.clone(); - - // 我们在这里需要大小*反比例,因为当我们自动调整Collider的大小时,它需要没有一个缩放的Renderable - let width = renderableBounds.width / this.entity.transform.scale.x; - let height = renderableBounds.height / this.entity.transform.scale.y; - - if (this instanceof CircleCollider) { - this.radius = Math.max(width, height) * 0.5; - // 获取Renderable的中心,将其转移到本地坐标,并将其作为我们碰撞器的localOffset - this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position); - } else if (this instanceof BoxCollider) { - this.width = width; - this.height = height; - - this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position); - } - } - } - this._isParentEntityAddedToScene = true; this.registerColliderWithPhysicsSystem(); } diff --git a/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts b/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts index 3714f6cf..5ca107db 100644 --- a/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts @@ -23,13 +23,5 @@ module es { Polygon.recenterPolygonVerts(points); this.shape = new Polygon(points); } - - public debugRender(batcher: IBatcher) { - let poly = this.shape as Polygon; - batcher.drawHollowRect(this.bounds, Debug.colliderBounds, 1); - batcher.drawPolygon(this.shape.position, poly.points, Debug.colliderEdge, true, 1); - batcher.drawPixel(this.entity.transform.position, Debug.colliderPosition, 4); - batcher.drawPixel(this.shape.position, Debug.colliderCenter, 2); - } } } diff --git a/source/src/ECS/Components/Renderables/IRenderable.ts b/source/src/ECS/Components/Renderables/IRenderable.ts deleted file mode 100644 index a5e14ecb..00000000 --- a/source/src/ECS/Components/Renderables/IRenderable.ts +++ /dev/null @@ -1,80 +0,0 @@ -module es { - /** - * 接口,当应用于一个Component时,它将被注册到场景渲染器中。 - * 请仔细实现这个功能 改变像layerDepth/renderLayer/material这样的东西需要更新Scene RenderableComponentList - */ - export interface IRenderable { - /** 包裹此对象的AABB。用来进行相机筛选 */ - bounds: Rectangle; - /** 这个IRenderable是否应该被渲染 */ - enabled: boolean; - /** - * 标准的Batcher图层深度,0为前面,1为后面。 - * 改变这个值会触发场景中可渲染组件列表的排序 - */ - layerDepth: number; - /** - * 较低的renderLayers在前面,较高的在後面,就像layerDepth一样,但不是限制在0-1。 - * 请注意,这意味着较高的renderLayers首先被发送到Batcher。在使用模板缓冲区时,这是一个重要的事实 - */ - renderLayer: number; - /** - * 由渲染器使用,用于指定该精灵应如何渲染。 - * 如果非空,当组件从实体中移除时,它会被自动处理。 - */ - material; - /** - * 这个Renderable的可见性。 - * 状态的改变最终会调用onBecameVisible/onBecameInvisible方法 - */ - isVisible: boolean; - /** - * 用于检索一个已经铸造的Material子类的帮助程序 - */ - getMaterial(): T; - /** - * 如果Renderables的边界与Camera.bounds相交,则返回true。 - * 处理isVisible标志的状态切换。 - * 在你的渲染方法中使用这个方法来决定你是否应该渲染 - * @param camera - */ - isVisibleFromCamera(camera: ICamera): boolean; - /** - * 被渲染器调用。摄像机可以用来进行裁剪,并使用Batcher实例进行绘制 - * @param batcher - * @param camera - */ - render(batcher: IBatcher, camera: ICamera); - /** - * 只有在没有对撞机的情况下才会渲染边界。 - * 始终在原点上渲染一个正方形 - * @param batcher - */ - debugRender(batcher: IBatcher); - } - - /** - * 对IRenderables进行排序的比较器。 - * 首先按 RenderLayer 排序,然后按 LayerDepth 排序。 - * 如果出现平局,则使用材料作为平局的断定器,以避免渲染状态的改变 - */ - export class RenderableComparer implements IComparer { - public compare(self: IRenderable, other: IRenderable): number { - let res = other.renderLayer - self.renderLayer; - if (res == 0) { - res = other.layerDepth - self.layerDepth; - if (res == 0) { - if (self.material == other.material) - return 0; - - if (other.material == null) - return -1; - - return 1; - } - } - - return res; - } - } -} \ No newline at end of file diff --git a/source/src/ECS/Components/Renderables/RenderableComponent.ts b/source/src/ECS/Components/Renderables/RenderableComponent.ts deleted file mode 100644 index ae0ad9e5..00000000 --- a/source/src/ECS/Components/Renderables/RenderableComponent.ts +++ /dev/null @@ -1,230 +0,0 @@ -module es { - /** - * IRenderable的具体实现。包含方便的方法。 - * 非常重要!子类必须覆盖width/height或bounds! 子类必须覆盖width/height或bounds! - */ - export abstract class RenderableComponent extends Component implements IRenderable, IComparer { - public static renderIdGenerator: number = 0; - /** - * 不重写bounds属性的子类必须实现这个!RenderableComponent的宽度。 - */ - public abstract get width(); - - /** - * 不重写bounds属性的子类必须实现这个! - */ - public abstract get height(); - - /** - * 包裹此对象的AABB。用来进行相机筛选。 - */ - public abstract get bounds(); - - /** - * 标准的Batcher图层深度,0为前面,1为后面。 - * 改变这个值会触发场景中可渲染组件列表的排序。 - */ - public get layerDepth() { - return this._layerDepth; - } - public set layerDepth(value: number) { - this.setLayerDepth(value); - } - - /** - * 较低的renderLayers在前面,较高的在后面,就像layerDepth一樣,但不是限制在0-1。 - * 请注意,这意味着更高的renderLayers首先被发送到Batcher。 - */ - public get renderLayer() { - return this._renderLayer; - } - public set renderLayer(value: number) { - this.setRenderLayer(value); - } - - /** - * 渲染时传递给批处理程序的颜色 - */ - public color: number = 0xffffff; - - /** - * 由渲染器使用,用于指定该精灵的渲染方式 - */ - public material: IMaterial; - /** - * 偏移。用于将多个Renderables添加到需要特定定位的实体 - */ - public get localOffset(): Vector2 { - return this._localOffset; - } - public set localOffset(value: Vector2) { - this.setLocalOffset(value); - } - /** - * 这个Renderable的可见性。 - * 状态的改变最终会调用onBecameVisible/onBecameInvisible方法 - */ - public get isVisible() { - return this._isVisble; - } - public set isVisible(value: boolean) { - if (this._isVisble != value) { - this._isVisble = value; - - if (this._isVisble) - this.onBecameVisible(); - else - this.onBecameInvisible(); - } - } - - constructor() { - super(); - } - - public debugRenderEnabled: boolean = true; - - protected _localOffset: Vector2 = Vector2.zero; - protected _layerDepth: number; - protected _renderLayer: number; - protected _bounds: Rectangle = Rectangle.empty; - protected _isVisble: boolean; - - protected _areBoundsDirty: boolean = true; - - public onEntityTransformChanged(comp: transform.Component) { - this._areBoundsDirty = true; - } - - /** - * 被渲染器调用。摄像机可以用来进行裁剪,并使用Batcher实例进行绘制 - * @param batcher - * @param camera - */ - public abstract render(batcher: IBatcher, camera: ICamera); - - /** - * 只有在没有对撞机的情况下才会渲染边界。始终在原点上渲染一个正方形 - * @param batcher - */ - public debugRender(batcher: IBatcher) { - if (!this.debugRenderEnabled) - return; - - // 如果我们没有对撞机,我们就画出我们的范围 - if (this.entity.getComponent(Collider) == null) - batcher.drawHollowRect(this.bounds, 0xFFFF00); - - batcher.drawPixel(this.entity.transform.position.add(this._localOffset), 0xcc3299, 4); - } - - /** - * 当Renderable进入相机帧时被调用。 - * 请注意,如果您的Renderer没有使用isVisibleFromCamera来进行裁剪检查,这些方法将不会被调用。 - * 所有默认的Renderer都会这样做 - */ - protected onBecameVisible() { - - } - - /** - * 当渲染器退出相机帧时,将调用这些方法。 - * 请注意,如果你的Renderer没有使用isVisibleFromCamera来进行Culling检查,这些方法将不会被调用。 - * 所有默认的Renderer都会这样做 - */ - protected onBecameInvisible() { - - } - - public onRemovedFromEntity() { - - } - - /** - * 如果Renderables的边界与Camera.bounds相交,则返回true。 - * 处理isVisible标志的状态切换。在你的渲染方法中使用这个方法来决定你是否应该渲染 - * @param camera - */ - public isVisibleFromCamera(camera: ICamera) { - this.isVisible = camera.bounds.intersects(this.bounds); - return this.isVisible; - } - - public setMaterial(material: IMaterial) { - this.material = material; - if (this.entity != null && this.entity.scene != null) - this.entity.scene.renderableComponents.setRenderLayerNeedsComponentSort(this.renderLayer); - return this; - } - - /** - * 标准的Batcher图层深度,0为前面,1为后面。 - * 改变这个值会触发一种类似于renderableComponents的方法 - * @param layerDepth - */ - public setLayerDepth(layerDepth: number): RenderableComponent { - this._layerDepth = MathHelper.clamp01(layerDepth); - - if (this.entity != null && this.entity.scene != null) - this.entity.scene.renderableComponents.setRenderLayerNeedsComponentSort(this.renderLayer); - return this; - } - - /** - * 较低的渲染层在前面,较高的在后面 - * @param renderLayer - */ - public setRenderLayer(renderLayer: number): RenderableComponent { - if (renderLayer != this._renderLayer) { - let oldRenderLayer = this._renderLayer; - this._renderLayer = renderLayer; - - // 如果该组件拥有一个实体,那么是由ComponentList管理,需要通知它改变了渲染层 - if (this.entity && this.entity.scene) - this.entity.scene.renderableComponents.updateRenderableRenderLayer(this, oldRenderLayer, this._renderLayer); - } - - return this; - } - - /** - * 偏移。用于将多个Renderables添加到需要特定定位的实体 - * @param offset - */ - public setLocalOffset(offset: Vector2): RenderableComponent { - if (!this._localOffset.equals(offset)) { - this._localOffset = offset; - this._areBoundsDirty = true; - } - - return this; - } - - /** - * 用于检索一个已经铸造的Material子类的帮助程序 - */ - public getMaterial(): T { - return this.material as T; - } - - /** - * 先按renderLayer排序,再按layerDepth排序,最后按材质排序 - * @param other - */ - public compare(other: RenderableComponent) { - let res = other.renderLayer - this.renderLayer; - if (res == 0) { - res = other.layerDepth - this.layerDepth; - if (res == 0) { - if (this.material == other.material) - return 0; - - if (other.material == null) - return -1; - - return 1; - } - } - } - } -} \ No newline at end of file diff --git a/source/src/ECS/CoreEvents.ts b/source/src/ECS/CoreEvents.ts index 231fb526..53b4e93a 100644 --- a/source/src/ECS/CoreEvents.ts +++ b/source/src/ECS/CoreEvents.ts @@ -1,29 +1,12 @@ module es { export enum CoreEvents { - /** - * 在图形设备重置时触发。当这种情况发生时,任何渲染目标或其他内容的VRAM将被擦除,需要重新生成 - */ - graphicsDeviceReset, /** * 当场景发生变化时触发 */ sceneChanged, /** - * 当设备方向改变时触发 + * 每帧更新事件 */ - orientationChanged, - /** - * 当Core.useCustomUpdate为true时则派发该事件 - */ - sceneUpdated, - addDefaultRender, - setRenderTarget, - clearGraphics, - disposeRenderTarget, - resolutionScale, - resolutionOffset, - createRenderTarget, - createCamera, - rendererSizeChanged, + frameUpdated, } } diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 99f4f3d2..18835822 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -380,14 +380,6 @@ module es { this.components.update(); } - /** - * 自定义渲染器可以选择是否调用它 - * @param batcher - */ - public debugRender(batcher: IBatcher) { - this.components.debugRender(batcher); - } - /** * 将组件添加到组件列表中。返回组件。 * @param component diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts index 79a1cd70..c21f49c0 100644 --- a/source/src/ECS/Scene.ts +++ b/source/src/ECS/Scene.ts @@ -13,105 +13,23 @@ module es { /** 场景 */ export class Scene { - /** - * 默认场景 摄像机 - */ - public camera: ICamera; /** * 这个场景中的实体列表 */ public readonly entities: EntityList; - /** 管理当前在场景中的所有RenderableComponents的列表 Entitys */ - public readonly renderableComponents: RenderableComponentList; - /** - * 如果ResolutionPolicy是完美的像素,这将被设置为为它计算的比例 - */ - public pixelPerfectScale: number = 1; - /** - * 如果设置了,最终渲染到屏幕上的时间可以推迟到这个委托。 - * 这实际上只在最终渲染可能需要全屏大小效果的情况下有用,即使使用了一个小的后置缓冲区 - */ - public set finalRenderDelegate(value: IFinalRenderDelegate) { - if (this._finalRenderDelegate != null) - this._finalRenderDelegate.unload(); - this._finalRenderDelegate = value; - - if (this._finalRenderDelegate != null) - this._finalRenderDelegate.onAddedToScene(this); - } - - public get finalRenderDelegate() { - return this._finalRenderDelegate; - } - - private _finalRenderDelegate: IFinalRenderDelegate; /** * 管理所有实体处理器 */ public readonly entityProcessors: EntityProcessorList; - /** - * 所有场景的默认分辨率大小 - */ - private static _defaultDesignResolutionSize: Vector2 = Vector2.zero; - private static _defaultDesignBleedSize: Vector2 = Vector2.zero; - /** - * 用于所有场景的默认分辨率策略 - */ - private static _defaultSceneResolutionPolicy: SceneResolutionPolicy = SceneResolutionPolicy.none; - /** - * 场景的解析策略 - */ - private _resolutionPolicy: SceneResolutionPolicy; - /** - * 场景使用的设计分辨率大小 - */ - private _designResolutionSize: Vector2 = Vector2.zero; - private _designBleedSize: Vector2 = Vector2.zero; - /** - * 这将根据分辨率策略进行设置,并用于RenderTarget的最终输出 - */ - private _finalRenderDestinationRect: Rectangle = Rectangle.empty; - - private _sceneRenderTarget: Ref = new Ref(null); - private _destinationRenderTarget: Ref = new Ref(null); - private _screenshotRequestCallback: (texture) => void; public readonly _sceneComponents: SceneComponent[] = []; - public _renderers: IRenderer[] = []; - public readonly _afterPostProcessorRenderers: IRenderer[] = []; private _didSceneBegin: boolean; - private currentRenderId: Ref = new Ref(null); - - /** - * 设置新场景将使用的默认设计尺寸和分辨率策略,水平/垂直Bleed仅与BestFit相关 - * @param width - * @param height - * @param sceneResolutionPolicy - * @param horizontalBleed - * @param vertialcalBleed - */ - public static setDefaultDesignResolution(width: number, height: number, - sceneResolutionPolicy: SceneResolutionPolicy, - horizontalBleed: number = 0, vertialcalBleed: number = 0) { - this._defaultDesignBleedSize = new Vector2(width, height); - this._defaultSceneResolutionPolicy = sceneResolutionPolicy; - if (this._defaultSceneResolutionPolicy == SceneResolutionPolicy.bestFit) - this._defaultDesignBleedSize = new Vector2(horizontalBleed, vertialcalBleed); - } - constructor() { this.entities = new EntityList(this); - this.renderableComponents = new RenderableComponentList(); this.entityProcessors = new EntityProcessorList(); - Framework.emitter.emit(CoreEvents.createCamera, this); - - this._resolutionPolicy = Scene._defaultSceneResolutionPolicy; - this._designResolutionSize = Scene._defaultDesignResolutionSize; - this._designBleedSize = Scene._defaultDesignBleedSize; - this.initialize(); } @@ -136,16 +54,7 @@ module es { } public begin() { - if (this._renderers.length == 0) { - Framework.emitter.emit(CoreEvents.addDefaultRender); - console.warn("场景开始时没有渲染器"); - } - Physics.reset(); - this.updateResolutionScaler(); - Framework.emitter.emit(CoreEvents.setRenderTarget, this._sceneRenderTarget); - Framework.emitter.addObserver(CoreEvents.graphicsDeviceReset, this.updateResolutionScaler, this); - Framework.emitter.addObserver(CoreEvents.orientationChanged, this.updateResolutionScaler, this); if (this.entityProcessors != null) this.entityProcessors.begin(); @@ -158,10 +67,6 @@ module es { public end() { this._didSceneBegin = false; - for (let i = 0; i < this._renderers.length; i++) - this._renderers[i].unload(); - - Framework.emitter.removeObserver(CoreEvents.graphicsDeviceReset, this.updateResolutionScaler); this.entities.removeAllEntities(); for (let i = 0; i < this._sceneComponents.length; i++) { @@ -169,9 +74,6 @@ module es { } this._sceneComponents.length = 0; - this.camera = null; - Framework.emitter.emit(CoreEvents.disposeRenderTarget, this._sceneRenderTarget); - Framework.emitter.emit(CoreEvents.disposeRenderTarget, this._destinationRenderTarget); Physics.clear(); if (this.entityProcessors) @@ -180,107 +82,7 @@ module es { this.unload(); } - public updateResolutionScaler() { - let designSize = this._designResolutionSize; - let screenSize = new Vector2(Screen.width, Screen.height); - let screenAspectRatio = screenSize.x / screenSize.y; - - let renderTargetWidth = screenSize.x; - let renderTargetHeight = screenSize.y; - - let resolutionScaleX = screenSize.x / designSize.x; - let resolutionScaleY = screenSize.y / designSize.y; - - let rectCalculated = false; - - // 计算PixelPerfect变体所使用的比例 - this.pixelPerfectScale = 1; - if (this._resolutionPolicy != SceneResolutionPolicy.none) { - if (designSize.x / designSize.y > screenAspectRatio) - this.pixelPerfectScale = screenSize.x / designSize.x; - else - this.pixelPerfectScale = screenSize.y / designSize.y; - - if (this.pixelPerfectScale == 0) - this.pixelPerfectScale = 1; - } - - switch (this._resolutionPolicy) { - case SceneResolutionPolicy.none: - this._finalRenderDestinationRect.x = this._finalRenderDestinationRect.y = 0; - this._finalRenderDestinationRect.width = screenSize.x; - this._finalRenderDestinationRect.height = screenSize.y; - rectCalculated = true; - break; - case SceneResolutionPolicy.bestFit: - let safeScaleX = screenSize.x / (designSize.x - this._designBleedSize.x); - let safeScaleY = screenSize.y / (designSize.y - this._designBleedSize.y); - - let resolutionScale = Math.max(resolutionScaleX, resolutionScaleY); - let safeScale = Math.min(safeScaleX, safeScaleY); - - resolutionScaleX = resolutionScaleY = Math.min(resolutionScale, safeScale); - - renderTargetWidth = designSize.x; - renderTargetHeight = designSize.y; - - break; - } - - // 如果我们还没有计算出一个矩形 - if (!rectCalculated) { - // 计算RenderTarget的显示矩形 - let renderWidth = designSize.x * resolutionScaleX; - let renderHeight = designSize.y * resolutionScaleY; - - this._finalRenderDestinationRect = new Rectangle((screenSize.x - renderWidth) / 2, - (screenSize.y - renderHeight) / 2, renderWidth, renderHeight); - } - - // 在Input类中设置一些值,将鼠标位置转换为我们的缩放分辨率 - let scaleX = renderTargetWidth / this._finalRenderDestinationRect.width; - let scaleY = renderTargetHeight / this._finalRenderDestinationRect.height; - - Framework.emitter.emit(CoreEvents.resolutionScale, new Vector2(scaleX, scaleY)); - Framework.emitter.emit(CoreEvents.resolutionOffset, this._finalRenderDestinationRect.location); - - // 调整我们的RenderTargets大小 - if (this._sceneRenderTarget != null) - Framework.emitter.emit(CoreEvents.disposeRenderTarget, this._sceneRenderTarget); - Framework.emitter.emit(CoreEvents.createRenderTarget, this._sceneRenderTarget, renderTargetWidth, renderTargetHeight); - - // 只有在已经存在的情况下才会创建 destinationRenderTarget - if (this._destinationRenderTarget != null) { - Framework.emitter.emit(CoreEvents.disposeRenderTarget, this._destinationRenderTarget); - Framework.emitter.emit(CoreEvents.createRenderTarget, this._destinationRenderTarget, renderTargetWidth, renderTargetHeight); - } - - // 通知渲染器、后处理器和FinalRenderDelegate渲染纹理尺寸的变化 - for (let i = 0; i < this._renderers.length; i++) - this._renderers[i].onSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight); - - for (let i = 0; i < this._afterPostProcessorRenderers.length; i++) - this._afterPostProcessorRenderers[i].onSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight); - - if (this._finalRenderDelegate != null) - this._finalRenderDelegate.onSceneBackBufferSizeChanged(renderTargetWidth, renderTargetHeight); - - this.camera.onSceneRenderTargetSizeChanged(renderTargetWidth, renderTargetHeight); - } - - /** - * 下一次绘制完成后,这将克隆回缓冲区,并调用回调与clone。 - * 注意,当使用完Texture后,你必须处理掉它 - * @param callback - */ - public requestScreenshot(callback: (texture) => void) { - this._screenshotRequestCallback = callback; - } - public update() { - // 我们在这里设置RenderTarget,这样Viewport就会与RenderTarget正确匹配 - Framework.emitter.emit(CoreEvents.setRenderTarget, this._sceneRenderTarget); - // 更新我们的列表,以防它们有任何变化 this.entities.updateLists(); @@ -296,92 +98,10 @@ module es { // 更新我们的实体组 this.entities.update(); - // 我们在entity.update之后更新我们的renderables,以防止任何新的Renderables被添加 - this.renderableComponents.updateList(); - if (this.entityProcessors != null) this.entityProcessors.lateUpdate(); } - public render() { - if (this._renderers.length == 0) { - console.error("场景中没有渲染器!"); - return; - } - - // 渲染器应该总是先有那些需要RenderTarget的。 - // 他们在渲染的时候会自己清空并设置自己为当前的RenderTarget。 - // 如果第一个Renderer想要sceneRenderTarget,我们现在就设置并清除它 - if (this._renderers[0].wantsToRenderToSceneRenderTarget) { - Framework.emitter.emit(CoreEvents.setRenderTarget, this._sceneRenderTarget); - Framework.emitter.emit(CoreEvents.clearGraphics); - } - - let lastRendererHadRenderTarget = false; - for (let i = 0; i < this._renderers.length; i++) { - if (lastRendererHadRenderTarget && this._renderers[i].wantsToRenderToSceneRenderTarget) { - Framework.emitter.emit(CoreEvents.setRenderTarget, this._sceneRenderTarget); - Framework.emitter.emit(CoreEvents.clearGraphics); - - // 强制更新相机矩阵,以考虑到新的视口尺寸 - if (this._renderers[i].camera != null) - this._renderers[i].camera.forceMatrixUpdate(); - this.camera && this.camera.forceMatrixUpdate(); - } - - this._renderers[i].render(this); - lastRendererHadRenderTarget = this._renderers[i].renderTexture != null; - } - } - - /** - * 任何存在的PostProcessors都可以进行处理,然后我们对RenderTarget进行最后的渲染。 - * 几乎在所有情况下,finalRenderTarget都是空的。 - * 只有在场景转换的第一帧中,如果转换请求渲染,它才会有一个值。 - * @param finalRenderTarget - */ - public postRender(finalRenderTarget = null) { - let enabledCounter = 0; - - for (let i = 0; i < this._afterPostProcessorRenderers.length; i++) { - if (i == 0) { - // 我们需要在这里设置正确的RenderTarget - let currentRenderTarget = MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget; - Framework.emitter.emit(CoreEvents.setRenderTarget, currentRenderTarget); - } - - if (this._afterPostProcessorRenderers[i].camera != null) - this._afterPostProcessorRenderers[i].camera.forceMatrixUpdate(); - this._afterPostProcessorRenderers[i].render(this); - } - - // 如果我们有一个截图请求,在最终渲染到回缓冲区之前处理它 - if (this._screenshotRequestCallback != null) { - let currentRenderTarget = MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget; - this._screenshotRequestCallback(currentRenderTarget.value); - this._screenshotRequestCallback = null; - } - - // 将我们的最终结果渲染到后置缓冲区,或者让我们的委托来做 - if (this._finalRenderDelegate != null) { - let currentRenderTarget = MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget; - this._finalRenderDelegate.handleFinalRender(finalRenderTarget, currentRenderTarget, this._finalRenderDestinationRect); - } else { - let currentRenderTarget = MathHelper.isEven(enabledCounter) ? this._sceneRenderTarget : this._destinationRenderTarget; - Framework.emitter.emit(CoreEvents.setRenderTarget, finalRenderTarget); - Framework.emitter.emit(CoreEvents.clearGraphics); - - Framework.batcher.begin(this.currentRenderId, null); - Framework.batcher.draw(currentRenderTarget.value, - new Vector2(this._finalRenderDestinationRect.x, this._finalRenderDestinationRect.y), - 0xffffff, - 0, - Vector2.zero, - new Vector2(this._finalRenderDestinationRect.width, this._finalRenderDestinationRect.height)); - Framework.batcher.end(); - } - } - /** * 向组件列表添加并返回SceneComponent * @param component @@ -434,67 +154,6 @@ module es { component.onRemovedFromScene(); } - /** - * 添加一个渲染器到场景中 - * @param renderer - */ - public addRenderer(renderer: T): T { - if (renderer.wantsToRenderAfterPostProcessors) { - this._afterPostProcessorRenderers.push(renderer); - this._afterPostProcessorRenderers.sort((a, b) => { - return a.compare(b); - }); - } else { - this._renderers.push(renderer); - this._renderers.sort((a, b) => { - return a.compare(b); - }); - } - - renderer.onAddedToScene(this); - - if (this._didSceneBegin) - Framework.emitter.emit(CoreEvents.rendererSizeChanged, this._sceneRenderTarget.value); - - return renderer; - } - - /** - * 得到第一个T型的渲染器 - * @param type - */ - public getRenderer(type): T { - for (let i = 0; i < this._renderers.length; i++) { - if (this._renderers[i] instanceof type) - return this._renderers[i] as T; - } - - for (let i = 0; i < this._afterPostProcessorRenderers.length; i++) { - if (this._afterPostProcessorRenderers[i] instanceof type) - return this._afterPostProcessorRenderers[i] as T; - } - - return null; - } - - /** - * 从场景中移除渲染器 - * @param renderer - */ - public removeRenderer(renderer: IRenderer) { - let afterProcessLinqList = new linq.List(this._afterPostProcessorRenderers); - let rendererLinqList = new linq.List(this._renderers); - Insist.isTrue(rendererLinqList.contains(renderer) || - afterProcessLinqList.contains(renderer)); - - if (renderer.wantsToRenderAfterPostProcessors) - afterProcessLinqList.remove(renderer); - else - rendererLinqList.remove(renderer); - - renderer.unload(); - } - /** * 将实体添加到此场景,并返回它 * @param name diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index 58eb8e3b..16eafc8a 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -82,9 +82,6 @@ module es { for (let component of this._components) { if (!component) continue; - if (component instanceof RenderableComponent) - new linq.List(this._entity.scene.renderableComponents.buffer).remove(component); - // 处理IUpdatable if (isIUpdatable(component)) new linq.List(this._updatableComponents).remove(component); @@ -96,9 +93,6 @@ module es { public registerAllComponents() { for (let component of this._components) { - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.buffer.push(component); - if (isIUpdatable(component)) this._updatableComponents.push(component); @@ -124,9 +118,6 @@ module es { for (let i = 0, count = this._componentsToAdd.length; i < count; i++) { let component = this._componentsToAdd[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.buffer.push(component); - if (isIUpdatable(component)) this._updatableComponents.push(component); @@ -162,9 +153,6 @@ module es { } public handleRemove(component: Component) { - if (component instanceof RenderableComponent) - new linq.List(this._entity.scene.renderableComponents.buffer).remove(component); - if (isIUpdatable(component)) new linq.List(this._updatableComponents).remove(component); @@ -254,12 +242,5 @@ module es { for (let i = 0; i < this._components.length; i++) this._components[i].onDisabled(); } - - public debugRender(batcher: IBatcher) { - for (let i = 0; i < this._components.length; i++) { - if (this._components[i].enabled) - this._components[i].debugRender(batcher); - } - } } } diff --git a/source/src/ECS/Utils/RenderableComponentList.ts b/source/src/ECS/Utils/RenderableComponentList.ts deleted file mode 100644 index 3b9b8686..00000000 --- a/source/src/ECS/Utils/RenderableComponentList.ts +++ /dev/null @@ -1,94 +0,0 @@ -module es { - export class RenderableComponentList { - // IRenderable列表的全局updateOrder排序 - public static compareUpdatableOrder: IComparer = new RenderableComparer(); - - /** - * 添加到实体的组件列表 - */ - private _components: IRenderable[] = []; - /** - * 通过renderLayer跟踪组件,便于检索 - */ - private _componentsByRenderLayer: Map = new Map(); - - private _unsortedRenderLayers: number[] = []; - private _componentsNeedSort: boolean = true; - - public get count() { - return this._components.length; - } - - public get buffer(){ - return this._components; - } - - public get(index: number): IRenderable { - return this._components[index]; - } - - public add(component: IRenderable) { - this._components.push(component); - this.addToRenderLayerList(component, component.renderLayer); - } - - public remove(component: IRenderable) { - new linq.List(this._components).remove(component); - new linq.List(this._componentsByRenderLayer.get(component.renderLayer)).remove(component); - } - - public updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number) { - // 需要注意的是,在组件 "上线 "之前,renderLayer可能会发生变化 - if (this._componentsByRenderLayer.has(oldRenderLayer) && - new linq.List(this._componentsByRenderLayer.get(oldRenderLayer)).contains(component)) { - new linq.List(this._componentsByRenderLayer.get(oldRenderLayer)).remove(component); - this.addToRenderLayerList(component, newRenderLayer); - } - } - - /** - * 弄脏RenderLayers排序标志,导致所有组件的重新排序 - * @param renderLayer - */ - public setRenderLayerNeedsComponentSort(renderLayer: number) { - if (!new linq.List(this._unsortedRenderLayers).contains(renderLayer)) - this._unsortedRenderLayers.push(renderLayer); - this._componentsNeedSort = true; - } - - private addToRenderLayerList(component: IRenderable, renderLayer: number) { - let list = this.componentsWithRenderLayer(renderLayer); - Insist.isFalse(new linq.List(list).contains(component), "组件renderLayer列表已经包含这个组件"); - } - - /** - * 获取所有给定renderLayer的组件。组件列表是预先排序的。 - * @param renderLayer - */ - public componentsWithRenderLayer(renderLayer: number) { - if (!this._componentsByRenderLayer.has(renderLayer)) { - this._componentsByRenderLayer.set(renderLayer, []); - } - - return this._componentsByRenderLayer.get(renderLayer); - } - - public updateList() { - if (this._componentsNeedSort) { - this._components.sort(RenderableComponentList.compareUpdatableOrder.compare); - this._componentsNeedSort = false; - } - - if (this._unsortedRenderLayers.length > 0) { - for (let i = 0, count = this._unsortedRenderLayers.length; i < count; i++) { - let renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]); - if (renderLayerComponents) { - renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare); - } - } - - this._unsortedRenderLayers.length = 0; - } - } - } -} \ No newline at end of file diff --git a/source/src/Framework.ts b/source/src/Framework.ts deleted file mode 100644 index 54c62d78..00000000 --- a/source/src/Framework.ts +++ /dev/null @@ -1,14 +0,0 @@ -/// -module es { - /** - * 这里作为框架的核心件 - * 全局函数移动到这 - */ - export class Framework { - /** - * 核心发射器。只发出核心级别的事件 - */ - public static emitter: Emitter = new Emitter(); - public static batcher: IBatcher; - } -} \ No newline at end of file diff --git a/source/src/Graphics/IBatcher.ts b/source/src/Graphics/IBatcher.ts deleted file mode 100644 index 6e1be0eb..00000000 --- a/source/src/Graphics/IBatcher.ts +++ /dev/null @@ -1,27 +0,0 @@ -module es { - export interface IBatcher { - /** - * 创建投影矩阵时要使用的矩阵 - */ - transformMatrix: Matrix; - /** - * 如果为true,则将在绘制目标位置之前将其四舍五入 - */ - shouldRoundDestinations: boolean; - disposed(); - begin(id: Ref, effect, transformationMatrix?: Matrix, disableBatching?: boolean); - end(); - prepRenderState(); - /** - * 设置是否应忽略位置舍入。在为调试绘制基元时很有用 - */ - setIgnoreRoundingDestinations(shouldIgnore: boolean); - drawHollowRect(rect: Rectangle, color: number, thickness?: number); - drawHollowBounds(x: number, y: number, width: number, height: number, color: number, thickness: number); - drawLine(start: Vector2, end: Vector2, color: number, thickness); - draw(texture, position: Vector2, color?: number, rotation?: number, origin?: Vector2, scale?: Vector2, effects?); - drawPixel(position: Vector2, color: number, size?: number); - drawPolygon(position: Vector2, points: Vector2[], color: number, closePoly?: boolean, thickness?: number); - drawCircle(position: Vector2, radius: number, color: number, thickness?: number, resolution?: number); - } -} \ No newline at end of file diff --git a/source/src/Graphics/ICamera.ts b/source/src/Graphics/ICamera.ts deleted file mode 100644 index 98d60bac..00000000 --- a/source/src/Graphics/ICamera.ts +++ /dev/null @@ -1,29 +0,0 @@ -module es { - export interface ICamera extends Component { - position: Vector2; - rotation: number; - rawZoom: number; - zoom: number; - minimumZoom: number; - maximumZoom: number; - bounds: Rectangle; - transformMatrix: Matrix2D; - inverseTransformMatrix: Matrix2D; - projectionMatrix: Matrix; - viewprojectionMatrix: Matrix; - origin: Vector2; - setInset(left: number, right: number, top: number, bottom: number): ICamera; - setPosition(position: Vector2): ICamera; - setRotation(rotation: number): ICamera; - setZoom(zoom: number): ICamera; - setMinimumZoom(minZoom: number): ICamera; - setMaximumZoom(maxZoom: number): ICamera; - forceMatrixUpdate(); - onEntityTransformChanged(comp: transform.Component); - zoomIn(deltaZoom: number); - zoomOut(deltaZoom: number); - worldToScreenPoint(worldPosition: Vector2): Vector2; - screenToWorldPoint(screenPosition: Vector2): Vector2; - onSceneRenderTargetSizeChanged(newWidth: number, newHeight: number); - } -} \ No newline at end of file diff --git a/source/src/Graphics/IFinalRenderDelegate.ts b/source/src/Graphics/IFinalRenderDelegate.ts deleted file mode 100644 index 85708683..00000000 --- a/source/src/Graphics/IFinalRenderDelegate.ts +++ /dev/null @@ -1,32 +0,0 @@ -module es { - /** - * 可选接口,可以添加到任何对象中,用于特殊情况下需要覆盖最终渲染到屏幕。 - * 请注意,如果有IFinalRenderDelegate存在,Scene.screenshotRequestCallback将不会像预期的那样工作。 - */ - export interface IFinalRenderDelegate { - /** - * 在添加到场景中时调用 - * @param scene - */ - onAddedToScene(scene: Scene); - /** - * 当后置缓冲区大小改变时调用 - * @param newWidth - * @param newHeight - */ - onSceneBackBufferSizeChanged(newWidth: number, newHeight: number); - /** - * 这个被场景调用,这样就可以处理最终的渲染。渲染应该在finalRenderTarget中完成。 - * 在大多数情况下,finalRenderTarget将是空的,所以渲染将只是到回缓冲区。 - * finalRenderTarget只有在场景转换的第一帧时才会被设置,其中转换已经请求了上一个场景的渲染 - * @param finalRenderTarget - * @param source - * @param finalRenderDestinationRect - */ - handleFinalRender(finalRenderTarget, source, finalRenderDestinationRect: Rectangle); - /** - * 场景结束时调用。在这里释放任何资源 - */ - unload(); - } -} \ No newline at end of file diff --git a/source/src/Graphics/IMaterial.ts b/source/src/Graphics/IMaterial.ts deleted file mode 100644 index 448a3b34..00000000 --- a/source/src/Graphics/IMaterial.ts +++ /dev/null @@ -1,15 +0,0 @@ -module es { - /** - * 便利的子类,有一个单一的属性,可以投递Effect,使配置更简单 - */ - export interface IMaterial { - /** - * Batcher为当前RenderableComponent使用的效果 - */ - effect; - dispose(); - onPreRender(camera: ICamera); - compareTo(other: IMaterial): number; - clone(): IMaterial; - } -} \ No newline at end of file diff --git a/source/src/Graphics/IRenderer.ts b/source/src/Graphics/IRenderer.ts deleted file mode 100644 index bcdf9683..00000000 --- a/source/src/Graphics/IRenderer.ts +++ /dev/null @@ -1,57 +0,0 @@ -module es { - export interface IRenderer { - /** - * Batcher使用的材料。任何RenderableComponent都可以覆盖它 - */ - material: IMaterial; - /** - * 渲染器用于渲染的Camera(实际上是它的transformMatrix和culling的边界)。 - * 这是一个方便的字段,不是必需的。 - * 渲染器子类可以在调用beginRender时选择使用的摄像机 - */ - camera: ICamera; - /** - * 指定场景调用渲染器的顺序 - */ - renderOrder: number; - /** - * 如果renderTarget不是空的,这个渲染器将渲染到RenderTarget中,而不是渲染到屏幕上 - */ - renderTexture; - /** - * 标志,决定是否要调试渲染。 - * 渲染方法接收一个bool(debugRenderEnabled)让渲染器知道全局调试渲染是否开启/关闭。 - * 然后渲染器使用本地的bool来决定是否应该调试渲染 - */ - shouldDebugRender: boolean; - /** - * 如果为true,场景将使用场景RenderTarget调用SetRenderTarget。 - * 如果Renderer有一个renderTexture,默认的实现会返回true - */ - wantsToRenderToSceneRenderTarget: boolean; - /** - * 如果为true,场景将在所有后处理器完成后调用渲染方法。 - * 这必须在调用Scene.addRenderer生效之前设置为true,并且Renderer不应该有renderTexture。 - * 使用这种类型的渲染器的主要原因是为了让你可以在不进行后期处理的情况下,在Scene的其余部分上渲染你的UI。 - * ScreenSpaceRenderer是一个将此设置为真的Renderer例子 - */ - wantsToRenderAfterPostProcessors: boolean; - /** - * 当Renderer被添加到场景中时被调用 - * @param scene - */ - onAddedToScene(scene: Scene); - /** - * 当场景结束或该渲染器从场景中移除时,调用该函数,用于清理 - */ - unload(); - render(scene: Scene); - /** - * 当默认的场景RenderTarget被调整大小时,以及在场景已经开始的情况下添加一个Renderer时,会被调用。 - * @param newWidth - * @param newHeight - */ - onSceneBackBufferSizeChanged(newWidth: number, newHeight: number); - compare(other: IRenderer): number; - } -} \ No newline at end of file