From caa3ffc8f5aeb5766cd6fbf29d7b8c21577145c9 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Mon, 13 Mar 2023 23:32:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9Ees.TimeUtils=202.=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=B9=B6=E7=BB=99=E9=83=A8=E5=88=86=E7=B1=BB=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B3=A8=E9=87=8A=203.=E7=A7=BB=E9=99=A4fasterDiction?= =?UTF-8?q?ary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/bin/framework.d.ts | 521 +++-- source/bin/framework.js | 1709 ++++++++++------- source/bin/framework.min.js | 2 +- source/src/ECS/Component.ts | 33 +- source/src/ECS/Systems/EntitySystem.ts | 26 +- .../ECS/Systems/IntervalIteratingSystem.ts | 11 +- source/src/ECS/Utils/Bits.ts | 16 +- source/src/ECS/Utils/ComponentList.ts | 272 ++- source/src/ECS/Utils/EntityList.ts | 381 ++-- source/src/ECS/Utils/EntityProcessorList.ts | 164 +- source/src/ECS/Utils/HashHelper.ts | 101 +- source/src/ECS/Utils/Time.ts | 63 +- source/src/ECS/Utils/TimeUtils.ts | 420 ++-- .../src/Utils/Collections/FasterDictionary.ts | 317 --- 14 files changed, 2240 insertions(+), 1796 deletions(-) delete mode 100644 source/src/Utils/Collections/FasterDictionary.ts diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 5313ef0c..c1686b23 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -216,10 +216,35 @@ declare module es { onDisabled(): void; setEnabled(isEnabled: boolean): this; setUpdateOrder(updateOrder: number): this; + /** + * 添加组件 + * @param component 要添加的组件实例 + * @returns 返回添加的组件实例 + */ addComponent(component: T): T; + /** + * 获取组件 + * @param type 组件类型 + * @returns 返回获取到的组件实例 + */ getComponent(type: new (...args: any[]) => T): T; + /** + * 获取一组指定类型的组件 + * @param typeName 组件类型名 + * @param componentList 可选参数,存储组件实例的数组 + * @returns 返回指定类型的组件实例数组 + */ getComponents(typeName: any, componentList?: any[]): any[]; + /** + * 判断实体是否包含指定类型的组件 + * @param type 组件类型 + * @returns 如果实体包含指定类型的组件,返回 true,否则返回 false。 + */ hasComponent(type: new (...args: any[]) => Component): boolean; + /** + * 删除组件 + * @param component 可选参数,要删除的组件实例。如果未指定该参数,则删除当前实例上的组件。 + */ removeComponent(component?: Component): void; } } @@ -1610,7 +1635,7 @@ declare module es { } declare module es { /** - * 追踪实体的子集,但不实现任何排序或迭代。 + * 实体系统的基类,用于处理一组实体。 */ abstract class EntitySystem { private _entities; @@ -1634,7 +1659,7 @@ declare module es { readonly matcher: Matcher; /** * 设置更新时序 - * @param order + * @param order 更新时序 */ setUpdateOrder(order: number): void; initialize(): void; @@ -1804,11 +1829,7 @@ declare module es { } declare module es { /** - * 每x个ticks处理一个实体的子集 - * - * 典型的用法是每隔一定的时间间隔重新生成弹药或生命值 - * 而无需在每个游戏循环中都进行 - * 而是每100毫秒一次或每秒 + * 定时遍历处理实体的系统,用于按指定的时间间隔遍历并处理感兴趣的实体。 */ abstract class IntervalIteratingSystem extends IntervalSystem { constructor(matcher: Matcher, interval: number); @@ -1817,6 +1838,10 @@ declare module es { * @param entity */ abstract processEntity(entity: Entity): any; + /** + * 遍历处理实体。 + * @param entities 本系统感兴趣的实体列表 + */ protected process(entities: Entity[]): void; } } @@ -1861,83 +1886,142 @@ declare module es { } } declare module es { + /** + * 位操作类,用于操作一个位数组。 + */ class Bits { private _bit; + /** + * 设置指定位置的位值。 + * @param index 位置索引 + * @param value 位值(0 或 1) + */ set(index: number, value: number): void; + /** + * 获取指定位置的位值。 + * @param index 位置索引 + * @returns 位值(0 或 1) + */ get(index: number): number; } } declare module es { class ComponentList { /** - * 组件列表的全局updateOrder排序 + * 比较IUpdatable对象的更新顺序。 */ static compareUpdatableOrder: IUpdatableComparer; _entity: Entity; /** - * 添加到实体的组件列表 + * 实体的组件列表。 */ _components: Component[]; /** - * 所有需要更新的组件列表 + * 可更新的组件列表。 */ _updatableComponents: IUpdatable[]; /** - * 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 + * 等待添加到实体的组件列表。 */ _componentsToAdd: { [index: number]: Component; }; /** - * 标记要删除此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 + * 等待从实体中移除的组件列表。 */ _componentsToRemove: { [index: number]: Component; }; + /** + * 等待添加到实体的组件列表(作为数组)。 + */ _componentsToAddList: Component[]; + /** + * 等待从实体中移除的组件列表(作为数组)。 + */ _componentsToRemoveList: Component[]; + /** + * 临时的组件缓冲列表。 + */ _tempBufferList: Component[]; /** - * 用于确定是否需要对该框架中的组件进行排序的标志 + * 指示组件列表是否已排序的标志。 */ _isComponentListUnsorted: boolean; + /** + * 按组件类型组织的组件列表字典。 + */ private componentsByType; + /** + * 按组件类型组织的等待添加到实体的组件列表字典。 + */ private componentsToAddByType; constructor(entity: Entity); readonly count: number; readonly buffer: Component[]; markEntityListUnsorted(): void; + /** + * 将组件添加到实体的组件列表中,并添加到组件类型字典中。 + * @param component 要添加的组件。 + */ add(component: Component): void; + /** + * 从实体的组件列表中移除组件,并从相应的组件类型字典中移除组件。 + * @param component 要从实体中移除的组件。 + */ remove(component: Component): void; /** * 立即从组件列表中删除所有组件 */ removeAllComponents(): void; + /** + * 从实体的所有组件上注销并从相关数据结构中删除它们。 + */ deregisterAllComponents(): void; + /** + * 注册实体的所有组件,并将它们添加到相应的数据结构中。 + */ registerAllComponents(): void; + /** + * 从实体的位掩码中减去组件类型的索引。 + * @param component 要从实体中删除的组件。 + */ private decreaseBits; + /** + * 在实体的位掩码中添加组件类型的索引。 + * @param component 要添加到实体的组件。 + */ private addBits; /** - * 处理任何需要删除或添加的组件 + * 更新实体的组件列表和相关数据结构。 + * 如果有组件要添加或删除,它将相应地更新组件列表和其他数据结构。 */ updateLists(): void; handleRemove(component: Component): void; private removeComponentsByType; private addComponentsByType; + /** + * 从待添加组件列表中移除指定类型的组件。 + * @param component 要移除的组件 + */ private removeComponentsToAddByType; + /** + * 向待添加组件列表中添加指定类型的组件。 + * @param component 要添加的组件 + */ private addComponentsToAddByType; /** - * 获取类型T的第一个组件并返回它 - * 可以选择跳过检查未初始化的组件(尚未调用onAddedToEntity方法的组件) - * 如果没有找到组件,则返回null。 - * @param type - * @param onlyReturnInitializedComponents + * 获取指定类型的第一个组件实例。 + * @param type 组件类型 + * @param onlyReturnInitializedComponents 是否仅返回已初始化的组件 + * @returns 指定类型的第一个组件实例,如果不存在则返回 null */ - getComponent(type: any, onlyReturnInitializedComponents: boolean): T; + getComponent(type: new (...args: any[]) => T, onlyReturnInitializedComponents: boolean): T; /** - * 获取T类型的所有组件,但不使用列表分配 - * @param typeName - * @param components + * 获取指定类型的所有组件实例。 + * @param typeName 组件类型名称 + * @param components 存储组件实例的数组 + * @returns 存储了指定类型的所有组件实例的数组 */ getComponents(typeName: any, components?: any[]): any[]; update(): void; @@ -1998,33 +2082,45 @@ declare module es { } declare module es { class EntityList { + /** + * 场景引用 + */ scene: Scene; /** - * 场景中添加的实体列表 + * 实体列表 */ _entities: Entity[]; /** - * 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们 + * 待添加的实体字典 */ _entitiesToAdded: { [index: number]: Entity; }; /** - * 本帧被标记为删除的实体列表。用于对实体进行分组,以便我们可以同时处理它们 + * 待移除的实体字典 */ _entitiesToRemove: { [index: number]: Entity; }; + /** + * 待添加的实体列表 + */ _entitiesToAddedList: Entity[]; + /** + * 待移除的实体列表 + */ _entitiesToRemoveList: Entity[]; /** - * 标志,用于确定我们是否需要在这一帧中对实体进行排序 + * 实体列表是否已排序 */ _isEntityListUnsorted: boolean; /** - * 通过标签跟踪实体,便于检索 + * 实体字典,以实体标签为键 */ _entityDict: Map>; + /** + * 未排序的标签集合 + */ _unsortedTags: Set; constructor(scene: Scene); readonly count: number; @@ -2037,23 +2133,45 @@ declare module es { */ add(entity: Entity): void; /** - * 从列表中删除一个实体。所有的生命周期方法将在下一帧中被调用 - * @param entity + * 从场景中移除实体。 + * @param entity 要从场景中移除的实体。 */ remove(entity: Entity): void; /** - * 从实体列表中删除所有实体 + * 从场景中移除所有实体。 */ removeAllEntities(): void; /** - * 检查实体目前是否由这个EntityList管理 - * @param entity + * 检查实体是否已经被添加到场景中。 + * @param entity 要检查的实体 + * @returns 如果实体已经被添加到场景中,则返回true;否则返回false */ contains(entity: Entity): boolean; + /** + * 获取具有指定标签的实体列表。 + * 如果列表不存在,则创建一个新列表并返回。 + * @param tag 实体标签 + * @returns 具有指定标签的实体列表 + */ getTagList(tag: number): Set; + /** + * 添加实体到标签列表中。 + * @param entity 实体 + */ addToTagList(entity: Entity): void; + /** + * 从标签列表中移除实体。 + * @param entity 实体 + */ removeFromTagList(entity: Entity): void; + /** + * 更新场景中所有启用的实体的Update方法 + * 如果实体的UpdateInterval为1或Time.frameCount模除UpdateInterval为0,则每帧调用Update + */ update(): void; + /** + * 更新场景中实体的列表。 + */ updateLists(): void; /** * 返回第一个找到的名字为name的实体。如果没有找到则返回null @@ -2061,15 +2179,15 @@ declare module es { */ findEntity(name: string): Entity; /** - * - * @param id - * @returns + * 通过实体ID在场景中查找对应实体 + * @param id 实体ID + * @returns 返回找到的实体,如果没有找到则返回 null */ findEntityById(id: number): Entity; /** - * 返回带有标签的所有实体的列表。如果没有实体有标签,则返回一个空列表。 - * 返回的List可以通过ListPool.free放回池中 - * @param tag + * 获取标签对应的实体列表 + * @param tag 实体的标签 + * @returns 返回所有拥有该标签的实体列表 */ entitiesWithTag(tag: number): Entity[]; /** @@ -2079,20 +2197,21 @@ declare module es { */ entityWithTag(tag: number): Entity; /** - * 返回在场景中找到的第一个T类型的组件。 - * @param type + * 在场景中查找具有给定类型的组件。 + * @param type 要查找的组件类型。 + * @returns 如果找到,则返回该组件;否则返回null。 */ - findComponentOfType(type: any): T; + findComponentOfType(type: new (...args: any[]) => T): T | null; /** - * 返回在场景中找到的所有T类型的组件。 - * 返回的List可以通过ListPool.free放回池中。 - * @param type + * 在场景中查找具有给定类型的所有组件。 + * @param type 要查找的组件类型。 + * @returns 具有给定类型的所有组件的列表。 */ - findComponentsOfType(type: any): T[]; + findComponentsOfType(type: new (...args: any[]) => T): T[]; /** - * 返回场景中包含特定组件的实体列表 - * @param types - * @returns + * 返回拥有指定类型组件的所有实体 + * @param types 要查询的组件类型列表 + * @returns 返回拥有指定类型组件的所有实体 */ findEntitiesOfComponent(...types: any[]): Entity[]; } @@ -2101,53 +2220,100 @@ declare module es { class EntityProcessorList { private _processors; private _orderDirty; - /** 获取系统列表 */ + /** 获取处理器列表 */ readonly processors: EntitySystem[]; - /** 系统数量 */ + /** 获取处理器数量 */ readonly count: number; + /** + * 添加处理器 + * @param processor 要添加的处理器 + */ add(processor: EntitySystem): void; + /** + * 移除处理器 + * @param processor 要移除的处理器 + */ remove(processor: EntitySystem): void; + /** + * 在实体上添加组件时被调用 + * @param entity 添加组件的实体 + */ onComponentAdded(entity: Entity): void; + /** + * 在实体上移除组件时被调用 + * @param entity 移除组件的实体 + */ onComponentRemoved(entity: Entity): void; + /** + * 在场景中添加实体时被调用 + * @param entity 添加的实体 + */ onEntityAdded(entity: Entity): void; + /** + * 在场景中移除实体时被调用 + * @param entity 移除的实体 + */ onEntityRemoved(entity: Entity): void; + /** 在处理器列表上开始循环 */ begin(): void; + /** 更新处理器列表 */ update(): void; - lateUpdate(): void; + /** 在处理器列表上完成循环 */ end(): void; + /** 设置处理器排序标志 */ setDirty(): void; + /** 清除处理器排序标志 */ clearDirty(): void; + /** + * 获取指定类型的处理器 + * @param type 指定类型的构造函数 + * @returns 指定类型的处理器 + */ getProcessor(type: new (...args: any[]) => T): T; + /** + * 通知处理器实体已更改 + * @param entity 发生更改的实体 + */ protected notifyEntityChanged(entity: Entity): void; + /** + * 从处理器列表中移除实体 + * @param entity 要移除的实体 + */ protected removeFromProcessors(entity: Entity): void; + /** 在处理器列表上进行后期更新 */ + lateUpdate(): void; } } declare module es { class HashHelpers { static readonly hashCollisionThreshold: number; static readonly hashPrime: number; - /** - * 用来作为哈希表大小的质数表。 - * 一个典型的调整大小的算法会在这个数组中选取比之前容量大两倍的最小质数。 - * 假设我们的Hashtable当前的容量为x,并且添加了足够多的元素,因此需要进行大小调整。 - * 调整大小首先计算2x,然后在表中找到第一个大于2x的质数,即如果质数的顺序是p_1,p_2,...,p_i,...,则找到p_n,使p_n-1 < 2x < p_n。 - * 双倍对于保持哈希特操作的渐近复杂度是很重要的,比如添加。 - * 拥有一个质数可以保证双倍哈希不会导致无限循环。 IE,你的哈希函数将是h1(key)+i*h2(key),0 <= i < size.h2和size必须是相对质数。 - */ static readonly primes: number[]; - /** - * 这是比Array.MaxArrayLength小的最大质数 - */ static readonly maxPrimeArrayLength: number; + /** + * 判断一个数是否为质数 + * @param candidate 要判断的数 + * @returns 是否为质数 + */ static isPrime(candidate: number): boolean; + /** + * 获取大于等于指定值的最小质数 + * @param min 指定值 + * @returns 大于等于指定值的最小质数 + */ static getPrime(min: number): number; /** - * - * @param oldSize - * @returns 返回要增长的哈希特表的大小 + * 扩展哈希表容量 + * @param oldSize 原哈希表容量 + * @returns 扩展后的哈希表容量 */ static expandPrime(oldSize: number): number; - static getHashCode(str: any): number; + /** + * 计算字符串的哈希值 + * @param str 要计算哈希值的字符串 + * @returns 哈希值 + */ + static getHashCode(str: string): number; } } declare module es { @@ -2281,104 +2447,118 @@ declare module es { } } declare module es { - /** 提供帧定时信息 */ + /** + * 时间管理器,用于管理游戏中的时间相关属性 + */ class Time { - /** 游戏运行的总时间 */ + /** 游戏运行的总时间,单位为秒 */ static totalTime: number; - /** deltaTime的未缩放版本。不受时间尺度的影响 */ + /** deltaTime 的未缩放版本,不受时间尺度的影响 */ static unscaledDeltaTime: number; /** 前一帧到当前帧的时间增量,按时间刻度进行缩放 */ static deltaTime: number; - /** 时间刻度缩放 */ + /** 时间刻度缩放,可以加快或减慢游戏时间 */ static timeScale: number; - /** DeltaTime可以为的最大值 */ + /** DeltaTime 可以为的最大值,避免游戏出现卡顿情况 */ static maxDeltaTime: number; /** 已传递的帧总数 */ static frameCount: number; - /** 自场景加载以来的总时间 */ + /** 自场景加载以来的总时间,单位为秒 */ static timeSinceSceneLoad: number; + /** 上一次记录的时间,用于计算两次调用 update 之间的时间差 */ private static _lastTime; + /** + * 更新时间管理器 + * @param currentTime 当前时间 + * @param useEngineTime 是否使用引擎时间 + */ static update(currentTime: number, useEngineTime: boolean): void; static sceneChanged(): void; /** - * 允许在间隔检查。只应该使用高于delta的间隔值,否则它将始终返回true。 - * @param interval + * 检查指定时间间隔是否已过去 + * @param interval 指定时间间隔 + * @returns 是否已过去指定时间间隔 */ static checkEvery(interval: number): boolean; } } -declare class TimeUtils { - /** - * 计算月份ID - * @param d 指定计算日期 - * @returns 月ID - */ - static monthId(d?: Date): number; - /** - * 计算日期ID - * @param d 指定计算日期 - * @returns 日期ID - */ - static dateId(t?: Date): number; - /** - * 计算周ID - * @param d 指定计算日期 - * @returns 周ID - */ - static weekId(d?: Date, first?: boolean): number; - /** - * 计算俩日期时间差,如果a比b小,返回负数 - */ - static diffDay(a: Date, b: Date, fixOne?: boolean): number; - /** - * 获取本周一 凌晨时间 - */ - static getFirstDayOfWeek(d?: Date): Date; - /** - * 获取当日凌晨时间 - */ - static getFirstOfDay(d?: Date): Date; - /** - * 获取次日凌晨时间 - */ - static getNextFirstOfDay(d?: Date): Date; - /** - * @returns 2018-12-12 - */ - static formatDate(date: Date): string; - /** - * @returns 2018-12-12 12:12:12 - */ - static formatDateTime(date: Date): string; - /** - * @returns s 2018-12-12 或者 2018-12-12 12:12:12 - */ - static parseDate(s: string): Date; - /** - * 秒数转换为时间形式。 - * @param time 秒数 - * @param partition 分隔符 - * @param showHour 是否显示小时 - * @return 返回一个以分隔符分割的时, 分, 秒 - * - * 比如: time = 4351; secondToTime(time)返回字符串01:12:31; - */ - static secondToTime(time?: number, partition?: string, showHour?: boolean): string; - /** - * 时间形式转换为毫秒数。 - * @param time 以指定分隔符分割的时间字符串 - * @param partition 分隔符 - * @return 毫秒数显示的字符串 - * @throws Error Exception - * - * 用法1 trace(MillisecondTransform.timeToMillisecond("00:60:00")) - * 输出 3600000 - * - * - * 用法2 trace(MillisecondTransform.timeToMillisecond("00.60.00",".")) - * 输出 3600000 - */ - static timeToMillisecond(time: string, partition?: string): string; +declare module es { + class TimeUtils { + /** + * 获取日期对应的年份和月份的数字组合 + * @param d 要获取月份的日期对象,不传则默认为当前时间 + * @returns 返回数字组合的年份和月份 + */ + static monthId(d?: Date): number; + /** + * 获取日期的数字组合 + * @param t - 可选参数,传入时间,若不传入则使用当前时间 + * @returns 数字组合 + */ + static dateId(t?: Date): number; + /** + * 获取当前日期所在周的数字组合 + * @param d - 可选参数,传入日期,若不传入则使用当前日期 + * @param first - 是否将当前周视为本年度的第1周,默认为true + * @returns 数字组合 + */ + static weekId(d?: Date, first?: boolean): number; + /** + * 计算两个日期之间相差的天数 + * @param a 第一个日期 + * @param b 第二个日期 + * @param fixOne 是否将相差天数四舍五入到整数 + * @returns 两个日期之间相差的天数 + */ + static diffDay(a: Date, b: Date, fixOne?: boolean): number; + /** + * 获取指定日期所在周的第一天 + * @param d 指定日期,默认值为今天 + * @returns 指定日期所在周的第一天 + */ + static getFirstDayOfWeek(d?: Date): Date; + /** + * 获取当日凌晨时间 + */ + static getFirstOfDay(d?: Date): Date; + /** + * 获取次日凌晨时间 + */ + static getNextFirstOfDay(d?: Date): Date; + /** + * 格式化日期为 "YYYY-MM-DD" 的字符串形式 + * @param date 要格式化的日期 + * @returns 格式化后的日期字符串 + */ + static formatDate(date: Date): string; + /** + * 将日期对象格式化为 "YYYY-MM-DD HH:mm:ss" 的字符串 + * @param date 日期对象 + * @returns 格式化后的字符串 + */ + static formatDateTime(date: Date): string; + /** + * 将字符串解析为Date对象 + * @param s 要解析的日期字符串,例如:2022-01-01 + * @returns 返回解析后的Date对象,如果解析失败,则返回当前时间的Date对象 + */ + static parseDate(s: string): Date; + /** + * 将秒数转换为时分秒的格式 + * @param time 秒数 + * @param partition 分隔符 + * @param showHour 是否显示小时位 + * @returns 转换后的时间字符串 + */ + static secondToTime(time?: number, partition?: string, showHour?: boolean): string; + /** + * 将时间字符串转换为毫秒数 + * @param time 时间字符串,如 "01:30:15" 表示 1小时30分钟15秒 + * @param partition 分隔符,默认为 ":" + * @returns 转换后的毫秒数字符串 + */ + static timeToMillisecond(time: string, partition?: string): string; + } } declare module es { /** @@ -5321,53 +5501,6 @@ declare module es { addAll(items: ImmutableBag): void; } } -declare module es { - /** - * 创建这个字典的原因只有一个: - * 我需要一个能让我直接以数组的形式对值进行迭代的字典,而不需要生成一个数组或使用迭代器。 - * 对于这个目标是比标准字典快N倍。 - * Faster dictionary在大部分操作上也比标准字典快,但差别可以忽略不计。 - * 唯一较慢的操作是在添加时调整内存大小,因为与标准数组相比,这个实现需要使用两个单独的数组。 - */ - class FasterDictionary { - _values: TValue[]; - _valuesInfo: FastNode[]; - _buckets: number[]; - _freeValueCellIndex: number; - _collisions: number; - constructor(size?: number); - getValuesArray(count: { - value: number; - }): TValue[]; - readonly valuesArray: TValue[]; - readonly count: number; - add(key: TKey, value: TValue): void; - addValue(key: TKey, value: TValue, indexSet: { - value: number; - }): boolean; - remove(key: TKey): boolean; - trim(): void; - clear(): void; - fastClear(): void; - containsKey(key: TKey): boolean; - tryGetValue(key: TKey): TValue; - tryFindIndex(key: TKey, findIndex: { - value: number; - }): boolean; - getDirectValue(index: number): TValue; - getIndex(key: TKey): number; - static updateLinkedList(index: number, valuesInfo: FastNode[]): void; - static hash(key: any): number; - static reduce(x: number, n: number): number; - } - class FastNode { - readonly key: any; - readonly hashcode: number; - previous: number; - next: number; - constructor(key: any, hash: number, previousNode?: number); - } -} declare module es { interface ImmutableBag { get(index: number): E; diff --git a/source/bin/framework.js b/source/bin/framework.js index 104a6e1e..36381235 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -567,18 +567,43 @@ var es; } return this; }; + /** + * 添加组件 + * @param component 要添加的组件实例 + * @returns 返回添加的组件实例 + */ Component.prototype.addComponent = function (component) { return this.entity.addComponent(component); }; + /** + * 获取组件 + * @param type 组件类型 + * @returns 返回获取到的组件实例 + */ Component.prototype.getComponent = function (type) { return this.entity.getComponent(type); }; + /** + * 获取一组指定类型的组件 + * @param typeName 组件类型名 + * @param componentList 可选参数,存储组件实例的数组 + * @returns 返回指定类型的组件实例数组 + */ Component.prototype.getComponents = function (typeName, componentList) { return this.entity.getComponents(typeName, componentList); }; + /** + * 判断实体是否包含指定类型的组件 + * @param type 组件类型 + * @returns 如果实体包含指定类型的组件,返回 true,否则返回 false。 + */ Component.prototype.hasComponent = function (type) { return this.entity.hasComponent(type); }; + /** + * 删除组件 + * @param component 可选参数,要删除的组件实例。如果未指定该参数,则删除当前实例上的组件。 + */ Component.prototype.removeComponent = function (component) { if (component) { this.entity.removeComponent(component); @@ -3887,7 +3912,7 @@ var es; /// (function (es) { /** - * 追踪实体的子集,但不实现任何排序或迭代。 + * 实体系统的基类,用于处理一组实体。 */ var EntitySystem = /** @class */ (function () { function EntitySystem(matcher) { @@ -3943,7 +3968,7 @@ var es; }); /** * 设置更新时序 - * @param order + * @param order 更新时序 */ EntitySystem.prototype.setUpdateOrder = function (order) { this._updateOrder = order; @@ -3964,12 +3989,14 @@ var es; this._entities.push(entity); this.onAdded(entity); }; - EntitySystem.prototype.onAdded = function (entity) { }; + EntitySystem.prototype.onAdded = function (entity) { + }; EntitySystem.prototype.remove = function (entity) { new es.List(this._entities).remove(entity); this.onRemoved(entity); }; - EntitySystem.prototype.onRemoved = function (entity) { }; + EntitySystem.prototype.onRemoved = function (entity) { + }; EntitySystem.prototype.update = function () { if (this.checkProcessing()) { this.begin(); @@ -3991,8 +4018,10 @@ var es; return; this._startTime = Date.now(); }; - EntitySystem.prototype.process = function (entities) { }; - EntitySystem.prototype.lateProcess = function (entities) { }; + EntitySystem.prototype.process = function (entities) { + }; + EntitySystem.prototype.lateProcess = function (entities) { + }; /** * 系统处理完毕后调用 */ @@ -4242,17 +4271,17 @@ var es; /// (function (es) { /** - * 每x个ticks处理一个实体的子集 - * - * 典型的用法是每隔一定的时间间隔重新生成弹药或生命值 - * 而无需在每个游戏循环中都进行 - * 而是每100毫秒一次或每秒 + * 定时遍历处理实体的系统,用于按指定的时间间隔遍历并处理感兴趣的实体。 */ var IntervalIteratingSystem = /** @class */ (function (_super) { __extends(IntervalIteratingSystem, _super); function IntervalIteratingSystem(matcher, interval) { return _super.call(this, matcher, interval) || this; } + /** + * 遍历处理实体。 + * @param entities 本系统感兴趣的实体列表 + */ IntervalIteratingSystem.prototype.process = function (entities) { var _this = this; entities.forEach(function (entity) { return _this.processEntity(entity); }); @@ -4323,13 +4352,26 @@ var es; })(es || (es = {})); var es; (function (es) { + /** + * 位操作类,用于操作一个位数组。 + */ var Bits = /** @class */ (function () { function Bits() { this._bit = {}; } + /** + * 设置指定位置的位值。 + * @param index 位置索引 + * @param value 位值(0 或 1) + */ Bits.prototype.set = function (index, value) { this._bit[index] = value; }; + /** + * 获取指定位置的位值。 + * @param index 位置索引 + * @returns 位值(0 或 1) + */ Bits.prototype.get = function (index) { var v = this._bit[index]; return v == null ? 0 : v; @@ -4345,25 +4387,40 @@ var es; var ComponentList = /** @class */ (function () { function ComponentList(entity) { /** - * 添加到实体的组件列表 + * 实体的组件列表。 */ this._components = []; /** - * 所有需要更新的组件列表 + * 可更新的组件列表。 */ this._updatableComponents = []; /** - * 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 + * 等待添加到实体的组件列表。 */ this._componentsToAdd = {}; /** - * 标记要删除此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 + * 等待从实体中移除的组件列表。 */ this._componentsToRemove = {}; + /** + * 等待添加到实体的组件列表(作为数组)。 + */ this._componentsToAddList = []; + /** + * 等待从实体中移除的组件列表(作为数组)。 + */ this._componentsToRemoveList = []; + /** + * 临时的组件缓冲列表。 + */ this._tempBufferList = []; + /** + * 按组件类型组织的组件列表字典。 + */ this.componentsByType = new Map(); + /** + * 按组件类型组织的等待添加到实体的组件列表字典。 + */ this.componentsToAddByType = new Map(); this._entity = entity; } @@ -4384,20 +4441,32 @@ var es; ComponentList.prototype.markEntityListUnsorted = function () { this._isComponentListUnsorted = true; }; + /** + * 将组件添加到实体的组件列表中,并添加到组件类型字典中。 + * @param component 要添加的组件。 + */ ComponentList.prototype.add = function (component) { + // 将组件添加到_componentsToAdd和_componentsToAddList中,并添加到相应的组件类型字典中 this._componentsToAdd[component.id] = component; this._componentsToAddList.push(component); this.addComponentsToAddByType(component); }; + /** + * 从实体的组件列表中移除组件,并从相应的组件类型字典中移除组件。 + * @param component 要从实体中移除的组件。 + */ ComponentList.prototype.remove = function (component) { + // 如果组件在_componentsToAdd中,则将其从_componentsToAddList中移除,并从相应的组件类型字典中移除组件 if (this._componentsToAdd[component.id]) { - var index = this._componentsToAddList.findIndex(function (c) { return c.id == component.id; }); - if (index != -1) + var index = this._componentsToAddList.findIndex(function (c) { return c.id === component.id; }); + if (index !== -1) { this._componentsToAddList.splice(index, 1); + } delete this._componentsToAdd[component.id]; this.removeComponentsToAddByType(component); return; } + // 如果组件不在_componentsToAdd中,则将其添加到_componentsToRemove和_componentsToRemoveList中 this._componentsToRemove[component.id] = component; this._componentsToRemoveList.push(component); }; @@ -4419,163 +4488,280 @@ var es; this._componentsToAddList.length = 0; this._componentsToRemoveList.length = 0; }; + /** + * 从实体的所有组件上注销并从相关数据结构中删除它们。 + */ ComponentList.prototype.deregisterAllComponents = function () { + var e_2, _a; if (this._components.length > 0) { - for (var i = 0, s = this._components.length; i < s; ++i) { - var component = this._components[i]; - if (!component) - continue; - // 处理IUpdatable - if (es.isIUpdatable(component)) - new es.List(this._updatableComponents).remove(component); - this.decreaseBits(component); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + try { + for (var _b = __values(this._components), _c = _b.next(); !_c.done; _c = _b.next()) { + var component = _c.value; + // 处理IUpdatable + if (es.isIUpdatable(component)) { + // 创建一个新的List实例,从_updatableComponents中移除组件,以避免并发修改异常 + new es.List(this._updatableComponents).remove(component); + } + // 从位掩码中减去组件类型的索引,通知实体处理器一个组件已被移除 + this.decreaseBits(component); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_2) throw e_2.error; } } } }; + /** + * 注册实体的所有组件,并将它们添加到相应的数据结构中。 + */ ComponentList.prototype.registerAllComponents = function () { + var e_3, _a; if (this._components.length > 0) { - for (var i = 0, s = this._components.length; i < s; ++i) { - var component = this._components[i]; - if (es.isIUpdatable(component)) - this._updatableComponents.push(component); - this.addBits(component); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); + try { + for (var _b = __values(this._components), _c = _b.next(); !_c.done; _c = _b.next()) { + var component = _c.value; + if (es.isIUpdatable(component)) { + // 如果组件是可更新的,则将其添加到_updatableComponents中 + this._updatableComponents.push(component); + } + // 将组件类型的索引添加到实体的位掩码中,通知实体处理器一个组件已被添加 + this.addBits(component); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + } + } + catch (e_3_1) { e_3 = { error: e_3_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_3) throw e_3.error; } } } }; + /** + * 从实体的位掩码中减去组件类型的索引。 + * @param component 要从实体中删除的组件。 + */ ComponentList.prototype.decreaseBits = function (component) { var bits = this._entity.componentBits; + // 获取组件类型的索引,将其对应位掩码减1 var typeIndex = es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)); bits.set(typeIndex, bits.get(typeIndex) - 1); }; + /** + * 在实体的位掩码中添加组件类型的索引。 + * @param component 要添加到实体的组件。 + */ ComponentList.prototype.addBits = function (component) { var bits = this._entity.componentBits; + // 获取组件类型的索引,将其对应位掩码加1 var typeIndex = es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)); bits.set(typeIndex, bits.get(typeIndex) + 1); }; /** - * 处理任何需要删除或添加的组件 + * 更新实体的组件列表和相关数据结构。 + * 如果有组件要添加或删除,它将相应地更新组件列表和其他数据结构。 */ ComponentList.prototype.updateLists = function () { + var e_4, _a, e_5, _b, e_6, _c; + // 处理要删除的组件 if (this._componentsToRemoveList.length > 0) { - var _loop_1 = function (i, l) { - var component = this_1._componentsToRemoveList[i]; + var _loop_1 = function (component) { + // 从实体中删除组件,从组件列表和相关数据结构中删除组件 this_1.handleRemove(component); - var index = this_1._components.findIndex(function (c) { return c.id == component.id; }); - if (index != -1) + // 从_components数组中删除组件 + var index = this_1._components.findIndex(function (c) { return c.id === component.id; }); + if (index !== -1) { this_1._components.splice(index, 1); + } + // 从组件类型字典中删除组件 this_1.removeComponentsByType(component); }; var this_1 = this; - for (var i = 0, l = this._componentsToRemoveList.length; i < l; ++i) { - _loop_1(i, l); + try { + for (var _d = __values(this._componentsToRemoveList), _e = _d.next(); !_e.done; _e = _d.next()) { + var component = _e.value; + _loop_1(component); + } } + catch (e_4_1) { e_4 = { error: e_4_1 }; } + finally { + try { + if (_e && !_e.done && (_a = _d.return)) _a.call(_d); + } + finally { if (e_4) throw e_4.error; } + } + // 清空_componentsToRemove和_componentsToRemoveList this._componentsToRemove = {}; this._componentsToRemoveList.length = 0; } + // 处理要添加的组件 if (this._componentsToAddList.length > 0) { - for (var i = 0, l = this._componentsToAddList.length; i < l; ++i) { - var component = this._componentsToAddList[i]; - if (es.isIUpdatable(component)) - this._updatableComponents.push(component); - this.addBits(component); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - this.addComponentsByType(component); - this._components.push(component); - this._tempBufferList.push(component); + try { + for (var _f = __values(this._componentsToAddList), _g = _f.next(); !_g.done; _g = _f.next()) { + var component = _g.value; + // 如果组件可以更新,则添加到可更新组件列表中 + if (es.isIUpdatable(component)) { + this._updatableComponents.push(component); + } + // 更新实体的组件位掩码,通知实体处理器一个组件已经添加 + this.addBits(component); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + // 将组件添加到相应类型的fastList中,将组件添加到_components数组中 + this.addComponentsByType(component); + this._components.push(component); + // 将组件添加到_tempBufferList中,稍后调用onAddedToEntity和onEnabled + this._tempBufferList.push(component); + } } - // 在调用onAddedToEntity之前清除,以防添加更多组件 + catch (e_5_1) { e_5 = { error: e_5_1 }; } + finally { + try { + if (_g && !_g.done && (_b = _f.return)) _b.call(_f); + } + finally { if (e_5) throw e_5.error; } + } + // 清空_componentsToAdd、_componentsToAddList和componentsToAddByType,设置_isComponentListUnsorted标志 this._componentsToAdd = {}; this._componentsToAddList.length = 0; this.componentsToAddByType.clear(); this._isComponentListUnsorted = true; } + // 调用新添加组件的onAddedToEntity和onEnabled方法 if (this._tempBufferList.length > 0) { - // 现在所有的组件都添加到了场景中,我们再次循环并调用onAddedToEntity/onEnabled - for (var i = 0, l = this._tempBufferList.length; i < l; ++i) { - var component = this._tempBufferList[i]; - component.onAddedToEntity(); - // enabled检查实体和组件 - if (component.enabled) { - component.onEnabled(); + try { + for (var _h = __values(this._tempBufferList), _j = _h.next(); !_j.done; _j = _h.next()) { + var component = _j.value; + component.onAddedToEntity(); + // 如果组件已启用,则调用onEnabled方法 + if (component.enabled) { + component.onEnabled(); + } } } + catch (e_6_1) { e_6 = { error: e_6_1 }; } + finally { + try { + if (_j && !_j.done && (_c = _h.return)) _c.call(_h); + } + finally { if (e_6) throw e_6.error; } + } + // 清空_tempBufferList this._tempBufferList.length = 0; } }; ComponentList.prototype.handleRemove = function (component) { + // 如果组件可以更新,从可更新组件列表中删除该组件 if (es.isIUpdatable(component) && this._updatableComponents.length > 0) { - var index = this._updatableComponents.findIndex(function (c) { return c.id == component.id; }); - if (index != -1) + var index = this._updatableComponents.findIndex(function (c) { return c.id === component.id; }); + if (index !== -1) { this._updatableComponents.splice(index, 1); + } } + // 更新实体的组件位掩码 this.decreaseBits(component); + // 通知实体处理器一个组件已被删除 this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + // 调用组件的onRemovedFromEntity方法,将其entity属性设置为null component.onRemovedFromEntity(); component.entity = null; }; ComponentList.prototype.removeComponentsByType = function (component) { + // 获取存储指定类型组件的fastList数组 var fastList = this.componentsByType.get(es.TypeUtils.getType(component)); - var fastIndex = fastList.findIndex(function (c) { return c.id == component.id; }); - if (fastIndex != -1) { - fastList.splice(fastIndex, 1); + // 在fastList中查找要删除的组件 + var index = fastList.findIndex(function (c) { return c.id === component.id; }); + if (index !== -1) { + // 找到组件后,使用splice方法将其从fastList中删除 + fastList.splice(index, 1); } }; ComponentList.prototype.addComponentsByType = function (component) { + // 获取存储指定类型组件的fastList数组 var fastList = this.componentsByType.get(es.TypeUtils.getType(component)); - if (!fastList) + // 如果fastList不存在,则创建一个空数组 + if (!fastList) { fastList = []; + } + // 在fastList中添加组件 fastList.push(component); + // 更新componentsByType字典,以便它包含fastList数组 this.componentsByType.set(es.TypeUtils.getType(component), fastList); }; + /** + * 从待添加组件列表中移除指定类型的组件。 + * @param component 要移除的组件 + */ ComponentList.prototype.removeComponentsToAddByType = function (component) { + // 获取待添加组件列表中指定类型的组件列表 var fastList = this.componentsToAddByType.get(es.TypeUtils.getType(component)); + // 在该列表中查找指定组件 var fastIndex = fastList.findIndex(function (c) { return c.id == component.id; }); + // 如果找到了指定组件,则从列表中移除它 if (fastIndex != -1) { fastList.splice(fastIndex, 1); } }; + /** + * 向待添加组件列表中添加指定类型的组件。 + * @param component 要添加的组件 + */ ComponentList.prototype.addComponentsToAddByType = function (component) { + // 获取待添加组件列表中指定类型的组件列表 var fastList = this.componentsToAddByType.get(es.TypeUtils.getType(component)); + // 如果指定类型的组件列表不存在,则创建一个新的列表 if (!fastList) fastList = []; + // 向指定类型的组件列表中添加组件 fastList.push(component); + // 更新待添加组件列表中指定类型的组件列表 this.componentsToAddByType.set(es.TypeUtils.getType(component), fastList); }; /** - * 获取类型T的第一个组件并返回它 - * 可以选择跳过检查未初始化的组件(尚未调用onAddedToEntity方法的组件) - * 如果没有找到组件,则返回null。 - * @param type - * @param onlyReturnInitializedComponents + * 获取指定类型的第一个组件实例。 + * @param type 组件类型 + * @param onlyReturnInitializedComponents 是否仅返回已初始化的组件 + * @returns 指定类型的第一个组件实例,如果不存在则返回 null */ ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) { + // 获取指定类型的组件列表 var fastList = this.componentsByType.get(type); + // 如果指定类型的组件列表存在并且不为空,则返回第一个组件实例 if (fastList && fastList.length > 0) return fastList[0]; - // 我们可以选择检查挂起的组件,以防addComponent和getComponent在同一个框架中被调用 + // 如果不仅返回已初始化的组件,则检查待添加组件列表中是否存在指定类型的组件 if (!onlyReturnInitializedComponents) { var fastToAddList = this.componentsToAddByType.get(type); if (fastToAddList && fastToAddList.length > 0) return fastToAddList[0]; } + // 如果指定类型的组件列表为空且待添加组件列表中也不存在该类型的组件,则返回 null return null; }; /** - * 获取T类型的所有组件,但不使用列表分配 - * @param typeName - * @param components + * 获取指定类型的所有组件实例。 + * @param typeName 组件类型名称 + * @param components 存储组件实例的数组 + * @returns 存储了指定类型的所有组件实例的数组 */ ComponentList.prototype.getComponents = function (typeName, components) { + // 如果没有传入组件实例数组,则创建一个新数组 if (!components) components = []; + // 获取指定类型的组件列表,并将其添加到组件实例数组中 var fastList = this.componentsByType.get(typeName); if (fastList) components = components.concat(fastList); + // 获取待添加组件列表中的指定类型的组件列表,并将其添加到组件实例数组中 var fastToAddList = this.componentsToAddByType.get(typeName); if (fastToAddList) components = components.concat(fastToAddList); + // 返回存储了指定类型的所有组件实例的数组 return components; }; ComponentList.prototype.update = function () { @@ -4617,7 +4803,7 @@ var es; } }; /** - * 组件列表的全局updateOrder排序 + * 比较IUpdatable对象的更新顺序。 */ ComponentList.compareUpdatableOrder = new es.IUpdatableComparer(); return ComponentList; @@ -4721,23 +4907,32 @@ var es; var EntityList = /** @class */ (function () { function EntityList(scene) { /** - * 场景中添加的实体列表 + * 实体列表 */ this._entities = []; /** - * 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们 + * 待添加的实体字典 */ this._entitiesToAdded = {}; /** - * 本帧被标记为删除的实体列表。用于对实体进行分组,以便我们可以同时处理它们 + * 待移除的实体字典 */ this._entitiesToRemove = {}; + /** + * 待添加的实体列表 + */ this._entitiesToAddedList = []; + /** + * 待移除的实体列表 + */ this._entitiesToRemoveList = []; /** - * 通过标签跟踪实体,便于检索 + * 实体字典,以实体标签为键 */ this._entityDict = new Map(); + /** + * 未排序的标签集合 + */ this._unsortedTags = new Set(); this.scene = scene; } @@ -4770,104 +4965,204 @@ var es; this._entitiesToAddedList.push(entity); }; /** - * 从列表中删除一个实体。所有的生命周期方法将在下一帧中被调用 - * @param entity + * 从场景中移除实体。 + * @param entity 要从场景中移除的实体。 */ EntityList.prototype.remove = function (entity) { - // 防止在同一帧中添加或删除实体 + // 如果实体在添加列表中,则将其从添加列表中移除 if (this._entitiesToAdded[entity.id]) { - var index = this._entitiesToAddedList.findIndex(function (e) { return e.id == entity.id; }); - if (index != -1) + var index = this._entitiesToAddedList.findIndex(function (e) { return e.id === entity.id; }); + if (index !== -1) { this._entitiesToAddedList.splice(index, 1); + } delete this._entitiesToAdded[entity.id]; return; } + // 如果实体不在添加列表中,则将其添加到移除列表中并将其添加到移除字典中 this._entitiesToRemoveList.push(entity); - if (!this._entitiesToRemove[entity.id]) + if (!this._entitiesToRemove[entity.id]) { this._entitiesToRemove[entity.id] = entity; + } }; /** - * 从实体列表中删除所有实体 + * 从场景中移除所有实体。 */ EntityList.prototype.removeAllEntities = function () { + var e_7, _a; + // 清除字典和列表,以及是否已排序的标志 this._unsortedTags.clear(); this._entitiesToAdded = {}; this._entitiesToAddedList.length = 0; this._isEntityListUnsorted = false; - // 为什么我们要在这里更新列表?主要是为了处理在场景切换前被分离的实体。 - // 它们仍然会在_entitiesToRemove列表中,这将由updateLists处理。 + // 调用updateLists方法,以处理要移除的实体 this.updateLists(); - for (var i = 0; i < this._entities.length; i++) { - this._entities[i]._isDestroyed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; + try { + // 标记并移除所有实体 + for (var _b = __values(this._entities), _c = _b.next(); !_c.done; _c = _b.next()) { + var entity = _c.value; + entity._isDestroyed = true; + entity.onRemovedFromScene(); + entity.scene = null; + } } + catch (e_7_1) { e_7 = { error: e_7_1 }; } + finally { + try { + if (_c && !_c.done && (_a = _b.return)) _a.call(_b); + } + finally { if (e_7) throw e_7.error; } + } + // 清空实体列表和实体字典 this._entities.length = 0; this._entityDict.clear(); }; /** - * 检查实体目前是否由这个EntityList管理 - * @param entity + * 检查实体是否已经被添加到场景中。 + * @param entity 要检查的实体 + * @returns 如果实体已经被添加到场景中,则返回true;否则返回false */ EntityList.prototype.contains = function (entity) { + // 检查实体是否存在于_entitiesToAdded字典中 return !!this._entitiesToAdded[entity.id]; }; + /** + * 获取具有指定标签的实体列表。 + * 如果列表不存在,则创建一个新列表并返回。 + * @param tag 实体标签 + * @returns 具有指定标签的实体列表 + */ EntityList.prototype.getTagList = function (tag) { + // 尝试从_entityDict中获取具有指定标签的实体列表 var list = this._entityDict.get(tag); + // 如果列表不存在,则创建一个新的Set实例,并添加到_entityDict中 if (!list) { list = new Set(); this._entityDict.set(tag, list); } return list; }; + /** + * 添加实体到标签列表中。 + * @param entity 实体 + */ EntityList.prototype.addToTagList = function (entity) { - this.getTagList(entity.tag).add(entity); + // 获取标签列表 + var list = this.getTagList(entity.tag); + // 将实体添加到标签列表中 + list.add(entity); + // 添加未排序标志 this._unsortedTags.add(entity.tag); }; + /** + * 从标签列表中移除实体。 + * @param entity 实体 + */ EntityList.prototype.removeFromTagList = function (entity) { + // 获取实体的标签列表 var list = this._entityDict.get(entity.tag); - if (list) + // 如果标签列表存在,则从中移除实体 + if (list) { list.delete(entity); - }; - EntityList.prototype.update = function () { - for (var i = 0, s = this._entities.length; i < s; ++i) { - var entity = this._entities[i]; - if (entity.enabled && (entity.updateInterval == 1 || es.Time.frameCount % entity.updateInterval == 0)) - entity.update(); } }; + /** + * 更新场景中所有启用的实体的Update方法 + * 如果实体的UpdateInterval为1或Time.frameCount模除UpdateInterval为0,则每帧调用Update + */ + EntityList.prototype.update = function () { + for (var i = 0; i < this._entities.length; i++) { + var entity = this._entities[i]; + if (entity.enabled && (entity.updateInterval === 1 || es.Time.frameCount % entity.updateInterval === 0)) { + entity.update(); + } + } + }; + /** + * 更新场景中实体的列表。 + */ EntityList.prototype.updateLists = function () { + var e_8, _a, e_9, _b, e_10, _c, e_11, _d; + // 处理要移除的实体 if (this._entitiesToRemoveList.length > 0) { - var _loop_2 = function (i, s) { - var entity = this_2._entitiesToRemoveList[i]; + var _loop_2 = function (entity) { + // 从标签列表中删除实体 this_2.removeFromTagList(entity); - // 处理常规实体列表 - var index = this_2._entities.findIndex(function (e) { return e.id == entity.id; }); - if (index != -1) + // 从场景实体列表中删除实体 + var index = this_2._entities.findIndex(function (e) { return e.id === entity.id; }); + if (index !== -1) { this_2._entities.splice(index, 1); + } + // 调用实体的onRemovedFromScene方法,并将其scene属性设置为null entity.onRemovedFromScene(); entity.scene = null; + // 通知场景实体处理器,一个实体已被移除 this_2.scene.entityProcessors.onEntityRemoved(entity); }; var this_2 = this; - for (var i = 0, s = this._entitiesToRemoveList.length; i < s; ++i) { - _loop_2(i, s); + try { + for (var _e = __values(this._entitiesToRemoveList), _f = _e.next(); !_f.done; _f = _e.next()) { + var entity = _f.value; + _loop_2(entity); + } } + catch (e_8_1) { e_8 = { error: e_8_1 }; } + finally { + try { + if (_f && !_f.done && (_a = _e.return)) _a.call(_e); + } + finally { if (e_8) throw e_8.error; } + } + // 清空要移除的实体列表和字典 this._entitiesToRemove = {}; this._entitiesToRemoveList.length = 0; } + // 处理要添加的实体 if (this._entitiesToAddedList.length > 0) { - for (var i = 0, s = this._entitiesToAddedList.length; i < s; ++i) { - var entity = this._entitiesToAddedList[i]; - this._entities.push(entity); - entity.scene = this.scene; - this.addToTagList(entity); - this.scene.entityProcessors.onEntityAdded(entity); + try { + // 添加实体到场景实体列表和标签列表中 + for (var _g = __values(this._entitiesToAddedList), _h = _g.next(); !_h.done; _h = _g.next()) { + var entity = _h.value; + this._entities.push(entity); + entity.scene = this.scene; + this.addToTagList(entity); + } } - for (var i = 0, s = this._entitiesToAddedList.length; i < s; ++i) { - var entity = this._entitiesToAddedList[i]; - entity.onAddedToScene(); + catch (e_9_1) { e_9 = { error: e_9_1 }; } + finally { + try { + if (_h && !_h.done && (_b = _g.return)) _b.call(_g); + } + finally { if (e_9) throw e_9.error; } } + try { + // 通知场景实体处理器,有新的实体已添加 + for (var _j = __values(this._entitiesToAddedList), _k = _j.next(); !_k.done; _k = _j.next()) { + var entity = _k.value; + this.scene.entityProcessors.onEntityAdded(entity); + } + } + catch (e_10_1) { e_10 = { error: e_10_1 }; } + finally { + try { + if (_k && !_k.done && (_c = _j.return)) _c.call(_j); + } + finally { if (e_10) throw e_10.error; } + } + try { + // 调用实体的onAddedToScene方法,以允许它们执行任何场景相关的操作 + for (var _l = __values(this._entitiesToAddedList), _m = _l.next(); !_m.done; _m = _l.next()) { + var entity = _m.value; + entity.onAddedToScene(); + } + } + catch (e_11_1) { e_11 = { error: e_11_1 }; } + finally { + try { + if (_m && !_m.done && (_d = _l.return)) _d.call(_l); + } + finally { if (e_11) throw e_11.error; } + } + // 清空要添加的实体列表和字典 this._entitiesToAdded = {}; this._entitiesToAddedList.length = 0; } @@ -4894,44 +5189,51 @@ var es; return null; }; /** - * - * @param id - * @returns + * 通过实体ID在场景中查找对应实体 + * @param id 实体ID + * @returns 返回找到的实体,如果没有找到则返回 null */ EntityList.prototype.findEntityById = function (id) { + // 遍历场景中所有实体 if (this._entities.length > 0) { for (var i = 0, s = this._entities.length; i < s; ++i) { var entity = this._entities[i]; + // 如果实体的ID匹配,返回该实体 if (entity.id == id) return entity; } } + // 在未添加的实体列表中查找 return this._entitiesToAdded[id]; }; /** - * 返回带有标签的所有实体的列表。如果没有实体有标签,则返回一个空列表。 - * 返回的List可以通过ListPool.free放回池中 - * @param tag + * 获取标签对应的实体列表 + * @param tag 实体的标签 + * @returns 返回所有拥有该标签的实体列表 */ EntityList.prototype.entitiesWithTag = function (tag) { - var e_2, _a; + var e_12, _a; + // 从字典中获取对应标签的实体列表 var list = this.getTagList(tag); + // 从对象池中获取 Entity 类型的数组 var returnList = es.ListPool.obtain(es.Entity); if (list.size > 0) { try { + // 将实体列表中的实体添加到返回列表中 for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) { var entity = list_1_1.value; returnList.push(entity); } } - catch (e_2_1) { e_2 = { error: e_2_1 }; } + catch (e_12_1) { e_12 = { error: e_12_1 }; } finally { try { if (list_1_1 && !list_1_1.done && (_a = list_1.return)) _a.call(list_1); } - finally { if (e_2) throw e_2.error; } + finally { if (e_12) throw e_12.error; } } } + // 返回已填充好实体的返回列表 return returnList; }; /** @@ -4940,7 +5242,7 @@ var es; * @returns */ EntityList.prototype.entityWithTag = function (tag) { - var e_3, _a; + var e_13, _a; var list = this.getTagList(tag); if (list.size > 0) { try { @@ -4949,116 +5251,204 @@ var es; return entity; } } - catch (e_3_1) { e_3 = { error: e_3_1 }; } + catch (e_13_1) { e_13 = { error: e_13_1 }; } finally { try { if (list_2_1 && !list_2_1.done && (_a = list_2.return)) _a.call(list_2); } - finally { if (e_3) throw e_3.error; } + finally { if (e_13) throw e_13.error; } } } return null; }; /** - * 返回在场景中找到的第一个T类型的组件。 - * @param type + * 在场景中查找具有给定类型的组件。 + * @param type 要查找的组件类型。 + * @returns 如果找到,则返回该组件;否则返回null。 */ EntityList.prototype.findComponentOfType = function (type) { - if (this._entities.length > 0) { - for (var i = 0, s = this._entities.length; i < s; i++) { - var entity = this._entities[i]; + var e_14, _a, e_15, _b; + try { + // 遍历场景中的所有实体,查找具有给定类型的组件 + for (var _c = __values(this._entities), _d = _c.next(); !_d.done; _d = _c.next()) { + var entity = _d.value; if (entity.enabled) { var comp = entity.getComponent(type); - if (comp) + if (comp) { return comp; + } } } } - if (this._entitiesToAddedList.length > 0) { - for (var i = 0; i < this._entitiesToAddedList.length; i++) { - var entity = this._entitiesToAddedList[i]; + catch (e_14_1) { e_14 = { error: e_14_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_14) throw e_14.error; } + } + try { + // 遍历待添加的实体列表中的所有实体,查找具有给定类型的组件 + for (var _e = __values(this._entitiesToAddedList), _f = _e.next(); !_f.done; _f = _e.next()) { + var entity = _f.value; if (entity.enabled) { var comp = entity.getComponent(type); - if (comp) + if (comp) { return comp; + } } } } + catch (e_15_1) { e_15 = { error: e_15_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_15) throw e_15.error; } + } + // 如果找不到具有给定类型的组件,则返回null return null; }; /** - * 返回在场景中找到的所有T类型的组件。 - * 返回的List可以通过ListPool.free放回池中。 - * @param type + * 在场景中查找具有给定类型的所有组件。 + * @param type 要查找的组件类型。 + * @returns 具有给定类型的所有组件的列表。 */ EntityList.prototype.findComponentsOfType = function (type) { + var e_16, _a, e_17, _b; + // 从池中获取一个可重用的组件列表 var comps = es.ListPool.obtain(type); - if (this._entities.length > 0) { - for (var i = 0, s = this._entities.length; i < s; i++) { - var entity = this._entities[i]; - if (entity.enabled) + try { + // 遍历场景中的所有实体,查找具有给定类型的组件并添加到组件列表中 + for (var _c = __values(this._entities), _d = _c.next(); !_d.done; _d = _c.next()) { + var entity = _d.value; + if (entity.enabled) { entity.getComponents(type, comps); + } } } - if (this._entitiesToAddedList.length > 0) { - for (var i = 0, s = this._entitiesToAddedList.length; i < s; i++) { - var entity = this._entitiesToAddedList[i]; - if (entity.enabled) + catch (e_16_1) { e_16 = { error: e_16_1 }; } + finally { + try { + if (_d && !_d.done && (_a = _c.return)) _a.call(_c); + } + finally { if (e_16) throw e_16.error; } + } + try { + // 遍历待添加的实体列表中的所有实体,查找具有给定类型的组件并添加到组件列表中 + for (var _e = __values(this._entitiesToAddedList), _f = _e.next(); !_f.done; _f = _e.next()) { + var entity = _f.value; + if (entity.enabled) { entity.getComponents(type, comps); + } } } + catch (e_17_1) { e_17 = { error: e_17_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e.return)) _b.call(_e); + } + finally { if (e_17) throw e_17.error; } + } + // 返回具有给定类型的所有组件的列表 return comps; }; /** - * 返回场景中包含特定组件的实体列表 - * @param types - * @returns + * 返回拥有指定类型组件的所有实体 + * @param types 要查询的组件类型列表 + * @returns 返回拥有指定类型组件的所有实体 */ EntityList.prototype.findEntitiesOfComponent = function () { var types = []; for (var _i = 0; _i < arguments.length; _i++) { types[_i] = arguments[_i]; } + var e_18, _a, e_19, _b, e_20, _c, e_21, _d; var entities = []; - if (this._entities.length > 0) { - for (var i = 0, s = this._entities.length; i < s; i++) { - if (this._entities[i].enabled) { - var meet = true; - if (types.length > 0) - for (var t = 0, ts = types.length; t < ts; t++) { - var type = types[t]; - var hasComp = this._entities[i].hasComponent(type); - if (!hasComp) { - meet = false; - break; - } - } - if (meet) { - entities.push(this._entities[i]); - } - } - } - } - if (this._entitiesToAddedList.length > 0) { - for (var i = 0, s = this._entitiesToAddedList.length; i < s; i++) { - var entity = this._entitiesToAddedList[i]; + try { + // 遍历所有已存在的实体 + for (var _e = __values(this._entities), _f = _e.next(); !_f.done; _f = _e.next()) { + var entity = _f.value; + // 只有启用的实体才会被考虑 if (entity.enabled) { + // 如果types数组为空,直接将实体添加到结果数组中 + if (types.length === 0) { + entities.push(entity); + continue; + } + // 对于每个指定的组件类型,检查实体是否具有该组件 var meet = true; - if (types.length > 0) - for (var t = 0, ts = types.length; t < ts; t++) { - var type = types[t]; + try { + for (var types_1 = __values(types), types_1_1 = types_1.next(); !types_1_1.done; types_1_1 = types_1.next()) { + var type = types_1_1.value; var hasComp = entity.hasComponent(type); if (!hasComp) { meet = false; break; } } + } + catch (e_19_1) { e_19 = { error: e_19_1 }; } + finally { + try { + if (types_1_1 && !types_1_1.done && (_b = types_1.return)) _b.call(types_1); + } + finally { if (e_19) throw e_19.error; } + } + // 如果实体满足要求,将其添加到结果数组中 if (meet) { entities.push(entity); } } } } + catch (e_18_1) { e_18 = { error: e_18_1 }; } + finally { + try { + if (_f && !_f.done && (_a = _e.return)) _a.call(_e); + } + finally { if (e_18) throw e_18.error; } + } + try { + // 遍历所有等待添加的实体,和上面的操作类似 + for (var _g = __values(this._entitiesToAddedList), _h = _g.next(); !_h.done; _h = _g.next()) { + var entity = _h.value; + if (entity.enabled) { + if (types.length === 0) { + entities.push(entity); + continue; + } + var meet = true; + try { + for (var types_2 = __values(types), types_2_1 = types_2.next(); !types_2_1.done; types_2_1 = types_2.next()) { + var type = types_2_1.value; + var hasComp = entity.hasComponent(type); + if (!hasComp) { + meet = false; + break; + } + } + } + catch (e_21_1) { e_21 = { error: e_21_1 }; } + finally { + try { + if (types_2_1 && !types_2_1.done && (_d = types_2.return)) _d.call(types_2); + } + finally { if (e_21) throw e_21.error; } + } + if (meet) { + entities.push(entity); + } + } + } + } + catch (e_20_1) { e_20 = { error: e_20_1 }; } + finally { + try { + if (_h && !_h.done && (_c = _g.return)) _c.call(_g); + } + finally { if (e_20) throw e_20.error; } + } return entities; }; return EntityList; @@ -5069,11 +5459,11 @@ var es; (function (es) { var EntityProcessorList = /** @class */ (function () { function EntityProcessorList() { - this._processors = []; - this._orderDirty = false; + this._processors = []; // 处理器列表 + this._orderDirty = false; // 处理器排序标志 } Object.defineProperty(EntityProcessorList.prototype, "processors", { - /** 获取系统列表 */ + /** 获取处理器列表 */ get: function () { return this._processors; }, @@ -5081,86 +5471,152 @@ var es; configurable: true }); Object.defineProperty(EntityProcessorList.prototype, "count", { - /** 系统数量 */ + /** 获取处理器数量 */ get: function () { return this._processors.length; }, enumerable: true, configurable: true }); + /** + * 添加处理器 + * @param processor 要添加的处理器 + */ EntityProcessorList.prototype.add = function (processor) { this._processors.push(processor); }; + /** + * 移除处理器 + * @param processor 要移除的处理器 + */ EntityProcessorList.prototype.remove = function (processor) { + // 使用 es.List 类的 remove() 方法从处理器列表中移除指定处理器 new es.List(this._processors).remove(processor); }; + /** + * 在实体上添加组件时被调用 + * @param entity 添加组件的实体 + */ EntityProcessorList.prototype.onComponentAdded = function (entity) { this.notifyEntityChanged(entity); }; + /** + * 在实体上移除组件时被调用 + * @param entity 移除组件的实体 + */ EntityProcessorList.prototype.onComponentRemoved = function (entity) { this.notifyEntityChanged(entity); }; + /** + * 在场景中添加实体时被调用 + * @param entity 添加的实体 + */ EntityProcessorList.prototype.onEntityAdded = function (entity) { this.notifyEntityChanged(entity); }; + /** + * 在场景中移除实体时被调用 + * @param entity 移除的实体 + */ EntityProcessorList.prototype.onEntityRemoved = function (entity) { this.removeFromProcessors(entity); }; + /** 在处理器列表上开始循环 */ EntityProcessorList.prototype.begin = function () { }; + /** 更新处理器列表 */ EntityProcessorList.prototype.update = function () { - if (this._processors.length == 0) + // 如果处理器列表为空,则直接返回 + if (this._processors.length === 0) { return; + } + // 如果需要重新排序处理器列表 if (this._orderDirty) { - // 进行排序 - this._processors = this._processors.sort(function (a, b) { return a.updateOrder - b.updateOrder; }); + // 对处理器列表进行排序 + this._processors.sort(function (a, b) { return a.updateOrder - b.updateOrder; }); + // 重新设置处理器的更新顺序 for (var i = 0, s = this._processors.length; i < s; ++i) { var processor = this._processors[i]; processor.setUpdateOrder(i); } + // 将标志设置为“未脏” this.clearDirty(); } + // 调用每个处理器的 update() 方法 for (var i = 0, s = this._processors.length; i < s; ++i) { - this._processors[i].update(); - } - }; - EntityProcessorList.prototype.lateUpdate = function () { - if (this._processors.length == 0) - return; - for (var i = 0, s = this._processors.length; i < s; ++i) { - this._processors[i].lateUpdate(); + var processor = this._processors[i]; + processor.update(); } }; + /** 在处理器列表上完成循环 */ EntityProcessorList.prototype.end = function () { }; + /** 设置处理器排序标志 */ EntityProcessorList.prototype.setDirty = function () { this._orderDirty = true; }; + /** 清除处理器排序标志 */ EntityProcessorList.prototype.clearDirty = function () { this._orderDirty = false; }; + /** + * 获取指定类型的处理器 + * @param type 指定类型的构造函数 + * @returns 指定类型的处理器 + */ EntityProcessorList.prototype.getProcessor = function (type) { - if (this._processors.length == 0) + // 如果处理器列表为空,则返回null + if (this._processors.length === 0) { return null; + } + // 遍历处理器列表,查找指定类型的处理器 for (var i = 0, s = this._processors.length; i < s; ++i) { var processor = this._processors[i]; - if (processor instanceof type) + // 如果当前处理器是指定类型的实例,则返回当前处理器 + if (processor instanceof type) { return processor; + } } + // 如果没有找到指定类型的处理器,则返回null return null; }; + /** + * 通知处理器实体已更改 + * @param entity 发生更改的实体 + */ EntityProcessorList.prototype.notifyEntityChanged = function (entity) { - if (this._processors.length == 0) + if (this._processors.length === 0) { return; + } + // 遍历处理器列表,调用每个处理器的 onChanged() 方法 for (var i = 0, s = this._processors.length; i < s; ++i) { - this._processors[i].onChanged(entity); + var processor = this._processors[i]; + processor.onChanged(entity); } }; + /** + * 从处理器列表中移除实体 + * @param entity 要移除的实体 + */ EntityProcessorList.prototype.removeFromProcessors = function (entity) { - if (this._processors.length == 0) + if (this._processors.length === 0) { return; + } + // 遍历处理器列表,调用每个处理器的 remove() 方法 for (var i = 0, s = this._processors.length; i < s; ++i) { - this._processors[i].remove(entity); + var processor = this._processors[i]; + processor.remove(entity); + } + }; + /** 在处理器列表上进行后期更新 */ + EntityProcessorList.prototype.lateUpdate = function () { + if (this._processors.length === 0) { + return; + } + // 调用每个处理器的 lateUpdate() 方法 + for (var i = 0, s = this._processors.length; i < s; ++i) { + var processor = this._processors[i]; + processor.lateUpdate(); } }; return EntityProcessorList; @@ -5172,36 +5628,50 @@ var es; var HashHelpers = /** @class */ (function () { function HashHelpers() { } + /** + * 判断一个数是否为质数 + * @param candidate 要判断的数 + * @returns 是否为质数 + */ HashHelpers.isPrime = function (candidate) { - if ((candidate & 1) != 0) { + if ((candidate & 1) !== 0) { // 位运算判断奇偶性 var limit = Math.sqrt(candidate); - for (var divisor = 3; divisor <= limit; divisor += 2) { - if ((candidate & divisor) == 0) + for (var divisor = 3; divisor <= limit; divisor += 2) { // 奇数因子判断 + if ((candidate % divisor) === 0) { return false; + } } return true; } - return (candidate == 2); + return (candidate === 2); // 2是质数 }; + /** + * 获取大于等于指定值的最小质数 + * @param min 指定值 + * @returns 大于等于指定值的最小质数 + */ HashHelpers.getPrime = function (min) { - if (min < 0) - throw new Error("参数错误 min不能小于0"); + if (min < 0) { + throw new Error("参数错误 min 不能小于0"); + } for (var i = 0; i < this.primes.length; i++) { var prime = this.primes[i]; - if (prime >= min) + if (prime >= min) { return prime; + } } - // 在我们预定义的表之外,计算的方式稍复杂。 - for (var i = (min | 1); i < Number.MAX_VALUE; i += 2) { - if (this.isPrime(i) && ((i - 1) % this.hashPrime != 0)) + // 在预定义的质数列表之外,需要计算最小的质数 + for (var i = (min | 1); i < Number.MAX_VALUE; i += 2) { // 从 min 向上计算奇数 + if (this.isPrime(i) && ((i - 1) % this.hashPrime !== 0)) { // i是质数且不是hashPrime的倍数 return i; + } } return min; }; /** - * - * @param oldSize - * @returns 返回要增长的哈希特表的大小 + * 扩展哈希表容量 + * @param oldSize 原哈希表容量 + * @returns 扩展后的哈希表容量 */ HashHelpers.expandPrime = function (oldSize) { var newSize = 2 * oldSize; @@ -5212,42 +5682,36 @@ var es; } return this.getPrime(newSize); }; + /** + * 计算字符串的哈希值 + * @param str 要计算哈希值的字符串 + * @returns 哈希值 + */ HashHelpers.getHashCode = function (str) { - var s; - if (typeof str == 'object') { - s = JSON.stringify(str); - } - else { - s = str.toString(); - } var hash = 0; - if (s.length == 0) + if (str.length === 0) { return hash; - for (var i = 0; i < s.length; i++) { - var char = s.charCodeAt(i); - hash = ((hash << 5) - hash) + char; - hash = hash & hash; + } + for (var i = 0; i < str.length; i++) { + var char = str.charCodeAt(i); + hash = ((hash << 5) - hash) + char; // 采用 FNV-1a 哈希算法 + hash = hash & hash; // 将hash值转换为32位整数 } return hash; }; + // 哈希冲突阈值,超过此值将使用另一种哈希算法 HashHelpers.hashCollisionThreshold = 100; + // 哈希值用于计算哈希表索引的质数 HashHelpers.hashPrime = 101; - /** - * 用来作为哈希表大小的质数表。 - * 一个典型的调整大小的算法会在这个数组中选取比之前容量大两倍的最小质数。 - * 假设我们的Hashtable当前的容量为x,并且添加了足够多的元素,因此需要进行大小调整。 - * 调整大小首先计算2x,然后在表中找到第一个大于2x的质数,即如果质数的顺序是p_1,p_2,...,p_i,...,则找到p_n,使p_n-1 < 2x < p_n。 - * 双倍对于保持哈希特操作的渐近复杂度是很重要的,比如添加。 - * 拥有一个质数可以保证双倍哈希不会导致无限循环。 IE,你的哈希函数将是h1(key)+i*h2(key),0 <= i < size.h2和size必须是相对质数。 - */ - HashHelpers.primes = [3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919, + // 一组预定义的质数,用于计算哈希表容量 + HashHelpers.primes = [ + 3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919, 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591, 17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437, 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263, - 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369]; - /** - * 这是比Array.MaxArrayLength小的最大质数 - */ + 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369 + ]; + // 可分配的最大数组长度,用于避免 OutOfMemoryException HashHelpers.maxPrimeArrayLength = 0x7FEFFFFD; return HashHelpers; }()); @@ -5609,274 +6073,317 @@ var es; })(es || (es = {})); var es; (function (es) { - /** 提供帧定时信息 */ + /** + * 时间管理器,用于管理游戏中的时间相关属性 + */ var Time = /** @class */ (function () { function Time() { } + /** + * 更新时间管理器 + * @param currentTime 当前时间 + * @param useEngineTime 是否使用引擎时间 + */ Time.update = function (currentTime, useEngineTime) { var dt = 0; if (useEngineTime) { dt = currentTime; } else { - if (currentTime == -1) { + // 如果当前时间为 -1,则表示使用系统时间 + if (currentTime === -1) { currentTime = Date.now(); } - if (this._lastTime == -1) + // 如果上一次记录的时间为 -1,则表示当前为第一次调用 update + if (this._lastTime === -1) { this._lastTime = currentTime; + } + // 计算两次调用 update 之间的时间差,并将其转换为秒 dt = (currentTime - this._lastTime) / 1000; } - if (dt > this.maxDeltaTime) + // 如果计算得到的时间差超过了最大时间步长,则将其限制为最大时间步长 + if (dt > this.maxDeltaTime) { dt = this.maxDeltaTime; + } + // 更新时间管理器的各个属性 this.totalTime += dt; this.deltaTime = dt * this.timeScale; this.unscaledDeltaTime = dt; this.timeSinceSceneLoad += dt; this.frameCount++; + // 记录当前时间,以备下一次调用 update 使用 this._lastTime = currentTime; }; Time.sceneChanged = function () { this.timeSinceSceneLoad = 0; }; /** - * 允许在间隔检查。只应该使用高于delta的间隔值,否则它将始终返回true。 - * @param interval + * 检查指定时间间隔是否已过去 + * @param interval 指定时间间隔 + * @returns 是否已过去指定时间间隔 */ Time.checkEvery = function (interval) { - // 我们减去了delta,因为timeSinceSceneLoad已经包含了这个update ticks delta - return es.MathHelper.toInt(this.timeSinceSceneLoad / interval) > es.MathHelper.toInt((this.timeSinceSceneLoad - this.deltaTime) / interval); + // 计算当前时刻所经过的完整时间间隔个数(向下取整) + var passedIntervals = Math.floor(this.timeSinceSceneLoad / interval); + // 计算上一帧到当前帧经过的时间所包含的时间间隔个数(向下取整) + var deltaIntervals = Math.floor(this.deltaTime / interval); + // 如果当前时刻所经过的时间间隔数比上一帧所经过的时间间隔数多,则说明时间间隔已过去 + return passedIntervals > deltaIntervals; }; - /** 游戏运行的总时间 */ + /** 游戏运行的总时间,单位为秒 */ Time.totalTime = 0; - /** deltaTime的未缩放版本。不受时间尺度的影响 */ + /** deltaTime 的未缩放版本,不受时间尺度的影响 */ Time.unscaledDeltaTime = 0; /** 前一帧到当前帧的时间增量,按时间刻度进行缩放 */ Time.deltaTime = 0; - /** 时间刻度缩放 */ + /** 时间刻度缩放,可以加快或减慢游戏时间 */ Time.timeScale = 1; - /** DeltaTime可以为的最大值 */ + /** DeltaTime 可以为的最大值,避免游戏出现卡顿情况 */ Time.maxDeltaTime = Number.MAX_VALUE; /** 已传递的帧总数 */ Time.frameCount = 0; - /** 自场景加载以来的总时间 */ + /** 自场景加载以来的总时间,单位为秒 */ Time.timeSinceSceneLoad = 0; + /** 上一次记录的时间,用于计算两次调用 update 之间的时间差 */ Time._lastTime = -1; return Time; }()); es.Time = Time; })(es || (es = {})); -var TimeUtils = /** @class */ (function () { - function TimeUtils() { - } - /** - * 计算月份ID - * @param d 指定计算日期 - * @returns 月ID - */ - TimeUtils.monthId = function (d) { - if (d === void 0) { d = null; } - d = d ? d : new Date(); - var y = d.getFullYear(); - var m = d.getMonth() + 1; - var g = m < 10 ? "0" : ""; - return parseInt(y + g + m); - }; - /** - * 计算日期ID - * @param d 指定计算日期 - * @returns 日期ID - */ - TimeUtils.dateId = function (t) { - if (t === void 0) { t = null; } - t = t ? t : new Date(); - var m = t.getMonth() + 1; - var a = m < 10 ? "0" : ""; - var d = t.getDate(); - var b = d < 10 ? "0" : ""; - return parseInt(t.getFullYear() + a + m + b + d); - }; - /** - * 计算周ID - * @param d 指定计算日期 - * @returns 周ID - */ - TimeUtils.weekId = function (d, first) { - if (d === void 0) { d = null; } - if (first === void 0) { first = true; } - d = d ? d : new Date(); - var c = new Date(); - c.setTime(d.getTime()); - c.setDate(1); - c.setMonth(0); //当年第一天 - var year = c.getFullYear(); - var firstDay = c.getDay(); - if (firstDay == 0) { - firstDay = 7; +var es; +(function (es) { + var TimeUtils = /** @class */ (function () { + function TimeUtils() { } - var max = false; - if (firstDay <= 4) { - max = firstDay > 1; - c.setDate(c.getDate() - (firstDay - 1)); - } - else { - c.setDate(c.getDate() + 7 - firstDay + 1); - } - var num = this.diffDay(d, c, false); - if (num < 0) { + /** + * 获取日期对应的年份和月份的数字组合 + * @param d 要获取月份的日期对象,不传则默认为当前时间 + * @returns 返回数字组合的年份和月份 + */ + TimeUtils.monthId = function (d) { + if (d === void 0) { d = null; } + // 如果传入了时间,则使用传入的时间,否则使用当前时间 + d = d ? d : new Date(); + // 获取当前年份 + var y = d.getFullYear(); + // 获取当前月份,并将月份转化为两位数的字符串格式 + var m = d.getMonth() + 1; + var g = m < 10 ? "0" : ""; + // 返回年份和月份的数字组合 + return parseInt(y + g + m); + }; + /** + * 获取日期的数字组合 + * @param t - 可选参数,传入时间,若不传入则使用当前时间 + * @returns 数字组合 + */ + TimeUtils.dateId = function (t) { + if (t === void 0) { t = null; } + // 如果传入了时间,则使用传入的时间,否则使用当前时间 + t = t ? t : new Date(); + // 获取当前月份,并将月份转化为两位数的字符串格式 + var m = t.getMonth() + 1; + var a = m < 10 ? "0" : ""; + // 获取当前日期,并将日期转化为两位数的字符串格式 + var d = t.getDate(); + var b = d < 10 ? "0" : ""; + // 返回年份、月份和日期的数字组合 + return parseInt(t.getFullYear() + a + m + b + d); + }; + /** + * 获取当前日期所在周的数字组合 + * @param d - 可选参数,传入日期,若不传入则使用当前日期 + * @param first - 是否将当前周视为本年度的第1周,默认为true + * @returns 数字组合 + */ + TimeUtils.weekId = function (d, first) { + if (d === void 0) { d = null; } + if (first === void 0) { first = true; } + d = d ? d : new Date(); + var c = new Date(d.getTime()); // 复制一个新的日期对象,以免改变原始日期对象 c.setDate(1); - c.setMonth(0); //当年第一天 - c.setDate(c.getDate() - 1); - return this.weekId(c, false); - } - var week = num / 7; - var weekIdx = Math.floor(week) + 1; - if (weekIdx == 53) { - c.setTime(d.getTime()); - c.setDate(c.getDate() - 1); - var endDay = c.getDay(); - if (endDay == 0) { - endDay = 7; + c.setMonth(0); // 将日期设置为当年的第一天 + var year = c.getFullYear(); + var firstDay = c.getDay(); + if (firstDay == 0) { + firstDay = 7; } - if (first && (!max || endDay < 4)) { - c.setFullYear(c.getFullYear() + 1); + var max = false; + if (firstDay <= 4) { + max = firstDay > 1; + c.setDate(c.getDate() - (firstDay - 1)); + } + else { + c.setDate(c.getDate() + 7 - firstDay + 1); + } + var num = this.diffDay(d, c, false); // 计算当前日期与本年度的第一个星期一之间的天数 + if (num < 0) { + // 当前日期在本年度第一个星期一之前,则返回上一年度的最后一个星期 c.setDate(1); - c.setMonth(0); //当年第一天 + c.setMonth(0); + c.setDate(c.getDate() - 1); return this.weekId(c, false); } - } - var g = weekIdx > 9 ? "" : "0"; - var s = year + "00" + g + weekIdx; //加上00防止和月份ID冲突 - return parseInt(s); - }; - /** - * 计算俩日期时间差,如果a比b小,返回负数 - */ - TimeUtils.diffDay = function (a, b, fixOne) { - if (fixOne === void 0) { fixOne = false; } - var x = (a.getTime() - b.getTime()) / 86400000; - return fixOne ? Math.ceil(x) : Math.floor(x); - }; - /** - * 获取本周一 凌晨时间 - */ - TimeUtils.getFirstDayOfWeek = function (d) { - d = d ? d : new Date(); - var day = d.getDay() || 7; - return new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1 - day, 0, 0, 0, 0); - }; - /** - * 获取当日凌晨时间 - */ - TimeUtils.getFirstOfDay = function (d) { - d = d ? d : new Date(); - d.setHours(0, 0, 0, 0); - return d; - }; - /** - * 获取次日凌晨时间 - */ - TimeUtils.getNextFirstOfDay = function (d) { - return new Date(this.getFirstOfDay(d).getTime() + 86400000); - }; - /** - * @returns 2018-12-12 - */ - TimeUtils.formatDate = function (date) { - var y = date.getFullYear(); - var m = date.getMonth() + 1; - m = m < 10 ? '0' + m : m; - var d = date.getDate(); - d = d < 10 ? ('0' + d) : d; - return y + '-' + m + '-' + d; - }; - /** - * @returns 2018-12-12 12:12:12 - */ - TimeUtils.formatDateTime = function (date) { - var y = date.getFullYear(); - var m = date.getMonth() + 1; - m = m < 10 ? ('0' + m) : m; - var d = date.getDate(); - d = d < 10 ? ('0' + d) : d; - var h = date.getHours(); - var i = date.getMinutes(); - i = i < 10 ? ('0' + i) : i; - var s = date.getSeconds(); - s = s < 10 ? ('0' + s) : s; - return y + '-' + m + '-' + d + ' ' + h + ':' + i + ":" + s; - }; - /** - * @returns s 2018-12-12 或者 2018-12-12 12:12:12 - */ - TimeUtils.parseDate = function (s) { - var t = Date.parse(s); - if (!isNaN(t)) { - return new Date(Date.parse(s.replace(/-/g, "/"))); - } - else { - return new Date(); - } - }; - /** - * 秒数转换为时间形式。 - * @param time 秒数 - * @param partition 分隔符 - * @param showHour 是否显示小时 - * @return 返回一个以分隔符分割的时, 分, 秒 - * - * 比如: time = 4351; secondToTime(time)返回字符串01:12:31; - */ - TimeUtils.secondToTime = function (time, partition, showHour) { - if (time === void 0) { time = 0; } - if (partition === void 0) { partition = ":"; } - if (showHour === void 0) { showHour = true; } - var hours = Math.floor(time / 3600); - var minutes = Math.floor(time % 3600 / 60); - var seconds = Math.floor(time % 3600 % 60); - var h = hours.toString(); - var m = minutes.toString(); - var s = seconds.toString(); - if (hours < 10) - h = "0" + h; - if (minutes < 10) - m = "0" + m; - if (seconds < 10) - s = "0" + s; - var timeStr; - if (showHour) - timeStr = h + partition + m + partition + s; - else - timeStr = m + partition + s; - return timeStr; - }; - /** - * 时间形式转换为毫秒数。 - * @param time 以指定分隔符分割的时间字符串 - * @param partition 分隔符 - * @return 毫秒数显示的字符串 - * @throws Error Exception - * - * 用法1 trace(MillisecondTransform.timeToMillisecond("00:60:00")) - * 输出 3600000 - * - * - * 用法2 trace(MillisecondTransform.timeToMillisecond("00.60.00",".")) - * 输出 3600000 - */ - TimeUtils.timeToMillisecond = function (time, partition) { - if (partition === void 0) { partition = ":"; } - var _ary = time.split(partition); - var timeNum = 0; - var len = _ary.length; - for (var i = 0; i < len; i++) { - var n = _ary[i]; - timeNum += n * Math.pow(60, (len - 1 - i)); - } - timeNum *= 1000; - return timeNum.toString(); - }; - return TimeUtils; -}()); + // 计算当前日期在本年度中是第几个星期 + var week = Math.floor(num / 7); + var weekIdx = Math.floor(week) + 1; + if (weekIdx == 53) { + c.setTime(d.getTime()); + c.setDate(c.getDate() - 1); + var endDay = c.getDay(); + if (endDay == 0) { + endDay = 7; + } + if (first && (!max || endDay < 4)) { + // 如果当前日期在本年度的最后一个星期并且当前年度的星期数不足53或当前日期在本年度第53周的星期4或更早,则返回下一年度的第1周 + c.setFullYear(c.getFullYear() + 1); + c.setDate(1); + c.setMonth(0); + return this.weekId(c, false); + } + } + var g = weekIdx > 9 ? "" : "0"; + var s = year + "00" + g + weekIdx; // 加上00防止和月份ID冲突 + return parseInt(s); + }; + /** + * 计算两个日期之间相差的天数 + * @param a 第一个日期 + * @param b 第二个日期 + * @param fixOne 是否将相差天数四舍五入到整数 + * @returns 两个日期之间相差的天数 + */ + TimeUtils.diffDay = function (a, b, fixOne) { + if (fixOne === void 0) { fixOne = false; } + var x = (a.getTime() - b.getTime()) / 86400000; // 计算两个日期相差的毫秒数,然后除以一天的毫秒数,得到相差的天数 + return fixOne ? Math.ceil(x) : Math.floor(x); // 如果 fixOne 参数为 true,则将相差天数四舍五入到整数,否则向下取整 + }; + /** + * 获取指定日期所在周的第一天 + * @param d 指定日期,默认值为今天 + * @returns 指定日期所在周的第一天 + */ + TimeUtils.getFirstDayOfWeek = function (d) { + if (d === void 0) { d = new Date(); } + // 获取当前日期是星期几,如果是0,则设置为7 + var dayOfWeek = d.getDay() || 7; + // 计算出指定日期所在周的第一天,即将指定日期减去星期几再加1 + // 这里用1减去dayOfWeek是为了保证星期一为一周的第一天 + return new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1 - dayOfWeek, 0, 0, 0, 0); + }; + /** + * 获取当日凌晨时间 + */ + TimeUtils.getFirstOfDay = function (d) { + d = d ? d : new Date(); + d.setHours(0, 0, 0, 0); + return d; + }; + /** + * 获取次日凌晨时间 + */ + TimeUtils.getNextFirstOfDay = function (d) { + return new Date(this.getFirstOfDay(d).getTime() + 86400000); + }; + /** + * 格式化日期为 "YYYY-MM-DD" 的字符串形式 + * @param date 要格式化的日期 + * @returns 格式化后的日期字符串 + */ + TimeUtils.formatDate = function (date) { + var y = date.getFullYear(); + var m = date.getMonth() + 1; + m = m < 10 ? '0' + m : m; + var d = date.getDate(); + d = d < 10 ? ('0' + d) : d; + return y + '-' + m + '-' + d; + }; + /** + * 将日期对象格式化为 "YYYY-MM-DD HH:mm:ss" 的字符串 + * @param date 日期对象 + * @returns 格式化后的字符串 + */ + TimeUtils.formatDateTime = function (date) { + var y = date.getFullYear(); + var m = date.getMonth() + 1; + m = m < 10 ? ('0' + m) : m; + var d = date.getDate(); + d = d < 10 ? ('0' + d) : d; + var h = date.getHours(); + var i = date.getMinutes(); + i = i < 10 ? ('0' + i) : i; + var s = date.getSeconds(); + s = s < 10 ? ('0' + s) : s; + return y + '-' + m + '-' + d + ' ' + h + ':' + i + ":" + s; + }; + /** + * 将字符串解析为Date对象 + * @param s 要解析的日期字符串,例如:2022-01-01 + * @returns 返回解析后的Date对象,如果解析失败,则返回当前时间的Date对象 + */ + TimeUtils.parseDate = function (s) { + var t = Date.parse(s); + if (!isNaN(t)) { + // 如果日期字符串中的分隔符为“-”,则需要先将其转换为“/”,否则解析会失败 + return new Date(Date.parse(s.replace(/-/g, "/"))); + } + else { + return new Date(); + } + }; + /** + * 将秒数转换为时分秒的格式 + * @param time 秒数 + * @param partition 分隔符 + * @param showHour 是否显示小时位 + * @returns 转换后的时间字符串 + */ + TimeUtils.secondToTime = function (time, partition, showHour) { + if (time === void 0) { time = 0; } + if (partition === void 0) { partition = ":"; } + if (showHour === void 0) { showHour = true; } + var hours = Math.floor(time / 3600); + var minutes = Math.floor(time % 3600 / 60); + var seconds = Math.floor(time % 3600 % 60); + var h = hours.toString(); + var m = minutes.toString(); + var s = seconds.toString(); + if (hours < 10) + h = "0" + h; + if (minutes < 10) + m = "0" + m; + if (seconds < 10) + s = "0" + s; + var timeStr; + if (showHour) + timeStr = h + partition + m + partition + s; + else + timeStr = m + partition + s; + return timeStr; + }; + /** + * 将时间字符串转换为毫秒数 + * @param time 时间字符串,如 "01:30:15" 表示 1小时30分钟15秒 + * @param partition 分隔符,默认为 ":" + * @returns 转换后的毫秒数字符串 + */ + TimeUtils.timeToMillisecond = function (time, partition) { + if (partition === void 0) { partition = ":"; } + var _ary = time.split(partition); + var timeNum = 0; + var len = _ary.length; + // 将时间转换成毫秒数 + for (var i = 0; i < len; i++) { + var n = _ary[i]; + timeNum += n * Math.pow(60, (len - 1 - i)); + } + timeNum *= 1000; + return timeNum.toString(); + }; + return TimeUtils; + }()); + es.TimeUtils = TimeUtils; +})(es || (es = {})); var es; (function (es) { /** @@ -12161,7 +12668,7 @@ var es; for (var _i = 1; _i < arguments.length; _i++) { data[_i - 1] = arguments[_i]; } - var e_4, _a, _b; + var e_22, _a, _b; var list = this._messageTable.get(eventType); if (list) { try { @@ -12170,12 +12677,12 @@ var es; (_b = observer.func).call.apply(_b, __spread([observer.context], data)); } } - catch (e_4_1) { e_4 = { error: e_4_1 }; } + catch (e_22_1) { e_22 = { error: e_22_1 }; } finally { try { if (list_3_1 && !list_3_1.done && (_a = list_3.return)) _a.call(list_3); } - finally { if (e_4) throw e_4.error; } + finally { if (e_22) throw e_22.error; } } } }; @@ -13255,276 +13762,6 @@ var es; es.Bag = Bag; })(es || (es = {})); var es; -(function (es) { - /** - * 创建这个字典的原因只有一个: - * 我需要一个能让我直接以数组的形式对值进行迭代的字典,而不需要生成一个数组或使用迭代器。 - * 对于这个目标是比标准字典快N倍。 - * Faster dictionary在大部分操作上也比标准字典快,但差别可以忽略不计。 - * 唯一较慢的操作是在添加时调整内存大小,因为与标准数组相比,这个实现需要使用两个单独的数组。 - */ - var FasterDictionary = /** @class */ (function () { - function FasterDictionary(size) { - if (size === void 0) { size = 1; } - this._freeValueCellIndex = 0; - this._collisions = 0; - this._valuesInfo = new Array(size); - this._values = new Array(size); - this._buckets = new Array(es.HashHelpers.getPrime(size)); - } - FasterDictionary.prototype.getValuesArray = function (count) { - count.value = this._freeValueCellIndex; - return this._values; - }; - Object.defineProperty(FasterDictionary.prototype, "valuesArray", { - get: function () { - return this._values; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(FasterDictionary.prototype, "count", { - get: function () { - return this._freeValueCellIndex; - }, - enumerable: true, - configurable: true - }); - FasterDictionary.prototype.add = function (key, value) { - if (!this.addValue(key, value, { value: 0 })) - throw new Error("key 已经存在"); - }; - FasterDictionary.prototype.addValue = function (key, value, indexSet) { - var hash = es.HashHelpers.getHashCode(key); - var bucketIndex = FasterDictionary.reduce(hash, this._buckets.length); - if (this._freeValueCellIndex == this._values.length) { - var expandPrime = es.HashHelpers.expandPrime(this._freeValueCellIndex); - this._values.length = expandPrime; - this._valuesInfo.length = expandPrime; - } - // buckets值-1表示它是空的 - var valueIndex = es.NumberExtension.toNumber(this._buckets[bucketIndex]) - 1; - if (valueIndex == -1) { - // 在最后一个位置创建信息节点,并填入相关信息 - this._valuesInfo[this._freeValueCellIndex] = new FastNode(key, hash); - } - else { - { - var currentValueIndex = valueIndex; - do { - // 必须检查键是否已经存在于字典中 - if (this._valuesInfo[currentValueIndex].hashcode == hash && - this._valuesInfo[currentValueIndex].key == key) { - // 键已经存在,只需将其值替换掉即可 - this._values[currentValueIndex] = value; - indexSet.value = currentValueIndex; - return false; - } - currentValueIndex = this._valuesInfo[currentValueIndex].previous; - } while (currentValueIndex != -1); // -1表示没有更多的值与相同的哈希值的键 - } - this._collisions++; - // 创建一个新的节点,该节点之前的索引指向当前指向桶的节点 - this._valuesInfo[this._freeValueCellIndex] = new FastNode(key, hash, valueIndex); - // 更新现有单元格的下一个单元格指向新的单元格,旧的单元格 -> 新的单元格 -> 旧的单元格 <- 下一个单元格 - this._valuesInfo[valueIndex].next = this._freeValueCellIndex; - } - // 重要的是:新的节点总是被桶单元格指向的那个节点,所以我可以假设被桶指向的那个节点总是最后添加的值(next = -1) - // item与这个bucketIndex将指向最后创建的值 - // TODO: 如果相反,我假设原来的那个是bucket中的那个,我就不需要在这里更新bucket了 - this._buckets[bucketIndex] = (this._freeValueCellIndex + 1); - this._values[this._freeValueCellIndex] = value; - indexSet.value = this._freeValueCellIndex; - this._freeValueCellIndex++; - if (this._collisions > this._buckets.length) { - // 我们需要更多的空间和更少的碰撞 - this._buckets = new Array(es.HashHelpers.expandPrime(this._collisions)); - this._collisions = 0; - // 我们需要得到目前存储的所有值的哈希码,并将它们分布在新的桶长上 - for (var newValueIndex = 0; newValueIndex < this._freeValueCellIndex; newValueIndex++) { - // 获取原始哈希码,并根据新的长度找到新的bucketIndex - bucketIndex = FasterDictionary.reduce(this._valuesInfo[newValueIndex].hashcode, this._buckets.length); - // bucketsIndex可以是-1或下一个值。 - // 如果是-1意味着没有碰撞。 - // 如果有碰撞,我们创建一个新节点,它的上一个指向旧节点。 - // 旧节点指向新节点,新节点指向旧节点,旧节点指向新节点,现在bucket指向新节点,这样我们就可以重建linkedlist. - // 获取当前值Index,如果没有碰撞,则为-1。 - var existingValueIndex = es.NumberExtension.toNumber(this._buckets[bucketIndex]) - 1; - // 将bucket索引更新为共享bucketIndex的当前项目的索引(最后找到的总是bucket中的那个) - this._buckets[bucketIndex] = newValueIndex + 1; - if (existingValueIndex != -1) { - // 这个单元格已经指向了新的bucket list中的一个值,这意味着有一个碰撞,出了问题 - this._collisions++; - // bucket将指向这个值,所以新的值将使用以前的索引 - this._valuesInfo[newValueIndex].previous = existingValueIndex; - this._valuesInfo[newValueIndex].next = -1; - // 并将之前的下一个索引更新为新的索引 - this._valuesInfo[existingValueIndex].next = newValueIndex; - } - else { - // 什么都没有被索引,桶是空的。我们需要更新之前的 next 和 previous 的值。 - this._valuesInfo[newValueIndex].next = -1; - this._valuesInfo[newValueIndex].previous = -1; - } - } - } - return true; - }; - FasterDictionary.prototype.remove = function (key) { - var hash = FasterDictionary.hash(key); - var bucketIndex = FasterDictionary.reduce(hash, this._buckets.length); - // 找桶 - var indexToValueToRemove = es.NumberExtension.toNumber(this._buckets[bucketIndex]) - 1; - // 第一部分:在bucket list中寻找实际的键,如果找到了,我就更新bucket list,使它不再指向要删除的单元格。 - while (indexToValueToRemove != -1) { - if (this._valuesInfo[indexToValueToRemove].hashcode == hash && - this._valuesInfo[indexToValueToRemove].key == key) { - // 如果找到了密钥,并且桶直接指向了要删除的节点 - if (this._buckets[bucketIndex] - 1 == indexToValueToRemove) { - if (this._valuesInfo[indexToValueToRemove].next != -1) - throw new Error("如果 bucket 指向单元格,那么 next 必须不存在。"); - // 如果前一个单元格存在,它的下一个指针必须被更新! - //<---迭代顺序 - // B(ucket总是指向最后一个) - // ------- ------- ------- - // 1 | | | | 2 | | | 3 | //bucket不能有下一个,只能有上一个。 - // ------- ------- ------- - //--> 插入 - var value = this._valuesInfo[indexToValueToRemove].previous; - this._buckets[bucketIndex] = value + 1; - } - else { - if (this._valuesInfo[indexToValueToRemove].next == -1) - throw new Error("如果 bucket 指向另一个单元格,则 NEXT 必须存在"); - } - FasterDictionary.updateLinkedList(indexToValueToRemove, this._valuesInfo); - break; - } - indexToValueToRemove = this._valuesInfo[indexToValueToRemove].previous; - } - if (indexToValueToRemove == -1) - return false; // 未找到 - this._freeValueCellIndex--; // 少了一个需要反复计算的值 - // 第二部分 - // 这时节点指针和水桶会被更新,但_values数组会被更新仍然有要删除的值 - // 这个字典的目标是能够做到像数组一样对数值进行迭代,所以数值数组必须始终是最新的 - // 如果要删除的单元格是列表中的最后一个,我们可以执行较少的操作(不需要交换),否则我们要将最后一个值的单元格移到要删除的值上。 - if (indexToValueToRemove != this._freeValueCellIndex) { - // 我们可以将两个数组的最后一个值移到要删除的数组中。 - // 为了做到这一点,我们需要确保 bucket 指针已经更新了 - // 首先我们在桶列表中找到指向要移动的单元格的指针的索引 - var movingBucketIndex = FasterDictionary.reduce(this._valuesInfo[this._freeValueCellIndex].hashcode, this._buckets.length); - // 如果找到了键,并且桶直接指向要删除的节点,现在必须指向要移动的单元格。 - if (this._buckets[movingBucketIndex] - 1 == this._freeValueCellIndex) - this._buckets[movingBucketIndex] = (indexToValueToRemove + 1); - // 否则意味着有多个键具有相同的哈希值(碰撞),所以我们需要更新链接列表和它的指针 - var next = this._valuesInfo[this._freeValueCellIndex].next; - var previous = this._valuesInfo[this._freeValueCellIndex].previous; - // 现在它们指向最后一个值被移入的单元格 - if (next != -1) - this._valuesInfo[next].previous = indexToValueToRemove; - if (previous != -1) - this._valuesInfo[previous].next = indexToValueToRemove; - // 最后,实际上是移动值 - this._valuesInfo[indexToValueToRemove] = this._valuesInfo[this._freeValueCellIndex]; - this._values[indexToValueToRemove] = this._values[this._freeValueCellIndex]; - } - return true; - }; - FasterDictionary.prototype.trim = function () { - var expandPrime = es.HashHelpers.expandPrime(this._freeValueCellIndex); - if (expandPrime < this._valuesInfo.length) { - this._values.length = expandPrime; - this._valuesInfo.length = expandPrime; - } - }; - FasterDictionary.prototype.clear = function () { - if (this._freeValueCellIndex == 0) - return; - this._freeValueCellIndex = 0; - this._buckets.length = 0; - this._values.length = 0; - this._valuesInfo.length = 0; - }; - FasterDictionary.prototype.fastClear = function () { - if (this._freeValueCellIndex == 0) - return; - this._freeValueCellIndex = 0; - this._buckets.length = 0; - this._valuesInfo.length = 0; - }; - FasterDictionary.prototype.containsKey = function (key) { - if (this.tryFindIndex(key, { value: 0 })) { - return true; - } - return false; - }; - FasterDictionary.prototype.tryGetValue = function (key) { - var findIndex = { value: 0 }; - if (this.tryFindIndex(key, findIndex)) { - return this._values[findIndex.value]; - } - return null; - }; - FasterDictionary.prototype.tryFindIndex = function (key, findIndex) { - // 我把所有的索引都用偏移量+1来存储,这样在bucket list中0就意味着实际上不存在 - // 当读取时,偏移量必须再偏移-1才是真实的 - // 这样我就避免了将数组初始化为-1 - var hash = FasterDictionary.hash(key); - var bucketIndex = FasterDictionary.reduce(hash, this._buckets.length); - var valueIndex = es.NumberExtension.toNumber(this._buckets[bucketIndex]) - 1; - // 即使我们找到了一个现有的值,我们也需要确定它是我们所要求的值 - while (valueIndex != -1) { - if (this._valuesInfo[valueIndex].hashcode == hash && this._valuesInfo[valueIndex].key == key) { - findIndex.value = valueIndex; - return true; - } - valueIndex = this._valuesInfo[valueIndex].previous; - } - findIndex.value = 0; - return false; - }; - FasterDictionary.prototype.getDirectValue = function (index) { - return this._values[index]; - }; - FasterDictionary.prototype.getIndex = function (key) { - var findIndex = { value: 0 }; - if (this.tryFindIndex(key, findIndex)) - return findIndex.value; - throw new Error("未找到key"); - }; - FasterDictionary.updateLinkedList = function (index, valuesInfo) { - var next = valuesInfo[index].next; - var previous = valuesInfo[index].previous; - if (next != -1) - valuesInfo[next].previous = previous; - if (previous != -1) - valuesInfo[previous].next = next; - }; - FasterDictionary.hash = function (key) { - return es.HashHelpers.getHashCode(key); - }; - FasterDictionary.reduce = function (x, n) { - if (x >= n) - return x % n; - return x; - }; - return FasterDictionary; - }()); - es.FasterDictionary = FasterDictionary; - var FastNode = /** @class */ (function () { - function FastNode(key, hash, previousNode) { - if (previousNode === void 0) { previousNode = -1; } - this.key = key; - this.hashcode = hash; - this.previous = previousNode; - this.next = -1; - } - return FastNode; - }()); - es.FastNode = FastNode; -})(es || (es = {})); -var es; (function (es) { var Node = /** @class */ (function () { // next为可选参数,如果不传则为undefined @@ -16057,7 +16294,7 @@ var es; * @returns Set 对象,其中包含了数组中的所有元素 */ List.prototype.toSet = function () { - var e_5, _a; + var e_23, _a; var result = new Set(); try { for (var _b = __values(this._elements), _c = _b.next(); !_c.done; _c = _b.next()) { @@ -16065,12 +16302,12 @@ var es; result.add(x); } } - catch (e_5_1) { e_5 = { error: e_5_1 }; } + catch (e_23_1) { e_23 = { error: e_23_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_5) throw e_5.error; } + finally { if (e_23) throw e_23.error; } } return result; }; @@ -16326,7 +16563,7 @@ var es; * 计算可见性多边形,并返回三角形扇形的顶点(减去中心顶点)。返回的数组来自ListPool */ VisibilityComputer.prototype.end = function () { - var e_6, _a; + var e_24, _a; var output = es.ListPool.obtain(es.Vector2); this.updateSegments(); this._endPoints.sort(this._radialComparer.compare); @@ -16365,12 +16602,12 @@ var es; } } } - catch (e_6_1) { e_6 = { error: e_6_1 }; } + catch (e_24_1) { e_24 = { error: e_24_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_6) throw e_6.error; } + finally { if (e_24) throw e_24.error; } } } VisibilityComputer._openSegments.clear(); @@ -16486,7 +16723,7 @@ var es; * 处理片段,以便我们稍后对它们进行分类 */ VisibilityComputer.prototype.updateSegments = function () { - var e_7, _a; + var e_25, _a; try { for (var _b = __values(this._segments), _c = _b.next(); !_c.done; _c = _b.next()) { var segment = _c.value; @@ -16504,12 +16741,12 @@ var es; segment.p2.begin = !segment.p1.begin; } } - catch (e_7_1) { e_7 = { error: e_7_1 }; } + catch (e_25_1) { e_25 = { error: e_25_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } - finally { if (e_7) throw e_7.error; } + finally { if (e_25) throw e_25.error; } } // 如果我们有一个聚光灯,我们需要存储前两个段的角度。 // 这些是光斑的边界,我们将用它们来过滤它们之外的任何顶点。 diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 094b5c3d..10fc3999 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;e0&&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}}}};!function(t){var e=function(){function e(n,i){void 0===n&&(n=!0),void 0===i&&(i=!0),this._globalManagers=[],this._coroutineManager=new t.CoroutineManager,this._timerManager=new t.TimerManager,this._frameCounterElapsedTime=0,this._frameCounter=0,this._totalMemory=0,e._instance=this,e.emitter=new t.Emitter,e.emitter.addObserver(t.CoreEvents.frameUpdated,this.update,this),e.registerGlobalManager(this._coroutineManager),e.registerGlobalManager(new t.TweenManager),e.registerGlobalManager(this._timerManager),e.entitySystemsEnabled=i,this.debug=n,this.initialize()}return Object.defineProperty(e,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(e,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(e){t.Insist.isNotNull(e,"场景不能为空"),null==this._instance._scene?(this._instance._scene=e,this._instance.onSceneChanged(),this._instance._scene.begin()):this._instance._nextScene=e},enumerable:!0,configurable:!0}),e.create=function(e){return void 0===e&&(e=!0),null==this._instance&&(this._instance=new t.Core(e)),this._instance},e.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},e.unregisterGlobalManager=function(e){new t.List(this._instance._globalManagers).remove(e),e.enabled=!1},e.getGlobalManager=function(t){for(var n=0,i=e._instance._globalManagers.length;n=1)){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._titleMemory&&this._titleMemory(this._totalMemory,this._frameCounter),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.sceneChanged),t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(n){if(void 0===n&&(n=-1),!e.paused){if(t.Time.update(n,-1!=n),null!=this._scene){for(var i=this._globalManagers.length-1;i>=0;i--)this._globalManagers[i].enabled&&this._globalManagers[i].update();null!=this._sceneTransition&&(null==this._sceneTransition||this._sceneTransition._loadsNewScene&&!this._sceneTransition._isNewSceneLoaded)||this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.startDebugDraw(),this.draw()}},e.prototype.draw=function(){null!=this._sceneTransition&&this._sceneTransition.preRender(),null==this._sceneTransition||this._sceneTransition.hasPreviousSceneRender||(null!=this._scene&&e.startCoroutine(this._sceneTransition.onBeginTransition()),this._sceneTransition.render())},e.paused=!1,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){var e;!function(t){t[t.error=0]="error",t[t.warn=1]="warn",t[t.log=2]="log",t[t.info=3]="info",t[t.trace=4]="trace"}(e=t.LogType||(t.LogType={}));var n=function(){function n(){}return n.warnIf=function(t,n){for(var i=[],r=2;r=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t0?new e(this.x/t,this.y/t):new e(0,1)},e.prototype.normalizeEqual=function(){var t=this.distance();return t>0?(this.setTo(this.x/t,this.y/t),this):(this.setTo(0,1),this)},e.prototype.magnitude=function(){return this.distance()},e.prototype.distance=function(t){return t||(t=e.zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},e.prototype.getLength=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.prototype.angleBetween=function(e,n){var i=e.sub(this),r=n.sub(this);return t.Vector2Ext.angle(i,r)},e.prototype.getDistance=function(t){return Math.sqrt(this.getDistanceSquared(t))},e.prototype.getDistanceSquared=function(t){var e=t.x-this.x,n=t.y-this.y;return e*e+n*n},e.prototype.isBetween=function(t,e){var n=e.sub(t).cross(this.sub(t));return Math.abs(n)=0&&this.dot(t.sub(e))>=0},e.prototype.cross=function(t){return this.x*t.y-this.y*t.x},e.prototype.getAngle=function(){return Math.atan2(this.y,this.x)},e.prototype.equals=function(t,e){return void 0===e&&(e=.001),Math.abs(this.x-t.x)<=e&&Math.abs(this.y-t.y)<=e},e.prototype.isValid=function(){return t.MathHelper.isValid(this.x)&&t.MathHelper.isValid(this.y)},e.min=function(t,n){return new e(t.xn.x?t.x:n.x,t.y>n.y?t.y:n.y)},e.hermite=function(n,i,r,o,s){return new e(t.MathHelper.hermite(n.x,i.x,r.x,o.x,s),t.MathHelper.hermite(n.y,i.y,r.y,o.y,s))},e.unsignedAngle=function(e,n,i){void 0===i&&(i=!0),e.normalizeEqual(),n.normalizeEqual();var r=Math.acos(t.MathHelper.clamp(e.dot(n),-1,1))*t.MathHelper.Rad2Deg;return i?Math.round(r):r},e.fromAngle=function(t,n){return void 0===n&&(n=1),new e(n*Math.cos(t),n*Math.sin(t))},e.prototype.clone=function(){return new e(this.x,this.y)},e.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(){this._sceneComponents=[],this.entities=new t.EntityList(this),this.entityProcessors=new t.EntityProcessorList,this.identifierPool=new t.IdentifierPool,this.initialize()}return e.prototype.initialize=function(){},e.prototype.onStart=function(){},e.prototype.unload=function(){},e.prototype.begin=function(){t.Physics.reset(),null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.prototype.end=function(){this._didSceneBegin=!1,this.entities.removeAllEntities();for(var e=0;e=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate()},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=this.position.sub(e).normalize();this.rotation=n*Math.acos(i.dot(t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(n.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,null!=this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this.setDirty(n.scaleDirty),this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(n.scaleDirty),this},i.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},i.prototype.updateTransform=function(){this.hierarchyDirty!=n.clean&&(null!=this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y,this._translationMatrix),this._localPositionDirty=!1),this._localRotationDirty&&(t.Matrix2D.createRotation(this._localRotation,this._rotationMatrix),this._localRotationDirty=!1),this._localScaleDirty&&(t.Matrix2D.createScale(this._localScale.x,this._localScale.y,this._scaleMatrix),this._localScaleDirty=!1),t.Matrix2D.multiply(this._scaleMatrix,this._rotationMatrix,this._localTransform),t.Matrix2D.multiply(this._localTransform,this._translationMatrix,this._localTransform),null==this.parent&&(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),null!=this.parent&&(t.Matrix2D.multiply(this._localTransform,this.parent._worldTransform,this._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=this.parent._scale.multiply(this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=n.clean)},i.prototype.setDirty=function(t){if(0==(this.hierarchyDirty&t)){switch(this.hierarchyDirty|=t,t){case n.positionDirty:this.entity.onTransformChanged(e.position);break;case n.rotationDirty:this.entity.onTransformChanged(e.rotation);break;case n.scaleDirty:this.entity.onTransformChanged(e.scale)}for(var i=0;i1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},n.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},n.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},n.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},n.prototype.setVelocity=function(t){return this.velocity=t,this},n.prototype.addImpulse=function(e){this.isImmovable||this.velocity.addEqual(e.scale(this._inverseMass*(t.Time.deltaTime*t.Time.deltaTime)*1e5))},n.prototype.onAddedToEntity=function(){this._collider=null;for(var e=0;e0)for(var i=0;i0&&(o=t.Vector2.zero);var a=this._friction;return s.lengthSquared()0&&this.collisionState.wasGroundedLastFrame&&(t=this.handleVerticalSlope(t)),0!==t.x&&(t=this.moveHorizontally(t)),0!==t.y&&(t=this.moveVertically(t)),this._player.setPosition(this._player.position.x+t.x,this._player.position.y+t.y),e>0&&(this.velocity.x=t.x/e,this.velocity.y=t.y/e),!this.collisionState.wasGroundedLastFrame&&this.collisionState.below&&(this.collisionState.becameGroundedThisFrame=!0),this._isGoingUpSlope&&(this.velocity.y=0),this._isWarpingToGround||this._triggerHelper.update();for(var n=0;n0&&(this.ignoreOneWayPlatformsTime-=e)},i.prototype.warpToGrounded=function(e){void 0===e&&(e=1e3),this.ignoreOneWayPlatformsTime=0,this._isWarpingToGround=!0;var n=0;do{if(n+=1,this.move(new t.Vector2(0,1),.02),n>e)break}while(!this.isGrounded);this._isWarpingToGround=!1},i.prototype.recalculateDistanceBetweenRays=function(){var t=this._collider.height*Math.abs(this._player.scale.y)-2*this._skinWidth;this._verticalDistanceBetweenRays=t/(this.totalHorizontalRays-1);var e=this._collider.width*Math.abs(this._player.scale.x)-2*this._skinWidth;this._horizontalDistanceBetweenRays=e/(this.totalVerticalRays-1)},i.prototype.primeRaycastOrigins=function(){var e=this._collider.bounds;this._raycastOrigins.topLeft=new t.Vector2(e.x+this._skinWidth,e.y+this._skinWidth),this._raycastOrigins.bottomRight=new t.Vector2(e.right-this._skinWidth,e.bottom-this._skinWidth),this._raycastOrigins.bottomLeft=new t.Vector2(e.x+this._skinWidth,e.bottom-this._skinWidth)},i.prototype.moveHorizontally=function(e){for(var n=e.x>0,i=Math.abs(e.x)+this._skinWidth*this.rayOriginSkinMutiplier,r=n?t.Vector2.right:t.Vector2.left,o=this._raycastOrigins.bottomLeft.y,s=n?this._raycastOrigins.bottomRight.x-this._skinWidth*(this.rayOriginSkinMutiplier-1):this._raycastOrigins.bottomLeft.x+this._skinWidth*(this.rayOriginSkinMutiplier-1),a=0;a0)&&(a&=~this.oneWayPlatformMask);for(var u=0;uthis.jumpingThreshold){var i=this.slopeSpeedMultiplier?this.slopeSpeedMultiplier.lerp(n):1;e.x*=i,e.y=Math.abs(Math.tan(n*t.MathHelper.Deg2Rad)*e.x);var r=e.x>0,o=r?this._raycastOrigins.bottomRight:this._raycastOrigins.bottomLeft,s=null;(s=this.supportSlopedOneWayPlatforms&&this.collisionState.wasGroundedLastFrame?t.Physics.linecast(o,o.add(e),this.platformMask,this.ignoredColliders):t.Physics.linecast(o,o.add(e),this.platformMask&~this.oneWayPlatformMask,this.ignoredColliders)).collider&&(e.x=s.point.x-o.x,e.y=s.point.y-o.y,r?e.x-=this._skinWidth:e.x+=this._skinWidth),this._isGoingUpSlope=!0,this.collisionState.below=!0}}else e.x=0;return!0},i}();t.CharacterController=i}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,n){if(e.components._components.length>0)for(var i=0;i0)for(var r=0;r0)for(r=0;r0)for(r=0;r0)for(var c=0;c0)for(var r=0;r=this.delay)},n.prototype.offerDelay=function(t){this.running?this.delay=Math.min(this.delay,t):(this.running=!0,this.delay=t)},n.prototype.getInitialTimeDelay=function(){return this.delay},n.prototype.getRemainingTimeUntilProcessing=function(){return this.running?this.delay-this.acc:0},n.prototype.isRunning=function(){return this.running},n.prototype.stop=function(){this.running=!1,this.acc=0},n}(t.EntitySystem);t.DelayedIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.enabled=!0,n}return __extends(e,t),e.prototype.lateProcessEntity=function(t){},e.prototype.process=function(t){if(0!==t.length)for(var e=0,n=t.length;e=this.interval&&(this.intervalRemainder=this.acc-this.interval,this.acc=0,!0)},n.prototype.getIntervalDelta=function(){return this.interval+this.intervalRemainder},n}(t.EntitySystem);t.IntervalSystem=e}(es||(es={})),function(t){var e=function(t){function e(e,n){return t.call(this,e,n)||this}return __extends(e,t),e.prototype.process=function(t){var e=this;t.forEach(function(t){return e.processEntity(t)})},e}(t.IntervalSystem);t.IntervalIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onChanged=function(t){},e.prototype.process=function(t){this.begin(),this.end()},e}(t.EntitySystem);t.PassiveSystem=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onChanged=function(t){},e.prototype.process=function(t){this.begin(),this.processSystem(),this.end()},e}(t.EntitySystem);t.ProcessingSystem=e}(es||(es={})),function(t){var e=function(){function t(){this._bit={}}return t.prototype.set=function(t,e){this._bit[t]=e},t.prototype.get=function(t){var e=this._bit[t];return null==e?0:e},t}();t.Bits=e}(es||(es={})),function(t){var e=function(){function e(t){this._components=[],this._updatableComponents=[],this._componentsToAdd={},this._componentsToRemove={},this._componentsToAddList=[],this._componentsToRemoveList=[],this._tempBufferList=[],this.componentsByType=new Map,this.componentsToAddByType=new Map,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[t.id]=t,this._componentsToAddList.push(t),this.addComponentsToAddByType(t)},e.prototype.remove=function(t){if(this._componentsToAdd[t.id]){var e=this._componentsToAddList.findIndex(function(e){return e.id==t.id});return-1!=e&&this._componentsToAddList.splice(e,1),delete this._componentsToAdd[t.id],void this.removeComponentsToAddByType(t)}this._componentsToRemove[t.id]=t,this._componentsToRemoveList.push(t)},e.prototype.removeAllComponents=function(){if(this._components.length>0)for(var t=0,e=this._components.length;t0)for(var e=0,n=this._components.length;e0)for(var e=0,n=this._components.length;e0){for(var e=function(t,e){var i=n._componentsToRemoveList[t];n.handleRemove(i);var r=n._components.findIndex(function(t){return t.id==i.id});-1!=r&&n._components.splice(r,1),n.removeComponentsByType(i)},n=this,i=0,r=this._componentsToRemoveList.length;i0){for(i=0,r=this._componentsToAddList.length;i0){for(i=0,r=this._tempBufferList.length;i0){var n=this._updatableComponents.findIndex(function(t){return t.id==e.id});-1!=n&&this._updatableComponents.splice(n,1)}this.decreaseBits(e),this._entity.scene.entityProcessors.onComponentRemoved(this._entity),e.onRemovedFromEntity(),e.entity=null},e.prototype.removeComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsByType.set(t.TypeUtils.getType(e),n)},e.prototype.removeComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsToAddByType.set(t.TypeUtils.getType(e),n)},e.prototype.getComponent=function(t,e){var n=this.componentsByType.get(t);if(n&&n.length>0)return n[0];if(!e){var i=this.componentsToAddByType.get(t);if(i&&i.length>0)return i[0]}return null},e.prototype.getComponents=function(t,e){e||(e=[]);var n=this.componentsByType.get(t);n&&(e=e.concat(n));var i=this.componentsToAddByType.get(t);return i&&(e=e.concat(i)),e},e.prototype.update=function(){if(this.updateLists(),this._updatableComponents.length>0)for(var t=0,e=this._updatableComponents.length;t0)for(var e=0,n=this._components.length;e0)for(e=0,n=this._componentsToAddList.length;e0)for(var t=0,e=this._components.length;t0)for(var t=0,e=this._components.length;t0){for(var t=function(t,n){var i=e._entitiesToRemoveList[t];e.removeFromTagList(i);var r=e._entities.findIndex(function(t){return t.id==i.id});-1!=r&&e._entities.splice(r,1),i.onRemovedFromScene(),i.scene=null,e.scene.entityProcessors.onEntityRemoved(i)},e=this,n=0,i=this._entitiesToRemoveList.length;n0){for(n=0,i=this._entitiesToAddedList.length;n0)for(var e=0,n=this._entities.length;e0)for(e=0,n=this._entitiesToAddedList.length;e0)for(var e=0,n=this._entities.length;e0)try{for(var s=__values(r),a=s.next();!a.done;a=s.next()){var u=a.value;o.push(u)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return o},e.prototype.entityWithTag=function(t){var e,n,i=this.getTagList(t);if(i.size>0)try{for(var r=__values(i),o=r.next();!o.done;o=r.next()){return o.value}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return null},e.prototype.findComponentOfType=function(t){if(this._entities.length>0)for(var e=0,n=this._entities.length;e0)for(e=0;e0)for(var i=0,r=this._entities.length;i0)for(i=0,r=this._entitiesToAddedList.length;i0)for(var i=0,r=this._entities.length;i0)for(var s=0,a=t.length;s0)for(i=0,r=this._entitiesToAddedList.length;i0)for(s=0,a=t.length;s=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i0?this.ids.removeLast():this.nextAvailableId_++},e.prototype.checkIn=function(t){this.ids.add(t)},e}();t.IdentifierPool=e}(es||(es={})),function(t){var e=function(){function e(){this.allSet=[],this.exclusionSet=[],this.oneSet=[]}return e.empty=function(){return new e},e.prototype.getAllSet=function(){return this.allSet},e.prototype.getExclusionSet=function(){return this.exclusionSet},e.prototype.getOneSet=function(){return this.oneSet},e.prototype.isInterestedEntity=function(t){return this.isInterested(t.componentBits)},e.prototype.isInterested=function(e){if(0!==this.allSet.length)for(var n=0;n=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}();t.StringUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.update=function(t,e){var n=0;e?n=t:(-1==t&&(t=Date.now()),-1==this._lastTime&&(this._lastTime=t),n=(t-this._lastTime)/1e3),n>this.maxDeltaTime&&(n=this.maxDeltaTime),this.totalTime+=n,this.deltaTime=n*this.timeScale,this.unscaledDeltaTime=n,this.timeSinceSceneLoad+=n,this.frameCount++,this._lastTime=t},e.sceneChanged=function(){this.timeSinceSceneLoad=0},e.checkEvery=function(e){return t.MathHelper.toInt(this.timeSinceSceneLoad/e)>t.MathHelper.toInt((this.timeSinceSceneLoad-this.deltaTime)/e)},e.totalTime=0,e.unscaledDeltaTime=0,e.deltaTime=0,e.timeScale=1,e.maxDeltaTime=Number.MAX_VALUE,e.frameCount=0,e.timeSinceSceneLoad=0,e._lastTime=-1,e}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,u=Math.floor(a)+1;if(53==u){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"+(u>9?"":"0")+u)},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(),u=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(u="0"+u),n?s+e+a+e+u:a+e+u},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=1,n.range=this._points.length-4):(e=t.MathHelper.clamp01(e)*this._curveCount,n.range=t.MathHelper.toInt(e),e-=n.range,n.range*=3),n.time=e,n},e.prototype.setControlPoint=function(t,e){if(t%3==0){var n=e.sub(this._points[t]);t>0&&this._points[t-1].addEqual(n),t+1Math.PI?e-2*Math.PI:e},e.isPowerOfTwo=function(t){return!(t<=0)&&0==(t&t-1)},e.lerp=function(t,n,i){return t+(n-t)*e.clamp01(i)},e.betterLerp=function(t,n,i,r){return Math.abs(t-n)180&&(i-=360),t+i*this.clamp01(n)},e.lerpAngleRadians=function(t,e,n){var i=this.repeat(e-t,2*Math.PI);return i>Math.PI&&(i-=2*Math.PI),t+i*this.clamp01(n)},e.pingPong=function(t,e){return t=this.repeat(t,2*e),e-Math.abs(t-e)},e.signThreshold=function(t,e){return Math.abs(t)>=e?Math.sign(t):0},e.inverseLerp=function(t,e,n){var i=e-t;return 0===i?0:(n-t)/i},e.lerpPrecise=function(t,e,n){return(1-n)*t+e*n},e.clamp=function(t,e,n){return tn?n:t},e.snap=function(t,e){return Math.round(t/e)*e},e.isEven=function(t){return t%2==0},e.isOdd=function(t){return t%2!=0},e.roundWithRoundedAmount=function(t,e){var n=Math.round(t);return e.value=t-n*Math.round(t/n),n},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.angleToVector=function(e,n){var i=Math.cos(e)*n,r=Math.sin(e)*n;return new t.Vector2(i,r)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.decrementWithWrap=function(t,e){return--t<0?e-1:t},e.hypotenuse=function(t,e){var n=t*t+e*e;return Math.sqrt(n)},e.closestPowerOfTwoGreaterThan=function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,(t|=t>>16)+1},e.roundToNearest=function(t,e){var n=t/e;return Math.round(n)*e},e.withinEpsilon=function(t,e){return void 0===e&&(e=this.Epsilon),Math.abs(t)180&&(n-=360),n},e.between=function(t,e,n){return t>=e&&t<=n},e.deltaAngleRadians=function(t,e){var n=this.repeat(e-t,2*Math.PI);return n>Math.PI&&(n-=2*Math.PI),n},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.floorToInt=function(t){var e=Math.floor(t);return this.toInt(e)},e.rotateAround=function(e,n){var i=t.Time.totalTime*n,r=Math.cos(i),o=Math.sin(i),s=e.x+r,a=e.y+o;return new t.Vector2(s,a)},e.rotateAround2=function(e,n,i){var r=n.x,o=n.y,s=e.x,a=e.y,u=this.toRadians(i),h=Math.cos(u),c=Math.sin(u),l=h*(s-r)-c*(a-o)+r,p=c*(s-r)+h*(a-o)+o;return new t.Vector2(l,p)},e.pointOnCircle=function(e,n,i){var r=this.toRadians(i),o=Math.cos(r)*n,s=Math.sin(r)*n,a=o+e.x,u=s+e.y;return new t.Vector2(a,u)},e.pointOnCircleRadians=function(e,n,i){var r=Math.cos(i)*n,o=Math.sin(i)*n,s=r+e.x,a=o+e.y;return new t.Vector2(s,a)},e.lissajou=function(e,n,i,r,o){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=0);var s=Math.sin(t.Time.totalTime*e+o)*i,a=Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(s,a)},e.lissajouDamped=function(e,n,i,r,o,s,a){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=.5),void 0===s&&(s=0),void 0===a&&(a=5);var u=this.pingPong(t.Time.totalTime,a),h=Math.pow(Math.E,-s*u),c=h*Math.sin(t.Time.totalTime*e+o)*i,l=h*Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(c,l)},e.hermite=function(t,e,n,i,r){if(0===r)return t;if(1===r)return n;return(2*t-2*n+i+e)*(r*r*r)+(3*n-3*t-2*e-i)*(r*r)+e*r+t},e.isValid=function(t){return!Number.isNaN(t)&&t!==1/0},e.smoothDamp=function(t,n,i,r,o,s){var a=2/(r=Math.max(1e-4,r)),u=a*s,h=1/(1+.48*u+.235*u*u),c=o*r,l=t-n,p=(i+a*(l=e.clamp(l,-c,c)))*s;i=(i-a*p)*h;var f=(n=t-l)+(l+p)*h;return t>n==f>n&&(i=((f=n)-n)/s),{value:f,currentVelocity:i}},e.smoothDampVector=function(e,n,i,r,o,s){var a=t.Vector2.zero,u=this.smoothDamp(e.x,n.x,i.x,r,o,s);a.x=u.value,i.x=u.currentVelocity;var h=this.smoothDamp(e.y,n.y,i.y,r,o,s);return a.y=h.value,i.y=h.currentVelocity,a},e.mapMinMax=function(t,n,i,r,o){return r+(e.clamp(t,n,i)-n)*(o-r)/(i-n)},e.fromAngle=function(e){return new t.Vector2(Math.cos(e),Math.sin(e)).normalizeEqual()},e.toInt=function(t){return t>0?Math.floor(t):Math.ceil(t)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e.PiOver2=Math.PI/2,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function t(t,e,n,i,r,o,s,a,u,h,c,l,p,f,d,m){this.m11=t,this.m12=e,this.m13=n,this.m14=i,this.m21=r,this.m22=o,this.m23=s,this.m24=a,this.m31=u,this.m32=h,this.m33=c,this.m34=l,this.m41=p,this.m42=f,this.m43=d,this.m44=m}return Object.defineProperty(t,"Identity",{get:function(){return this.identity},enumerable:!0,configurable:!0}),t.createOrthographicOffCenter=function(e,n,i,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(n-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-i),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+n)/(e-n),a.m42=(r+i)/(i-r),a.m43=o/(o-s),a.m44=1},t.createTranslation=function(t,e){e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=t.x,e.m42=t.y,e.m43=0,e.m44=1},t.createRotationZ=function(e,n){n=t.Identity;var i=Math.cos(e),r=Math.sin(e);n.m11=i,n.m12=r,n.m21=-r,n.m22=i},t.multiply=function(e,n,i){void 0===i&&(i=new t);var r=e.m11*n.m11+e.m12*n.m21+e.m13*n.m31+e.m14*n.m41,o=e.m11*n.m12+e.m12*n.m22+e.m13*n.m32+e.m14*n.m42,s=e.m11*n.m13+e.m12*n.m23+e.m13*n.m33+e.m14*n.m43,a=e.m11*n.m14+e.m12*n.m24+e.m13*n.m34+e.m14*n.m44,u=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,c=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=u,i.m22=h,i.m23=c,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=m,i.m41=y,i.m42=g,i.m43=_,i.m44=v},t.identity=new t(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t}();t.Matrix=e}(es||(es={})),function(t){var e=function(){function e(){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0}return Object.defineProperty(e,"identity",{get:function(){return(new e).setIdentity()},enumerable:!0,configurable:!0}),e.prototype.setIdentity=function(){return this.setValues(1,0,0,1,0,0)},e.prototype.setValues=function(t,e,n,i,r,o){return this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=r,this.m32=o,this},Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m22=t.y},enumerable:!0,configurable:!0}),e.createRotation=function(t,e){e.setIdentity();var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-1*i,e.m22=n},e.createRotationOut=function(t,e){var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-i,e.m22=n},e.createScale=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createScaleOut=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createTranslation=function(t,e,n){return n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=t,n.m32=e,n},e.createTranslationOut=function(t,e){e.m11=1,e.m12=0,e.m21=0,e.m22=1,e.m31=t.x,e.m32=t.y},e.invert=function(t){var e=1/t.determinant(),n=this.identity;return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.multiply=function(t,e,n){var i=t.m11*e.m11+t.m12*e.m21,r=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,s=t.m21*e.m12+t.m22*e.m22,a=t.m31*e.m11+t.m32*e.m21+e.m31,u=t.m31*e.m12+t.m32*e.m22+e.m32;n.m11=i,n.m12=r,n.m21=o,n.m22=s,n.m31=a,n.m32=u},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,n){return t.m11=t.m11+(e.m11-t.m11)*n,t.m12=t.m12+(e.m12-t.m12)*n,t.m21=t.m21+(e.m21-t.m21)*n,t.m22=t.m22+(e.m22-t.m22)*n,t.m31=t.m31+(e.m31-t.m31)*n,t.m32=t.m32+(e.m32-t.m32)*n,t},e.transpose=function(t){var e=this.identity;return e.m11=t.m11,e.m12=t.m21,e.m21=t.m12,e.m22=t.m22,e.m31=0,e.m32=0,e},e.prototype.mutiplyTranslation=function(n,i){var r=new e;return e.createTranslation(n,i,r),t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var n=new t.Matrix;return n.m11=e.m11,n.m12=e.m12,n.m13=0,n.m14=0,n.m21=e.m21,n.m22=e.m22,n.m23=0,n.m24=0,n.m31=0,n.m32=0,n.m33=1,n.m34=0,n.m41=e.m31,n.m42=e.m32,n.m43=0,n.m44=1,n},e.prototype.toString=function(){return"{m11:"+this.m11+" m12:"+this.m12+" m21:"+this.m21+" m22:"+this.m22+" m31:"+this.m31+" m32:"+this.m32+"}"},e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(){function e(){}return e.add=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11+n.m11,i.m12=e.m12+n.m12,i.m21=e.m21+n.m21,i.m22=e.m22+n.m22,i.m31=e.m31+n.m31,i.m32=e.m32+n.m32,i},e.divide=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11/n.m11,i.m12=e.m12/n.m12,i.m21=e.m21/n.m21,i.m22=e.m22/n.m22,i.m31=e.m31/n.m31,i.m32=e.m32/n.m32,i},e.mutiply=function(e,n){var i=t.Matrix2D.identity;if(n instanceof t.Matrix2D){var r=e.m11*n.m11+e.m12*n.m21,o=n.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,u=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=u,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(e,n,i,r){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),void 0===r&&(r=0),this.x=0,this.y=0,this.width=0,this.height=0,this._tempMat=new t.Matrix2D,this._transformMat=new t.Matrix2D,this.x=e,this.y=n,this.width=i,this.height=r}return Object.defineProperty(e,"empty",{get:function(){return new e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"maxRect",{get:function(){return new e(Number.MIN_VALUE/2,Number.MIN_VALUE/2,Number.MAX_VALUE,Number.MAX_VALUE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.isEmpty=function(){return 0==this.width&&0==this.height&&0==this.x&&0==this.y},Object.defineProperty(e.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),e.fromMinMax=function(t,n,i,r){return new e(t,n,i-t,r-n)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;oi&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return i}else{var o=1/t.direction.x,s=(this.x-t.start.x)*o,a=(this.x+this.width-t.start.x)*o;if(s>a&&(a=(e=__read([s,a],2))[0],s=e[1]),i.distance=Math.max(s,i.distance),r=Math.min(a,r),i.distance>r)return i}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return i}else{var u=1/t.direction.y,h=(this.y-t.start.y)*u,c=(this.y+this.height-t.start.y)*u;if(h>c&&(c=(n=__read([h,c],2))[0],h=n[1]),i.distance=Math.max(h,i.distance),r=Math.min(c,r),i.distance>r)return i}return i.intersected=!0,i},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(c)>=p)return t.Vector2.zero;var f=h>0?l-h:-l-h,d=c>0?p-c:-p-c;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return Math.trunc(this.x)^Math.trunc(this.y)^Math.trunc(this.width)^Math.trunc(this.height)},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.PairSet,this._previousTriggerIntersections=new t.PairSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){var e=[],n=this.getColliders();if(n.length>0)for(var i=0;i=t.Collider.lateSortOrder?e.push(u):this.notifyTriggerListeners(u,!0)),this._activeTriggerIntersections.add(u)}}if(e.length>0)for(i=0;i0)for(var n=0;n0)for(var i=0;i0)for(var o=0;o1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},n.lineToLineIntersection=function(e,n,i,r,o){void 0===o&&(o=t.Vector2.zero),o.x=0,o.y=0;var s=n.sub(e),a=r.sub(i),u=s.x*a.y-s.y*a.x;if(0==u)return!1;var h=i.sub(e),c=(h.x*a.y-h.y*a.x)/u;if(c<0||c>1)return!1;var l=(h.x*s.y-h.y*s.x)/u;if(l<0||l>1)return!1;var p=e.add(s.scale(c));return o.x=p.x,o.y=p.y,!0},n.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scale(o))},n.circleToCircle=function(e,n,i,r){return t.Vector2.sqrDistance(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.sqrDistance(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setAllValues=function(t,e,n,i,r){this.collider=t,this.fraction=e,this.distance=n,this.point=i,this.normal=r},e.prototype.setValues=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.clone=function(){var t=new e;return t.setAllValues(this.collider,this.fraction,this.distance,this.point,this.normal),t},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset(),this._colliderArray[0]=null},e.clear=function(){this._spatialHash.clear()},e.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){return void 0===i&&(i=this.allLayers),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var n=t.bounds;return this._spatialHash.aabbBroadphase(n,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,n,i,r){void 0===r&&(r=e.allLayers);var o=t.bounds.getSweptBroadphaseBounds(n,i);return this._spatialHash.aabbBroadphase(o,t,r)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.linecast=function(t,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._hitArray[0].reset(),e.linecastAll(t,n,this._hitArray,i,r),this._hitArray[0]},e.linecastAll=function(t,e,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._spatialHash.linecast(t,e,n,i,r)},e.overlapRectangle=function(t,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,n),this._colliderArray[0]},e.overlapRectangleAll=function(t,n,i){return void 0===i&&(i=e.allLayers),0==n.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,n,i)},e.gravity=new t.Vector2(0,-300),e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e.debugRender=!1,e._hitArray=[new t.RaycastHit],e._colliderArray=[null],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(t,e){this._start=t.clone(),this._end=e.clone(),this._direction=this._end.sub(this._start)}return Object.defineProperty(t.prototype,"start",{get:function(){return this._start},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"end",{get:function(){return this._end},enumerable:!0,configurable:!0}),t}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestBox=new t.Box(0,0),this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds.clone();e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(e){for(var n=e.registeredPhysicsBounds.clone(),i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom),o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){var a=this.cellAtPosition(o,s);t.Insist.isNotNull(a,"从不存在碰撞器的单元格中移除碰撞器: ["+e+"]"),null!=a&&new t.List(a).remove(e)}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.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 u=this.cellAtPosition(s,a);if(u&&u.length>0)for(var h=0;h0)for(var u=0;u=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;ri&&(i=o,n=r)}return t[n]},n.getClosestPointOnPolygonToPoint=function(e,n){for(var i={distanceSquared:Number.MAX_VALUE,edgeNormal:t.Vector2.zero,closestPoint:t.Vector2.zero},r=0,o=0;ot.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;oi&&(n.copyFrom(r),i=o),r.setTo(-this.width/2,-this.height/2),(o=r.dot(e))>i&&(n.copyFrom(r),i=o),r.setTo(this.width/2,-this.height/2),(o=r.dot(e))>i&&(n.copyFrom(r),i=o),n},n}(t.Polygon);t.Box=e}(es||(es={})),function(t){var e=function(e){function n(t){var n=e.call(this)||this;return n.radius=t,n._originalRadius=t,n}return __extends(n,e),n.prototype.recalculateBounds=function(e){if(this.center=e.localOffset,e.shouldColliderScaleAndRotateWithTransform){var n=e.entity.transform.scale,i=1===n.x&&1===n.y,r=Math.max(n.x,n.y);if(this.radius=this._originalRadius*r,0!==e.entity.transform.rotation){var o=Math.atan2(e.localOffset.y,e.localOffset.x)*t.MathHelper.Rad2Deg,s=i?e._localOffsetLength:e.localOffset.multiply(e.entity.transform.scale).magnitude();this.center=t.MathHelper.pointOnCircle(t.Vector2.zero,s,e.entity.transform.rotation+o)}}this.position=e.transform.position.add(this.center),this.bounds=new t.Rectangle(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},n.prototype.overlaps=function(e){var i=new t.Out;if(e instanceof t.Box&&e.isUnrotated)return t.Collisions.rectToCircle(e.bounds,this.position,this.radius);if(e instanceof n)return t.Collisions.circleToCircle(this.position,this.radius,e.position,e.radius);if(e instanceof t.Polygon)return t.ShapeCollisionsCircle.circleToPolygon(this,e,i);throw new Error("overlaps of circle to "+e+" are not supported")},n.prototype.collidesWithShape=function(e,i){if(e instanceof t.Box&&e.isUnrotated)return t.ShapeCollisionsCircle.circleToBox(this,e,i);if(e instanceof n)return t.ShapeCollisionsCircle.circleToCircle(this,e,i);if(e instanceof t.Polygon)return t.ShapeCollisionsCircle.circleToPolygon(this,e,i);throw new Error("Collisions of Circle to "+e+" are not supported")},n.prototype.collidesWithLine=function(e,n,i){return t.ShapeCollisionsLine.lineToCircle(e,n,this,i)},n.prototype.getPointAlongEdge=function(e){return new t.Vector2(this.position.x+this.radius*Math.cos(e),this.position.y+this.radius*Math.sin(e))},n.prototype.containsPoint=function(t){return t.sub(this.position).lengthSquared()<=this.radius*this.radius},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.pointToCircle(e,this,n)},n}(t.Shape);t.Circle=e}(es||(es={})),function(t){var e=function(){function e(){this.normal=t.Vector2.zero,this.minimumTranslationVector=t.Vector2.zero,this.point=t.Vector2.zero}return e.prototype.reset=function(){this.collider=null,this.normal.setTo(0,0),this.minimumTranslationVector.setTo(0,0),this.point&&this.point.setTo(0,0)},e.prototype.cloneTo=function(e){e.collider=this.collider,e.normal.setTo(this.normal.x,this.normal.y),e.minimumTranslationVector.setTo(this.minimumTranslationVector.x,this.minimumTranslationVector.y),this.point&&(e.point||(e.point=new t.Vector2(0,0)),e.point.setTo(this.point.x,this.point.y))},e.prototype.removeHorizontalTranslation=function(e){if(Math.sign(this.normal.x)!==Math.sign(e.x)||0===e.x&&0!==this.normal.x){var n=this.minimumTranslationVector.magnitude()/this.normal.y;1!=Math.abs(this.normal.x)&&Math.abs(n)this.end.dot(t)?this.start:this.end},e.prototype.getClosestPoint=function(t,e){var n=e.copyFrom(this.end).sub(this.start),i=t.sub(this.start).dot(n)/n.lengthSquared();return i<0?e.copyFrom(this.start):i>1?e.copyFrom(this.end):e.copyFrom(n).multiplyScaler(i).add(this.start)},e}();t.Line=e}(es||(es={})),function(t){var e=function(){function t(){this.min=Number.MAX_VALUE,this.max=-Number.MAX_VALUE}return t.prototype.project=function(t,e){for(var n=e.points,i=t.dot(n[0]),r=i,o=1;or&&(r=a)}this.min=i,this.max=r},t.prototype.overlap=function(t){return this.max>=t.min&&t.max>=this.min},t.prototype.getOverlap=function(t){return Math.min(this.max,t.max)-Math.max(this.min,t.min)},t}();t.Projection=e}(es||(es={})),function(t){var e=function(){function e(){}return e.intersectMovingCircleBox=function(e,n,i,r){var o=n.bounds;o.inflate(e.radius,e.radius);var s=new t.Ray2D(e.position.sub(i),e.position),a=o.rayIntersects(s);if(!a.intersected&&a.distance>1)return!1;var u,h=s.start.add(s.direction.scale(r)),c=0;h.xn.bounds.right&&(c|=1),h.yn.bounds.bottom&&(c|=2);var l=u+c;return 3==l&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,n){var i=t.Vector2.zero;return i.x=0==(1&n)?e.right:e.left,i.y=0==(1&n)?e.bottom:e.top,i},e.testCircleBox=function(t,e,n){var i=e.bounds.getClosestPointOnRectangleToPoint(t.position).sub(t.position);return i.dot(i)<=t.radius*t.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(e){function n(t,n,i,r){var o=e.call(this)||this;return o.center=t,o.radius=n,o.startAngle=i,o.endAngle=r,o.angle=r-i,o.radiusSquared=n*n,o.points=o.getPoints(),o.calculateProperties(),o}return __extends(n,e),Object.defineProperty(n.prototype,"sectorAngle",{get:function(){var t=this.endAngle-this.startAngle;return t<0&&(t+=360),t},enumerable:!0,configurable:!0}),n.prototype.getCentroid=function(){var e=(Math.cos(this.startAngle)+Math.cos(this.endAngle))*this.radius/3,n=(Math.sin(this.startAngle)+Math.sin(this.endAngle))*this.radius/3;return new t.Vector2(e+this.center.x,n+this.center.y)},n.prototype.getAngle=function(){return this.startAngle},n.prototype.recalculateBounds=function(e){var n=this.center.add(e.localOffset),i=n.x-this.radius,r=n.y-this.radius,o=2*this.radius,s=2*this.radius,a=new t.Rectangle(i,r,o,s);this.bounds=a,this.center=n},n.prototype.overlaps=function(e){var n=new t.Out;if(e instanceof t.Polygon)return t.ShapeCollisionSector.sectorToPolygon(this,e,n);if(e instanceof t.Circle)return!!t.ShapeCollisionSector.sectorToCircle(this,e,n)&&(n.value.invertResult(),!0);throw new Error("overlaps of Sector to "+e+" are not supported")},n.prototype.collidesWithShape=function(e,n){if(e instanceof t.Box)return t.ShapeCollisionSector.sectorToBox(this,e,n);if(e instanceof t.Polygon)return t.ShapeCollisionSector.sectorToPolygon(this,e,n);if(e instanceof t.Circle)return t.ShapeCollisionSector.sectorToCircle(this,e,n);throw new Error("overlaps of Polygon to "+e+" are not supported")},n.prototype.collidesWithLine=function(e,n,i){var r=e.sub(this.center),o=n.sub(this.center),s=r.getAngle(),a=o.getAngle()-s;if(a>Math.PI?a-=2*Math.PI:a<-Math.PI&&(a+=2*Math.PI),a>=this.startAngle&&a<=this.endAngle){var u=r.getLength(),h=this.startAngle-s,c=u*Math.cos(h),l=u*Math.sin(h),p=new t.Vector2(c,l);if(p.isBetween(e,n)){var f=p.sub(e).getLength(),d=f/e.getDistance(n),m=p.sub(this.center).normalize(),y=p.add(this.center),g=new t.RaycastHit;return g.setValues(d,f,y,m),i.value=g,!0}}return!1},n.prototype.containsPoint=function(t){var e=t.sub(this.center);if(e.lengthSquared()>this.radiusSquared)return!1;var n=e.getAngle(),i=this.startAngle,r=(this.angle,n-i);return r<0&&(r+=2*Math.PI),!(r>this.angle)},n.prototype.pointCollidesWithShape=function(e,n){return this.containsPoint(e)?(n&&(n.value=new t.CollisionResult,n.value.normal=e.sub(this.center).normalize(),n.value.minimumTranslationVector=n.value.normal.scale(this.radius-e.sub(this.center).getLength()),n.value.point=e),!0):(n&&(n.value=null),!1)},n.prototype.getPoints=function(){for(var e=new Array(this.numberOfPoints),n=0;nn&&(n=o,i.copyFrom(this.points[r]))}return i},n}(t.Shape);t.Sector=e}(es||(es={})),function(t){var e=function(){function e(){}return e.sectorToPolygon=function(e,n,i){for(var r=n.points.length,o=!1,s=new t.Vector2,a=new t.Vector2,u=new t.Out,h=0;h0)return!1;i.value&&Math.abs(h)e.radius*e.radius&&!a)return!1;if(a)s=i.value.normal.scale(Math.sqrt(o.distanceSquared)-e.radius);else if(0===o.distanceSquared)s=i.value.normal.scale(e.radius);else{var u=Math.sqrt(o.distanceSquared);s=r.sub(o.closestPoint).scale((e.radius-u)/u*-1)}return i.value.minimumTranslationVector=s,i.value.point=o.closestPoint.add(n.position),!0},e.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scaleEqual(o))},e}();t.ShapeCollisionsCircle=e}(es||(es={})),function(t){var e=function(){function e(){}return e.lineToPoly=function(n,i,r,o){o.value=new t.RaycastHit;for(var s=t.Vector2.zero,a=t.Vector2.zero,u=Number.MAX_VALUE,h=!1,c=r.points.length-1,l=0;l1)return!1;var c=(u.x*o.y-u.y*o.x)/a;if(c<0||c>1)return!1;var l=t.add(o.scale(h));return r.x=l.x,r.y=l.y,!0},e.lineToCircle=function(e,n,i,r){r.value=new t.RaycastHit;var o=t.Vector2.distance(e,n),s=t.Vector2.divideScaler(n.sub(e),o),a=e.sub(i.position),u=a.dot(s),h=a.dot(a)-i.radius*i.radius;if(h>0&&u>0)return!1;var c=u*u-h;return!(c<0)&&(r.value.fraction=-u-Math.sqrt(c),r.value.fraction<0&&(r.value.fraction=0),r.value.point=e.add(s.scale(r.value.fraction)),r.value.distance=t.Vector2.distance(e,r.value.point),r.value.normal=r.value.point.sub(i.position).normalize(),r.value.fraction=r.value.distance/o,!0)},e}();t.ShapeCollisionsLine=e}(es||(es={})),function(t){var e=function(){function e(){}return e.pointToCircle=function(e,n,i){i.value=new t.CollisionResult;var r=t.Vector2.sqrDistance(e,n.position),o=1+n.radius;if(r0&&(o=!1),!o)return!1;(p=Math.abs(p))i.max&&(i.max=n);return i},e.intervalDistance=function(t,e,n,i){return t=0&&this._elapsedTime<=this._duration&&this.updateValue(),this._loopType!=e.none&&this._tweenState==n.complete&&0!=this._loops&&this.handleLooping(t);var i=this.calculateDeltaTime();return this.updateElapsedTime(i),this._tweenState==n.complete&&(this.handleCompletion(),!0)},i.prototype.calculateElapsedTimeExcess=function(){var t=0;return!this._isRunningInReverse&&this._elapsedTime>=this._duration?(t=this._elapsedTime-this._duration,this._elapsedTime=this._duration,this._tweenState=n.complete):this._isRunningInReverse&&this._elapsedTime<=0&&(t=0-this._elapsedTime,this._elapsedTime=0,this._tweenState=n.complete),t},i.prototype.calculateDeltaTime=function(){var e=this._isTimeScaleIndependent?t.Time.unscaledDeltaTime:t.Time.deltaTime;return e*=this._timeScale,this._isRunningInReverse&&(e=-e),e},i.prototype.updateElapsedTime=function(t){this._elapsedTime+=t,this._isRunningInReverse?(this._elapsedTime=Math.max(0,this._elapsedTime),this._elapsedTime=Math.min(this._elapsedTime,this._duration)):this._elapsedTime=Math.min(this._elapsedTime,this._duration)},i.prototype.handleCompletion=function(){this._completionHandler&&this._completionHandler(this),null!=this._nextTween&&(this._nextTween.start(),this._nextTween=null)},i.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._target=null,this._nextTween=null)},i.prototype.isRunning=function(){return this._tweenState==n.running},i.prototype.start=function(){this._isFromValueOverridden||(this._fromValue=this._target.getTweenedValue()),this._tweenState==n.complete&&(this._tweenState=n.running,t.TweenManager.addTween(this))},i.prototype.pause=function(){this._tweenState=n.paused},i.prototype.resume=function(){this._tweenState=n.running},i.prototype.stop=function(i){void 0===i&&(i=!1),this._tweenState=n.complete,i?(this._elapsedTime=this._isRunningInReverse?0:this._duration,this._loopType=e.none,this._loops=0):t.TweenManager.removeTween(this)},i.prototype.jumpToElapsedTime=function(e){this._elapsedTime=t.MathHelper.clamp(e,0,this._duration),this.updateValue()},i.prototype.reverseTween=function(){this._isRunningInReverse=!this._isRunningInReverse},i.prototype.waitForCompletion=function(){return __generator(this,function(t){switch(t.label){case 0:return this._tweenState==n.complete?[3,2]:[4,null];case 1:return t.sent(),[3,0];case 2:return[2]}})},i.prototype.getTargetObject=function(){return this._target.getTargetObject()},i.prototype.resetState=function(){this.context=null,this._completionHandler=this._loopCompleteHandler=null,this._isFromValueOverridden=!1,this._isTimeScaleIndependent=!1,this._tweenState=n.complete,this._isRelative=!1,this._easeType=t.TweenManager.defaultEaseType,null!=this._nextTween&&(this._nextTween.recycleSelf(),this._nextTween=null),this._delay=0,this._duration=0,this._timeScale=1,this._elapsedTime=0,this._loopType=e.none,this._delayBetweenLoops=0,this._loops=0,this._isRunningInReverse=!1},i.prototype.initialize=function(t,e,n){this.resetState(),this._target=t,this._toValue=e,this._duration=n},i.prototype.handleLooping=function(t){this._loops--,this._loopType==e.pingpong&&this.reverseTween(),this._loopType!=e.restartFromBeginning&&this._loops%2!=0||this._loopCompleteHandler&&this._completionHandler(this),0!=this._loops&&(this._tweenState=n.running,this._loopType==e.restartFromBeginning?this._elapsedTime=t-this._delayBetweenLoops:this._isRunningInReverse?this._elapsedTime+=this._delayBetweenLoops-t:this._elapsedTime=t-this._delayBetweenLoops,0==this._delayBetweenLoops&&t>0&&this.updateValue())},i}();t.Tween=i}(es||(es={})),function(t){var e=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheNumberTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue+=this._fromValue,this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheNumberTweens&&t.Pool.free(n,this)},n}(t.Tween);t.NumberTween=e;var n=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheVector2Tweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue.add(this._fromValue),this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheVector2Tweens&&t.Pool.free(n,this)},n}(t.Tween);t.Vector2Tween=n;var i=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheRectTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue=new t.Rectangle(this._toValue.x+this._fromValue.x,this._toValue.y+this._fromValue.y,this._toValue.width+this._fromValue.width,this._toValue.height+this._fromValue.height),this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheRectTweens&&t.Pool.free(n,this)},n}(t.Tween);t.RectangleTween=i}(es||(es={})),function(t){var e;!function(t){t[t.position=0]="position",t[t.localPosition=1]="localPosition",t[t.scale=2]="scale",t[t.localScale=3]="localScale",t[t.rotationDegrees=4]="rotationDegrees",t[t.localRotationDegrees=5]="localRotationDegrees"}(e=t.TransformTargetType||(t.TransformTargetType={}));var n=function(n){function i(){return null!==n&&n.apply(this,arguments)||this}return __extends(i,n),i.prototype.setTweenedValue=function(t){switch(this._targetType){case e.position:this._transform.position=t;break;case e.localPosition:this._transform.localPosition=t;break;case e.scale:this._transform.scale=t;break;case e.localScale:this._transform.localScale=t;break;case e.rotationDegrees:this._transform.rotationDegrees=t.x;case e.localRotationDegrees:this._transform.localRotationDegrees=t.x}},i.prototype.getTweenedValue=function(){switch(this._targetType){case e.position:return this._transform.position;case e.localPosition:return this._transform.localPosition;case e.scale:return this._transform.scale;case e.localScale:return this._transform.localScale;case e.rotationDegrees:return new t.Vector2(this._transform.rotationDegrees,this._transform.rotationDegrees);case e.localRotationDegrees:return new t.Vector2(this._transform.localRotationDegrees,0)}},i.prototype.getTargetObject=function(){return this._transform},i.prototype.setTargetAndType=function(t,e){this._transform=t,this._targetType=e},i.prototype.updateValue=function(){this._targetType!=e.rotationDegrees&&this._targetType!=e.localRotationDegrees||this._isRelative?this.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration)):this.setTweenedValue(t.Lerps.easeAngle(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},i.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._target=null,this._nextTween=null,this._transform=null,t.Pool.free(t.Vector2Tween,this))},i}(t.Vector2Tween);t.TransformVector2Tween=n}(es||(es={})),function(t){var e;!function(t){t[t.linear=0]="linear",t[t.sineIn=1]="sineIn",t[t.sineOut=2]="sineOut",t[t.sineInOut=3]="sineInOut",t[t.quadIn=4]="quadIn",t[t.quadOut=5]="quadOut",t[t.quadInOut=6]="quadInOut",t[t.quintIn=7]="quintIn",t[t.quintOut=8]="quintOut",t[t.quintInOut=9]="quintInOut",t[t.cubicIn=10]="cubicIn",t[t.cubicOut=11]="cubicOut",t[t.cubicInOut=12]="cubicInOut",t[t.quartIn=13]="quartIn",t[t.quartOut=14]="quartOut",t[t.quartInOut=15]="quartInOut",t[t.expoIn=16]="expoIn",t[t.expoOut=17]="expoOut",t[t.expoInOut=18]="expoInOut",t[t.circleIn=19]="circleIn",t[t.circleOut=20]="circleOut",t[t.circleInOut=21]="circleInOut",t[t.elasticIn=22]="elasticIn",t[t.elasticOut=23]="elasticOut",t[t.elasticInOut=24]="elasticInOut",t[t.punch=25]="punch",t[t.backIn=26]="backIn",t[t.backOut=27]="backOut",t[t.backInOut=28]="backInOut",t[t.bounceIn=29]="bounceIn",t[t.bounceOut=30]="bounceOut",t[t.bounceInOut=31]="bounceInOut"}(e=t.EaseType||(t.EaseType={}));var n=function(){function n(){}return n.oppositeEaseType=function(t){switch(t){case e.linear:return t;case e.backIn:return e.backOut;case e.backOut:return e.backIn;case e.backInOut:return t;case e.bounceIn:return e.bounceOut;case e.bounceOut:return e.bounceIn;case e.bounceInOut:return t;case e.circleIn:return e.circleOut;case e.circleOut:return e.circleIn;case e.circleInOut:return t;case e.cubicIn:return e.cubicOut;case e.cubicOut:return e.cubicIn;case e.circleInOut:case e.punch:return t;case e.expoIn:return e.expoOut;case e.expoOut:return e.expoIn;case e.expoInOut:return t;case e.quadIn:return e.quadOut;case e.quadOut:return e.quadIn;case e.quadInOut:return t;case e.quartIn:return e.quadOut;case e.quartOut:return e.quartIn;case e.quadInOut:return t;case e.sineIn:return e.sineOut;case e.sineOut:return e.sineIn;case e.sineInOut:default:return t}},n.ease=function(n,i,r){switch(n){case e.linear:return t.Easing.Linear.easeNone(i,r);case e.backIn:return t.Easing.Back.easeIn(i,r);case e.backOut:return t.Easing.Back.easeOut(i,r);case e.backInOut:return t.Easing.Back.easeInOut(i,r);case e.bounceIn:return t.Easing.Bounce.easeIn(i,r);case e.bounceOut:return t.Easing.Bounce.easeOut(i,r);case e.bounceInOut:return t.Easing.Bounce.easeInOut(i,r);case e.circleIn:return t.Easing.Circular.easeIn(i,r);case e.circleOut:return t.Easing.Circular.easeOut(i,r);case e.circleInOut:return t.Easing.Circular.easeInOut(i,r);case e.cubicIn:return t.Easing.Cubic.easeIn(i,r);case e.cubicOut:return t.Easing.Cubic.easeOut(i,r);case e.cubicInOut:return t.Easing.Cubic.easeInOut(i,r);case e.elasticIn:return t.Easing.Elastic.easeIn(i,r);case e.elasticOut:return t.Easing.Elastic.easeOut(i,r);case e.elasticInOut:return t.Easing.Elastic.easeInOut(i,r);case e.punch:return t.Easing.Elastic.punch(i,r);case e.expoIn:return t.Easing.Exponential.easeIn(i,r);case e.expoOut:return t.Easing.Exponential.easeOut(i,r);case e.expoInOut:return t.Easing.Exponential.easeInOut(i,r);case e.quadIn:return t.Easing.Quadratic.easeIn(i,r);case e.quadOut:return t.Easing.Quadratic.easeOut(i,r);case e.quadInOut:return t.Easing.Quadratic.easeInOut(i,r);case e.quintIn:return t.Easing.Quintic.easeIn(i,r);case e.quintOut:return t.Easing.Quintic.easeOut(i,r);case e.quintInOut:return t.Easing.Quintic.easeInOut(i,r);case e.sineIn:return t.Easing.Sinusoidal.easeIn(i,r);case e.sineOut:return t.Easing.Sinusoidal.easeOut(i,r);case e.sineInOut:return t.Easing.Sinusoidal.easeInOut(i,r);default:return t.Easing.Linear.easeNone(i,r)}},n}();t.EaseHelper=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(e){function n(){var t=e.call(this)||this;return t._activeTweens=[],t._tempTweens=[],n._instance=t,t}return __extends(n,e),Object.defineProperty(n,"activeTweens",{get:function(){return this._instance._activeTweens},enumerable:!0,configurable:!0}),n.prototype.update=function(){this._isUpdating=!0;for(var e=this._activeTweens.length-1;e>=0;--e){var n=this._activeTweens[e];n.tick()&&this._tempTweens.push(n)}this._isUpdating=!1;for(e=0;e=0;--e)n._instance._activeTweens[e].stop(t)},n.allTweensWithContext=function(t){for(var e=[],i=0;i=0;--i)n._instance._activeTweens[i].context==t&&n._instance._activeTweens[i].stop(e)},n.allTweenWithTarget=function(t){for(var e=[],i=0;i=0;--i)if(n._instance._activeTweens[i]){var r=n._instance._activeTweens[i];r.getTargetObject()==t&&r.stop(e)}},n.defaultEaseType=t.EaseType.quartIn,n.removeAllTweensOnLevelLoad=!1,n.cacheNumberTweens=!0,n.cacheVector2Tweens=!0,n.cacheColorTweens=!0,n.cacheRectTweens=!1,n}(t.GlobalManager);t.TweenManager=e}(es||(es={})),function(t){!function(t){var e=function(){function t(){}return t.easeNone=function(t,e){return t/e},t}();t.Linear=e;var n=function(){function t(){}return t.easeIn=function(t,e){return(t/=e)*t},t.easeOut=function(t,e){return-1*(t/=e)*(t-2)},t.easeInOut=function(t,e){return(t/=e/2)<1?.5*t*t:-.5*(--t*(t-2)-1)},t}();t.Quadratic=n;var i=function(){function t(){}return t.easeIn=function(t,e,n){return void 0===n&&(n=1.70158),(t/=e)*t*((n+1)*t-n)},t.easeOut=function(t,e,n){return void 0===n&&(n=1.70158),(t=t/e-1)*t*((n+1)*t+n)+1},t.easeInOut=function(t,e,n){return void 0===n&&(n=1.70158),(t/=e/2)<1?t*t*(((n*=1.525)+1)*t-n)*.5:.5*((t-=2)*t*(((n*=1.525)+1)*t+n)+2)},t}();t.Back=i;var r=function(){function t(){}return t.easeOut=function(t,e){return(t/=e)<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},t.easeIn=function(t,e){return 1-this.easeOut(e-t,e)},t.easeInOut=function(t,e){return t= 2");if(t.sort(function(t,e){return t.t-e.t}),0!==t[0].t)throw new Error("curve must start with 0");if(1!==t[t.length-1].t)throw new Error("curve must end with 1");this._points=t}return Object.defineProperty(e.prototype,"points",{get:function(){return this._points},enumerable:!0,configurable:!0}),e.prototype.lerp=function(e){for(var n=1;n>7,n+=n<<3,n^=n>>17,n+=n<<5},t}();t.Hash=e}(es||(es={})),function(t){var e=function(){function t(){this._listeners=[]}return t.prototype.addListener=function(t,e){-1===this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t})&&this._listeners.push({caller:t,callback:e})},t.prototype.removeListener=function(t,e){var n=this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t});n>=0&&this._listeners.splice(n,1)},t.prototype.clearListener=function(){this._listeners=[]},t.prototype.clearListenerWithCaller=function(t){for(var e=this._listeners.length-1;e>=0;e--){this._listeners[e].caller===t&&this._listeners.splice(e,1)}},t.prototype.notify=function(){for(var t,e=[],n=0;n=0;i--){var r=this._listeners[i];r.caller?(t=r.callback).call.apply(t,__spread([r.caller],e)):r.callback.apply(r,__spread(e))}},t}();t.Observable=e;var n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e){t.prototype.notify.call(this,e)},e}(e);t.ObservableT=n;var i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e,n){t.prototype.notify.call(this,e,n)},e}(e);t.ObservableTT=i;var r=function(){function t(t,n){this.bindAction(t,n),this._onExec=new e}return t.prototype.bindAction=function(t,e){this._caller=t,this._action=e},t.prototype.dispatch=function(){for(var t,e=[],n=0;n3&&o<500;){o++;var a=!0,u=n[this._triPrev[s]],h=n[s],c=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(u,h,c)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],u,h,c)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.length>8&255]+e[t>>16&255]+e[t>>24&255]+"-"+e[255&n]+e[n>>8&255]+"-"+e[n>>16&15|64]+e[n>>24&255]+"-"+e[63&i|128]+e[i>>8&255]+"-"+e[i>>16&255]+e[i>>24&255]+e[255&r]+e[r>>8&255]+e[r>>16&255]+e[r>>24&255]},t}();t.UUID=n}(es||(es={})),function(t){t.getClassName=function(t){return t.className||t.name}}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return __spread(this._completeSlices,[this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(es||(es={})),function(t){var e=function(){function t(t){void 0===t&&(t=64),this.size_=0,this.length=0,this.array=[],this.length=t}return t.prototype.removeAt=function(t){var e=this.array[t];return this.array[t]=this.array[--this.size_],this.array[this.size_]=null,e},t.prototype.remove=function(t){var e,n=this.size_;for(e=0;e0){var t=this.array[--this.size_];return this.array[this.size_]=null,t}return null},t.prototype.contains=function(t){var e,n;for(e=0,n=this.size_;n>e;e++)if(t===this.array[e])return!0;return!1},t.prototype.removeAll=function(t){var e,n,i,r,o=!1;for(e=0,i=t.size();e=this.length)throw new Error("ArrayIndexOutOfBoundsException");return this.array[t]},t.prototype.safeGet=function(t){return t>=this.length&&this.grow(7*t/4+1),this.array[t]},t.prototype.size=function(){return this.size_},t.prototype.getCapacity=function(){return this.length},t.prototype.isIndexWithinBounds=function(t){return t=this.length&&this.grow(2*t),this.size_=t+1,this.array[t]=e},t.prototype.grow=function(t){void 0===t&&(t=1+~~(3*this.length/2)),this.length=~~t},t.prototype.ensureCapacity=function(t){t>=this.length&&this.grow(2*t)},t.prototype.clear=function(){var t,e;for(t=0,e=this.size_;te;e++)this.add(t.get(e))},t}();t.Bag=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=1),this._freeValueCellIndex=0,this._collisions=0,this._valuesInfo=new Array(e),this._values=new Array(e),this._buckets=new Array(t.HashHelpers.getPrime(e))}return e.prototype.getValuesArray=function(t){return t.value=this._freeValueCellIndex,this._values},Object.defineProperty(e.prototype,"valuesArray",{get:function(){return this._values},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"count",{get:function(){return this._freeValueCellIndex},enumerable:!0,configurable:!0}),e.prototype.add=function(t,e){if(!this.addValue(t,e,{value:0}))throw new Error("key 已经存在")},e.prototype.addValue=function(i,r,o){var s=t.HashHelpers.getHashCode(i),a=e.reduce(s,this._buckets.length);if(this._freeValueCellIndex==this._values.length){var u=t.HashHelpers.expandPrime(this._freeValueCellIndex);this._values.length=u,this._valuesInfo.length=u}var h=t.NumberExtension.toNumber(this._buckets[a])-1;if(-1==h)this._valuesInfo[this._freeValueCellIndex]=new n(i,s);else{var c=h;do{if(this._valuesInfo[c].hashcode==s&&this._valuesInfo[c].key==i)return this._values[c]=r,o.value=c,!1;c=this._valuesInfo[c].previous}while(-1!=c);this._collisions++,this._valuesInfo[this._freeValueCellIndex]=new n(i,s,h),this._valuesInfo[h].next=this._freeValueCellIndex}if(this._buckets[a]=this._freeValueCellIndex+1,this._values[this._freeValueCellIndex]=r,o.value=this._freeValueCellIndex,this._freeValueCellIndex++,this._collisions>this._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){return function(t,e){this.element=t,this.next=e}}();function n(t,e){return t===e}t.Node=e,t.defaultEquals=n;var i=function(){function t(t){void 0===t&&(t=n),this.count=0,this.next=void 0,this.equalsFn=t,this.head=null}return t.prototype.push=function(t){var n,i=new e(t);if(null==this.head)this.head=i;else{for(n=this.head;null!=n.next;)n=n.next;n.next=i}this.count++},t.prototype.removeAt=function(t){if(t>=0&&t=0&&t<=this.count){for(var e=this.head,n=0;n=0&&n<=this.count){var i=new e(t);if(0===n)i.next=this.head,this.head=i;else{var r=this.getElementAt(n-1);i.next=r.next,r.next=i}return this.count++,!0}return!1},t.prototype.indexOf=function(t){for(var e=this.head,n=0;n0)for(var n=0;nthis._objectQueue.get(t).length;)this._objectQueue.get(t).splice(0,1)},t.clearCache=function(t){this.checkCreate(t),this._objectQueue.get(t).length=0},t.obtain=function(t){return this.checkCreate(t),this._objectQueue.get(t).length>0?this._objectQueue.get(t).shift():[]},t.free=function(t,e){this.checkCreate(t),this._objectQueue.get(t).push(e),e.length=0},t.checkCreate=function(t){this._objectQueue.has(t)||this._objectQueue.set(t,[])},t._objectQueue=new Map,t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first===t.first&&this.second===t.second},t}();t.Pair=e}(es||(es={})),function(t){var e=function(){function t(){this._all=new Array}return Object.defineProperty(t.prototype,"all",{get:function(){return this._all},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return this._all.findIndex(function(e){return e.equals(t)})>-1},t.prototype.add=function(t){this.has(t)||this._all.push(t)},t.prototype.remove=function(t){var e=this._all.findIndex(function(e){return e.equals(t)});if(e>-1){var n=this._all[e];this._all[e]=this._all[this._all.length-1],this._all[this._all.length-1]=n,this._all=this._all.slice(0,this._all.length-1)}},t.prototype.clear=function(){this._all=[]},t.prototype.union=function(t){var e=t.all;if(e.length>0)for(var n=0;n0)for(var n=0;n0)for(var i=0;i0?e.pop():new t},e.free=function(e,n){this.checkCreate(e),this._objectQueue.get(e).push(n),t.isIPoolable(n)&&n.reset()},e.checkCreate=function(t){this._objectQueue.has(t)||this._objectQueue.set(t,[])},e._objectQueue=new Map,e}();t.Pool=e,t.isIPoolable=function(t){return"function"==typeof t.reset}}(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.clearAllCoroutines=function(){for(var n=0;n=0;r--){var o=n[r];if(o.isDone)t.Pool.free(e,o),n.splice(r,1);else{var s=o.waitForCoroutine;if(null!=s){if(!s.isDone){i.push(o);continue}o.waitForCoroutine=null}var a=o.waitTimer;a>0?(o.waitTimer=a-(o.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime),i.push(o)):this.tickCoroutine(o)&&i.push(o)}}n.push.apply(n,__spread(i)),i.length=0,this._isInUpdate=!1},i.prototype.tickCoroutine=function(n){var i=n.enumerator.next(),r=i.value;return i.done||n.isDone?(t.Pool.free(e,n),!1):!r||(r instanceof t.WaitForSeconds?(n.waitTimer=r.waitTime,!0):"number"==typeof r?(n.waitTimer=r,!0):"string"==typeof r?"break"!==r||(t.Pool.free(e,n),!1):"function"==typeof r?(n.waitForCoroutine=this.startCoroutine(r),!0):!(r instanceof e)||(n.waitForCoroutine=r,!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 u=Math.abs(this.freeRectangles[s].width-e),h=Math.abs(this.freeRectangles[s].height-n),c=Math.min(u,h);(a=n&&this.freeRectangles[s].height>=e){u=Math.abs(this.freeRectangles[s].width-n),h=Math.abs(this.freeRectangles[s].height-e),c=Math.min(u,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={})),function(t){var e=function(){function e(){}return e.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},e.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},e.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},e.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},e.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},e.cloneList=function(t){return t?t.slice(0,t.length):null},e.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},e.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},e.shuffle=function(e){for(var n=e.length;n>1;){n--;var i=t.RandomUtils.randint(0,n+1),r=e[i];e[i]=e[n],e[n]=r}},e.addIfNotPresent=function(e,n){return!new t.List(e).contains(n)&&(e.push(n),!0)},e.lastItem=function(t){return t[t.length-1]},e.randomItem=function(e){return e[t.RandomUtils.randint(0,e.length-1)]},e.randomItems=function(e,n,i){for(var r=new Set;r.size!=i;){var o=this.randomItem(n);r.has(o)||r.add(o)}var s=t.ListPool.obtain(e);return r.forEach(function(t){return s.push(t)}),s},e}();t.ArrayUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],u=0;u>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(u++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(u++))),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,u=[],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),u.push(this._keyStr.charAt(r)),u.push(this._keyStr.charAt(o)),u.push(this._keyStr.charAt(s)),u.push(this._keyStr.charAt(a));return u=u.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random().5?1:-1},t}();t.RandomUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,i.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e.boundsFromPolygonVector=function(e){for(var n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,s=0;sr&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(n,i),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,n){return new t.Rectangle(e.x,e.y,n.x-e.x,n.y-e.y)},e.getSweptBroadphaseBounds=function(e,n,i){var r=t.Rectangle.empty;return r.x=n>0?e.x:e.x+n,r.y=i>0?e.y:e.y+i,r.width=n>0?n+e.width:e.width-n,r.height=i>0?i+e.height:e.height-i,r},e.prototype.collisionCheck=function(t,e,n,i){n.value=i.value=0;var r=e.x-(t.x+t.width),o=e.x+e.width-t.x,s=e.y-(t.y+t.height),a=e.y+e.height-t.y;return!(r>0||o<0||s>0||a<0)&&(n.value=Math.abs(r)=l||Math.abs(c)>=p)return t.Vector2.zero;var f=h>0?l-h:-l-h,d=c>0?p-c:-p-c;return new t.Vector2(f,d)},e.getClosestPointOnBoundsToOrigin=function(e){var n=this.getMax(e),i=Math.abs(e.location.x),r=new t.Vector2(e.location.x,0);return Math.abs(n.x)r&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(t.MathHelper.toInt(n),t.MathHelper.toInt(i)),new t.Vector2(t.MathHelper.toInt(r),t.MathHelper.toInt(o)))},e.calculateBounds=function(e,n,i,r,o,s,a,u){if(0==s)e.x=t.MathHelper.toInt(n.x+i.x-r.x*o.x),e.y=t.MathHelper.toInt(n.y+i.y-r.y*o.y),e.width=t.MathHelper.toInt(a*o.x),e.height=t.MathHelper.toInt(u*o.y);else{var h=n.x+i.x,c=n.y+i.y,l=new t.Matrix2D;t.Matrix2D.createTranslation(-h-r.x,-c-r.y,l),t.Matrix2D.createScale(o.x,o.y,void 0),l=l.multiply(void 0),t.Matrix2D.createRotation(s,void 0),l=l.multiply(void 0),t.Matrix2D.createTranslation(h,c,void 0),l=l.multiply(void 0);var p=new t.Vector2(h,c),f=new t.Vector2(h+a,c),d=new t.Vector2(h,c+u),m=new t.Vector2(h+a,c+u);t.Vector2Ext.transformR(p,l,p),t.Vector2Ext.transformR(f,l,f),t.Vector2Ext.transformR(d,l,d),t.Vector2Ext.transformR(m,l,m);var y=t.MathHelper.toInt(Math.min(p.x,m.x,f.x,d.x)),g=t.MathHelper.toInt(Math.max(p.x,m.x,f.x,d.x)),_=t.MathHelper.toInt(Math.min(p.y,m.y,f.y,d.y)),v=t.MathHelper.toInt(Math.max(p.y,m.y,f.y,d.y));e.location=new t.Vector2(y,_),e.width=t.MathHelper.toInt(g-y),e.height=t.MathHelper.toInt(v-_)}},e.scale=function(e,n){e.x=t.MathHelper.toInt(e.x*n.x),e.y=t.MathHelper.toInt(e.y*n.y),e.width=t.MathHelper.toInt(e.width*n.x),e.height=t.MathHelper.toInt(e.height*n.y)},e.translate=function(t,e){t.location.addEqual(e)},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function t(){}return t.premultiplyAlpha=function(t){for(var e=t[0],n=0;nt.MathHelper.Epsilon?e.divideScaler(n):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){var e=this.sum(t),n=this.count(t);return 0===n?NaN:e/n},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]:null},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){void 0===i&&(i=t.keyComparer(e,!0));var r=this._elements.slice();return r.sort(i),new n(r,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){var e=this.indexOf(t);return-1!==e&&(this.removeAt(e),!0)},e.prototype.removeAll=function(n){return new e(this.where(t.negate(n)).toArray())},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){var o=n.select(t).elementAt(r);return e.addRange(o.toArray())},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.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.bind(n)},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),this._timers.splice(t,1))},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 __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;e0&&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}}}};!function(t){var e=function(){function e(n,i){void 0===n&&(n=!0),void 0===i&&(i=!0),this._globalManagers=[],this._coroutineManager=new t.CoroutineManager,this._timerManager=new t.TimerManager,this._frameCounterElapsedTime=0,this._frameCounter=0,this._totalMemory=0,e._instance=this,e.emitter=new t.Emitter,e.emitter.addObserver(t.CoreEvents.frameUpdated,this.update,this),e.registerGlobalManager(this._coroutineManager),e.registerGlobalManager(new t.TweenManager),e.registerGlobalManager(this._timerManager),e.entitySystemsEnabled=i,this.debug=n,this.initialize()}return Object.defineProperty(e,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(e,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(e){t.Insist.isNotNull(e,"场景不能为空"),null==this._instance._scene?(this._instance._scene=e,this._instance.onSceneChanged(),this._instance._scene.begin()):this._instance._nextScene=e},enumerable:!0,configurable:!0}),e.create=function(e){return void 0===e&&(e=!0),null==this._instance&&(this._instance=new t.Core(e)),this._instance},e.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},e.unregisterGlobalManager=function(e){new t.List(this._instance._globalManagers).remove(e),e.enabled=!1},e.getGlobalManager=function(t){for(var n=0,i=e._instance._globalManagers.length;n=1)){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._titleMemory&&this._titleMemory(this._totalMemory,this._frameCounter),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.sceneChanged),t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(n){if(void 0===n&&(n=-1),!e.paused){if(t.Time.update(n,-1!=n),null!=this._scene){for(var i=this._globalManagers.length-1;i>=0;i--)this._globalManagers[i].enabled&&this._globalManagers[i].update();null!=this._sceneTransition&&(null==this._sceneTransition||this._sceneTransition._loadsNewScene&&!this._sceneTransition._isNewSceneLoaded)||this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.startDebugDraw(),this.draw()}},e.prototype.draw=function(){null!=this._sceneTransition&&this._sceneTransition.preRender(),null==this._sceneTransition||this._sceneTransition.hasPreviousSceneRender||(null!=this._scene&&e.startCoroutine(this._sceneTransition.onBeginTransition()),this._sceneTransition.render())},e.paused=!1,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){var e;!function(t){t[t.error=0]="error",t[t.warn=1]="warn",t[t.log=2]="log",t[t.info=3]="info",t[t.trace=4]="trace"}(e=t.LogType||(t.LogType={}));var n=function(){function n(){}return n.warnIf=function(t,n){for(var i=[],r=2;r=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t0?new e(this.x/t,this.y/t):new e(0,1)},e.prototype.normalizeEqual=function(){var t=this.distance();return t>0?(this.setTo(this.x/t,this.y/t),this):(this.setTo(0,1),this)},e.prototype.magnitude=function(){return this.distance()},e.prototype.distance=function(t){return t||(t=e.zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},e.prototype.getLength=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.prototype.angleBetween=function(e,n){var i=e.sub(this),r=n.sub(this);return t.Vector2Ext.angle(i,r)},e.prototype.getDistance=function(t){return Math.sqrt(this.getDistanceSquared(t))},e.prototype.getDistanceSquared=function(t){var e=t.x-this.x,n=t.y-this.y;return e*e+n*n},e.prototype.isBetween=function(t,e){var n=e.sub(t).cross(this.sub(t));return Math.abs(n)=0&&this.dot(t.sub(e))>=0},e.prototype.cross=function(t){return this.x*t.y-this.y*t.x},e.prototype.getAngle=function(){return Math.atan2(this.y,this.x)},e.prototype.equals=function(t,e){return void 0===e&&(e=.001),Math.abs(this.x-t.x)<=e&&Math.abs(this.y-t.y)<=e},e.prototype.isValid=function(){return t.MathHelper.isValid(this.x)&&t.MathHelper.isValid(this.y)},e.min=function(t,n){return new e(t.xn.x?t.x:n.x,t.y>n.y?t.y:n.y)},e.hermite=function(n,i,r,o,s){return new e(t.MathHelper.hermite(n.x,i.x,r.x,o.x,s),t.MathHelper.hermite(n.y,i.y,r.y,o.y,s))},e.unsignedAngle=function(e,n,i){void 0===i&&(i=!0),e.normalizeEqual(),n.normalizeEqual();var r=Math.acos(t.MathHelper.clamp(e.dot(n),-1,1))*t.MathHelper.Rad2Deg;return i?Math.round(r):r},e.fromAngle=function(t,n){return void 0===n&&(n=1),new e(n*Math.cos(t),n*Math.sin(t))},e.prototype.clone=function(){return new e(this.x,this.y)},e.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(){this._sceneComponents=[],this.entities=new t.EntityList(this),this.entityProcessors=new t.EntityProcessorList,this.identifierPool=new t.IdentifierPool,this.initialize()}return e.prototype.initialize=function(){},e.prototype.onStart=function(){},e.prototype.unload=function(){},e.prototype.begin=function(){t.Physics.reset(),null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.prototype.end=function(){this._didSceneBegin=!1,this.entities.removeAllEntities();for(var e=0;e=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate()},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=this.position.sub(e).normalize();this.rotation=n*Math.acos(i.dot(t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(n.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,null!=this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this.setDirty(n.scaleDirty),this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(n.scaleDirty),this},i.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},i.prototype.updateTransform=function(){this.hierarchyDirty!=n.clean&&(null!=this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y,this._translationMatrix),this._localPositionDirty=!1),this._localRotationDirty&&(t.Matrix2D.createRotation(this._localRotation,this._rotationMatrix),this._localRotationDirty=!1),this._localScaleDirty&&(t.Matrix2D.createScale(this._localScale.x,this._localScale.y,this._scaleMatrix),this._localScaleDirty=!1),t.Matrix2D.multiply(this._scaleMatrix,this._rotationMatrix,this._localTransform),t.Matrix2D.multiply(this._localTransform,this._translationMatrix,this._localTransform),null==this.parent&&(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),null!=this.parent&&(t.Matrix2D.multiply(this._localTransform,this.parent._worldTransform,this._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=this.parent._scale.multiply(this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=n.clean)},i.prototype.setDirty=function(t){if(0==(this.hierarchyDirty&t)){switch(this.hierarchyDirty|=t,t){case n.positionDirty:this.entity.onTransformChanged(e.position);break;case n.rotationDirty:this.entity.onTransformChanged(e.rotation);break;case n.scaleDirty:this.entity.onTransformChanged(e.scale)}for(var i=0;i1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},n.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},n.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},n.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},n.prototype.setVelocity=function(t){return this.velocity=t,this},n.prototype.addImpulse=function(e){this.isImmovable||this.velocity.addEqual(e.scale(this._inverseMass*(t.Time.deltaTime*t.Time.deltaTime)*1e5))},n.prototype.onAddedToEntity=function(){this._collider=null;for(var e=0;e0)for(var i=0;i0&&(o=t.Vector2.zero);var a=this._friction;return s.lengthSquared()0&&this.collisionState.wasGroundedLastFrame&&(t=this.handleVerticalSlope(t)),0!==t.x&&(t=this.moveHorizontally(t)),0!==t.y&&(t=this.moveVertically(t)),this._player.setPosition(this._player.position.x+t.x,this._player.position.y+t.y),e>0&&(this.velocity.x=t.x/e,this.velocity.y=t.y/e),!this.collisionState.wasGroundedLastFrame&&this.collisionState.below&&(this.collisionState.becameGroundedThisFrame=!0),this._isGoingUpSlope&&(this.velocity.y=0),this._isWarpingToGround||this._triggerHelper.update();for(var n=0;n0&&(this.ignoreOneWayPlatformsTime-=e)},i.prototype.warpToGrounded=function(e){void 0===e&&(e=1e3),this.ignoreOneWayPlatformsTime=0,this._isWarpingToGround=!0;var n=0;do{if(n+=1,this.move(new t.Vector2(0,1),.02),n>e)break}while(!this.isGrounded);this._isWarpingToGround=!1},i.prototype.recalculateDistanceBetweenRays=function(){var t=this._collider.height*Math.abs(this._player.scale.y)-2*this._skinWidth;this._verticalDistanceBetweenRays=t/(this.totalHorizontalRays-1);var e=this._collider.width*Math.abs(this._player.scale.x)-2*this._skinWidth;this._horizontalDistanceBetweenRays=e/(this.totalVerticalRays-1)},i.prototype.primeRaycastOrigins=function(){var e=this._collider.bounds;this._raycastOrigins.topLeft=new t.Vector2(e.x+this._skinWidth,e.y+this._skinWidth),this._raycastOrigins.bottomRight=new t.Vector2(e.right-this._skinWidth,e.bottom-this._skinWidth),this._raycastOrigins.bottomLeft=new t.Vector2(e.x+this._skinWidth,e.bottom-this._skinWidth)},i.prototype.moveHorizontally=function(e){for(var n=e.x>0,i=Math.abs(e.x)+this._skinWidth*this.rayOriginSkinMutiplier,r=n?t.Vector2.right:t.Vector2.left,o=this._raycastOrigins.bottomLeft.y,s=n?this._raycastOrigins.bottomRight.x-this._skinWidth*(this.rayOriginSkinMutiplier-1):this._raycastOrigins.bottomLeft.x+this._skinWidth*(this.rayOriginSkinMutiplier-1),a=0;a0)&&(a&=~this.oneWayPlatformMask);for(var c=0;cthis.jumpingThreshold){var i=this.slopeSpeedMultiplier?this.slopeSpeedMultiplier.lerp(n):1;e.x*=i,e.y=Math.abs(Math.tan(n*t.MathHelper.Deg2Rad)*e.x);var r=e.x>0,o=r?this._raycastOrigins.bottomRight:this._raycastOrigins.bottomLeft,s=null;(s=this.supportSlopedOneWayPlatforms&&this.collisionState.wasGroundedLastFrame?t.Physics.linecast(o,o.add(e),this.platformMask,this.ignoredColliders):t.Physics.linecast(o,o.add(e),this.platformMask&~this.oneWayPlatformMask,this.ignoredColliders)).collider&&(e.x=s.point.x-o.x,e.y=s.point.y-o.y,r?e.x-=this._skinWidth:e.x+=this._skinWidth),this._isGoingUpSlope=!0,this.collisionState.below=!0}}else e.x=0;return!0},i}();t.CharacterController=i}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,n){if(e.components._components.length>0)for(var i=0;i0)for(var r=0;r0)for(r=0;r0)for(r=0;r0)for(var h=0;h0)for(var r=0;r=this.delay)},n.prototype.offerDelay=function(t){this.running?this.delay=Math.min(this.delay,t):(this.running=!0,this.delay=t)},n.prototype.getInitialTimeDelay=function(){return this.delay},n.prototype.getRemainingTimeUntilProcessing=function(){return this.running?this.delay-this.acc:0},n.prototype.isRunning=function(){return this.running},n.prototype.stop=function(){this.running=!1,this.acc=0},n}(t.EntitySystem);t.DelayedIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.enabled=!0,n}return __extends(e,t),e.prototype.lateProcessEntity=function(t){},e.prototype.process=function(t){if(0!==t.length)for(var e=0,n=t.length;e=this.interval&&(this.intervalRemainder=this.acc-this.interval,this.acc=0,!0)},n.prototype.getIntervalDelta=function(){return this.interval+this.intervalRemainder},n}(t.EntitySystem);t.IntervalSystem=e}(es||(es={})),function(t){var e=function(t){function e(e,n){return t.call(this,e,n)||this}return __extends(e,t),e.prototype.process=function(t){var e=this;t.forEach(function(t){return e.processEntity(t)})},e}(t.IntervalSystem);t.IntervalIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onChanged=function(t){},e.prototype.process=function(t){this.begin(),this.end()},e}(t.EntitySystem);t.PassiveSystem=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onChanged=function(t){},e.prototype.process=function(t){this.begin(),this.processSystem(),this.end()},e}(t.EntitySystem);t.ProcessingSystem=e}(es||(es={})),function(t){var e=function(){function t(){this._bit={}}return t.prototype.set=function(t,e){this._bit[t]=e},t.prototype.get=function(t){var e=this._bit[t];return null==e?0:e},t}();t.Bits=e}(es||(es={})),function(t){var e=function(){function e(t){this._components=[],this._updatableComponents=[],this._componentsToAdd={},this._componentsToRemove={},this._componentsToAddList=[],this._componentsToRemoveList=[],this._tempBufferList=[],this.componentsByType=new Map,this.componentsToAddByType=new Map,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[t.id]=t,this._componentsToAddList.push(t),this.addComponentsToAddByType(t)},e.prototype.remove=function(t){if(this._componentsToAdd[t.id]){var e=this._componentsToAddList.findIndex(function(e){return e.id===t.id});return-1!==e&&this._componentsToAddList.splice(e,1),delete this._componentsToAdd[t.id],void this.removeComponentsToAddByType(t)}this._componentsToRemove[t.id]=t,this._componentsToRemoveList.push(t)},e.prototype.removeAllComponents=function(){if(this._components.length>0)for(var t=0,e=this._components.length;t0)try{for(var i=__values(this._components),r=i.next();!r.done;r=i.next()){var o=r.value;t.isIUpdatable(o)&&new t.List(this._updatableComponents).remove(o),this.decreaseBits(o),this._entity.scene.entityProcessors.onComponentRemoved(this._entity)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},e.prototype.registerAllComponents=function(){var e,n;if(this._components.length>0)try{for(var i=__values(this._components),r=i.next();!r.done;r=i.next()){var o=r.value;t.isIUpdatable(o)&&this._updatableComponents.push(o),this.addBits(o),this._entity.scene.entityProcessors.onComponentAdded(this._entity)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},e.prototype.decreaseBits=function(e){var n=this._entity.componentBits,i=t.ComponentTypeManager.getIndexFor(t.TypeUtils.getType(e));n.set(i,n.get(i)-1)},e.prototype.addBits=function(e){var n=this._entity.componentBits,i=t.ComponentTypeManager.getIndexFor(t.TypeUtils.getType(e));n.set(i,n.get(i)+1)},e.prototype.updateLists=function(){var e,n,i,r,o,s;if(this._componentsToRemoveList.length>0){var a=function(t){c.handleRemove(t);var e=c._components.findIndex(function(e){return e.id===t.id});-1!==e&&c._components.splice(e,1),c.removeComponentsByType(t)},c=this;try{for(var u=__values(this._componentsToRemoveList),h=u.next();!h.done;h=u.next()){a(f=h.value)}}catch(t){e={error:t}}finally{try{h&&!h.done&&(n=u.return)&&n.call(u)}finally{if(e)throw e.error}}this._componentsToRemove={},this._componentsToRemoveList.length=0}if(this._componentsToAddList.length>0){try{for(var l=__values(this._componentsToAddList),p=l.next();!p.done;p=l.next()){var f=p.value;t.isIUpdatable(f)&&this._updatableComponents.push(f),this.addBits(f),this._entity.scene.entityProcessors.onComponentAdded(this._entity),this.addComponentsByType(f),this._components.push(f),this._tempBufferList.push(f)}}catch(t){i={error:t}}finally{try{p&&!p.done&&(r=l.return)&&r.call(l)}finally{if(i)throw i.error}}this._componentsToAdd={},this._componentsToAddList.length=0,this.componentsToAddByType.clear(),this._isComponentListUnsorted=!0}if(this._tempBufferList.length>0){try{for(var d=__values(this._tempBufferList),y=d.next();!y.done;y=d.next()){(f=y.value).onAddedToEntity(),f.enabled&&f.onEnabled()}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=d.return)&&s.call(d)}finally{if(o)throw o.error}}this._tempBufferList.length=0}},e.prototype.handleRemove=function(e){if(t.isIUpdatable(e)&&this._updatableComponents.length>0){var n=this._updatableComponents.findIndex(function(t){return t.id===e.id});-1!==n&&this._updatableComponents.splice(n,1)}this.decreaseBits(e),this._entity.scene.entityProcessors.onComponentRemoved(this._entity),e.onRemovedFromEntity(),e.entity=null},e.prototype.removeComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id===e.id});-1!==i&&n.splice(i,1)},e.prototype.addComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsByType.set(t.TypeUtils.getType(e),n)},e.prototype.removeComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsToAddByType.set(t.TypeUtils.getType(e),n)},e.prototype.getComponent=function(t,e){var n=this.componentsByType.get(t);if(n&&n.length>0)return n[0];if(!e){var i=this.componentsToAddByType.get(t);if(i&&i.length>0)return i[0]}return null},e.prototype.getComponents=function(t,e){e||(e=[]);var n=this.componentsByType.get(t);n&&(e=e.concat(n));var i=this.componentsToAddByType.get(t);return i&&(e=e.concat(i)),e},e.prototype.update=function(){if(this.updateLists(),this._updatableComponents.length>0)for(var t=0,e=this._updatableComponents.length;t0)for(var e=0,n=this._components.length;e0)for(e=0,n=this._componentsToAddList.length;e0)for(var t=0,e=this._components.length;t0)for(var t=0,e=this._components.length;t0){var c=function(t){u.removeFromTagList(t);var e=u._entities.findIndex(function(e){return e.id===t.id});-1!==e&&u._entities.splice(e,1),t.onRemovedFromScene(),t.scene=null,u.scene.entityProcessors.onEntityRemoved(t)},u=this;try{for(var h=__values(this._entitiesToRemoveList),l=h.next();!l.done;l=h.next()){c(d=l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(e=h.return)&&e.call(h)}finally{if(t)throw t.error}}this._entitiesToRemove={},this._entitiesToRemoveList.length=0}if(this._entitiesToAddedList.length>0){try{for(var p=__values(this._entitiesToAddedList),f=p.next();!f.done;f=p.next()){var d=f.value;this._entities.push(d),d.scene=this.scene,this.addToTagList(d)}}catch(t){n={error:t}}finally{try{f&&!f.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}try{for(var y=__values(this._entitiesToAddedList),m=y.next();!m.done;m=y.next()){d=m.value;this.scene.entityProcessors.onEntityAdded(d)}}catch(t){r={error:t}}finally{try{m&&!m.done&&(o=y.return)&&o.call(y)}finally{if(r)throw r.error}}try{for(var g=__values(this._entitiesToAddedList),_=g.next();!_.done;_=g.next()){(d=_.value).onAddedToScene()}}catch(t){s={error:t}}finally{try{_&&!_.done&&(a=g.return)&&a.call(g)}finally{if(s)throw s.error}}this._entitiesToAdded={},this._entitiesToAddedList.length=0}},e.prototype.findEntity=function(t){if(this._entities.length>0)for(var e=0,n=this._entities.length;e0)for(e=0,n=this._entitiesToAddedList.length;e0)for(var e=0,n=this._entities.length;e0)try{for(var s=__values(r),a=s.next();!a.done;a=s.next()){var c=a.value;o.push(c)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return o},e.prototype.entityWithTag=function(t){var e,n,i=this.getTagList(t);if(i.size>0)try{for(var r=__values(i),o=r.next();!o.done;o=r.next()){return o.value}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return null},e.prototype.findComponentOfType=function(t){var e,n,i,r;try{for(var o=__values(this._entities),s=o.next();!s.done;s=o.next()){if((u=s.value).enabled)if(h=u.getComponent(t))return h}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}try{for(var a=__values(this._entitiesToAddedList),c=a.next();!c.done;c=a.next()){var u,h;if((u=c.value).enabled)if(h=u.getComponent(t))return h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return null},e.prototype.findComponentsOfType=function(e){var n,i,r,o,s=t.ListPool.obtain(e);try{for(var a=__values(this._entities),c=a.next();!c.done;c=a.next()){(l=c.value).enabled&&l.getComponents(e,s)}}catch(t){n={error:t}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}try{for(var u=__values(this._entitiesToAddedList),h=u.next();!h.done;h=u.next()){var l;(l=h.value).enabled&&l.getComponents(e,s)}}catch(t){r={error:t}}finally{try{h&&!h.done&&(o=u.return)&&o.call(u)}finally{if(r)throw r.error}}return s},e.prototype.findEntitiesOfComponent=function(){for(var t,e,n,i,r,o,s,a,c=[],u=0;u=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e=0;if(0===t.length)return e;for(var n=0;n0?this.ids.removeLast():this.nextAvailableId_++},e.prototype.checkIn=function(t){this.ids.add(t)},e}();t.IdentifierPool=e}(es||(es={})),function(t){var e=function(){function e(){this.allSet=[],this.exclusionSet=[],this.oneSet=[]}return e.empty=function(){return new e},e.prototype.getAllSet=function(){return this.allSet},e.prototype.getExclusionSet=function(){return this.exclusionSet},e.prototype.getOneSet=function(){return this.oneSet},e.prototype.isInterestedEntity=function(t){return this.isInterested(t.componentBits)},e.prototype.isInterested=function(e){if(0!==this.allSet.length)for(var n=0;n=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}();t.StringUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t,e){var n=0;e?n=t:(-1===t&&(t=Date.now()),-1===this._lastTime&&(this._lastTime=t),n=(t-this._lastTime)/1e3),n>this.maxDeltaTime&&(n=this.maxDeltaTime),this.totalTime+=n,this.deltaTime=n*this.timeScale,this.unscaledDeltaTime=n,this.timeSinceSceneLoad+=n,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return Math.floor(this.timeSinceSceneLoad/t)>Math.floor(this.deltaTime/t)},t.totalTime=0,t.unscaledDeltaTime=0,t.deltaTime=0,t.timeScale=1,t.maxDeltaTime=Number.MAX_VALUE,t.frameCount=0,t.timeSinceSceneLoad=0,t._lastTime=-1,t}();t.Time=e}(es||(es={})),function(t){var e=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(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=Math.floor(s/7),c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var u=n.getDay();if(0==u&&(u=7),e&&(!o||u<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){void 0===t&&(t=new Date);var e=t.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=1,n.range=this._points.length-4):(e=t.MathHelper.clamp01(e)*this._curveCount,n.range=t.MathHelper.toInt(e),e-=n.range,n.range*=3),n.time=e,n},e.prototype.setControlPoint=function(t,e){if(t%3==0){var n=e.sub(this._points[t]);t>0&&this._points[t-1].addEqual(n),t+1Math.PI?e-2*Math.PI:e},e.isPowerOfTwo=function(t){return!(t<=0)&&0==(t&t-1)},e.lerp=function(t,n,i){return t+(n-t)*e.clamp01(i)},e.betterLerp=function(t,n,i,r){return Math.abs(t-n)180&&(i-=360),t+i*this.clamp01(n)},e.lerpAngleRadians=function(t,e,n){var i=this.repeat(e-t,2*Math.PI);return i>Math.PI&&(i-=2*Math.PI),t+i*this.clamp01(n)},e.pingPong=function(t,e){return t=this.repeat(t,2*e),e-Math.abs(t-e)},e.signThreshold=function(t,e){return Math.abs(t)>=e?Math.sign(t):0},e.inverseLerp=function(t,e,n){var i=e-t;return 0===i?0:(n-t)/i},e.lerpPrecise=function(t,e,n){return(1-n)*t+e*n},e.clamp=function(t,e,n){return tn?n:t},e.snap=function(t,e){return Math.round(t/e)*e},e.isEven=function(t){return t%2==0},e.isOdd=function(t){return t%2!=0},e.roundWithRoundedAmount=function(t,e){var n=Math.round(t);return e.value=t-n*Math.round(t/n),n},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.angleToVector=function(e,n){var i=Math.cos(e)*n,r=Math.sin(e)*n;return new t.Vector2(i,r)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.decrementWithWrap=function(t,e){return--t<0?e-1:t},e.hypotenuse=function(t,e){var n=t*t+e*e;return Math.sqrt(n)},e.closestPowerOfTwoGreaterThan=function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,(t|=t>>16)+1},e.roundToNearest=function(t,e){var n=t/e;return Math.round(n)*e},e.withinEpsilon=function(t,e){return void 0===e&&(e=this.Epsilon),Math.abs(t)180&&(n-=360),n},e.between=function(t,e,n){return t>=e&&t<=n},e.deltaAngleRadians=function(t,e){var n=this.repeat(e-t,2*Math.PI);return n>Math.PI&&(n-=2*Math.PI),n},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.floorToInt=function(t){var e=Math.floor(t);return this.toInt(e)},e.rotateAround=function(e,n){var i=t.Time.totalTime*n,r=Math.cos(i),o=Math.sin(i),s=e.x+r,a=e.y+o;return new t.Vector2(s,a)},e.rotateAround2=function(e,n,i){var r=n.x,o=n.y,s=e.x,a=e.y,c=this.toRadians(i),u=Math.cos(c),h=Math.sin(c),l=u*(s-r)-h*(a-o)+r,p=h*(s-r)+u*(a-o)+o;return new t.Vector2(l,p)},e.pointOnCircle=function(e,n,i){var r=this.toRadians(i),o=Math.cos(r)*n,s=Math.sin(r)*n,a=o+e.x,c=s+e.y;return new t.Vector2(a,c)},e.pointOnCircleRadians=function(e,n,i){var r=Math.cos(i)*n,o=Math.sin(i)*n,s=r+e.x,a=o+e.y;return new t.Vector2(s,a)},e.lissajou=function(e,n,i,r,o){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=0);var s=Math.sin(t.Time.totalTime*e+o)*i,a=Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(s,a)},e.lissajouDamped=function(e,n,i,r,o,s,a){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=.5),void 0===s&&(s=0),void 0===a&&(a=5);var c=this.pingPong(t.Time.totalTime,a),u=Math.pow(Math.E,-s*c),h=u*Math.sin(t.Time.totalTime*e+o)*i,l=u*Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(h,l)},e.hermite=function(t,e,n,i,r){if(0===r)return t;if(1===r)return n;return(2*t-2*n+i+e)*(r*r*r)+(3*n-3*t-2*e-i)*(r*r)+e*r+t},e.isValid=function(t){return!Number.isNaN(t)&&t!==1/0},e.smoothDamp=function(t,n,i,r,o,s){var a=2/(r=Math.max(1e-4,r)),c=a*s,u=1/(1+.48*c+.235*c*c),h=o*r,l=t-n,p=(i+a*(l=e.clamp(l,-h,h)))*s;i=(i-a*p)*u;var f=(n=t-l)+(l+p)*u;return t>n==f>n&&(i=((f=n)-n)/s),{value:f,currentVelocity:i}},e.smoothDampVector=function(e,n,i,r,o,s){var a=t.Vector2.zero,c=this.smoothDamp(e.x,n.x,i.x,r,o,s);a.x=c.value,i.x=c.currentVelocity;var u=this.smoothDamp(e.y,n.y,i.y,r,o,s);return a.y=u.value,i.y=u.currentVelocity,a},e.mapMinMax=function(t,n,i,r,o){return r+(e.clamp(t,n,i)-n)*(o-r)/(i-n)},e.fromAngle=function(e){return new t.Vector2(Math.cos(e),Math.sin(e)).normalizeEqual()},e.toInt=function(t){return t>0?Math.floor(t):Math.ceil(t)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e.PiOver2=Math.PI/2,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function t(t,e,n,i,r,o,s,a,c,u,h,l,p,f,d,y){this.m11=t,this.m12=e,this.m13=n,this.m14=i,this.m21=r,this.m22=o,this.m23=s,this.m24=a,this.m31=c,this.m32=u,this.m33=h,this.m34=l,this.m41=p,this.m42=f,this.m43=d,this.m44=y}return Object.defineProperty(t,"Identity",{get:function(){return this.identity},enumerable:!0,configurable:!0}),t.createOrthographicOffCenter=function(e,n,i,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(n-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-i),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+n)/(e-n),a.m42=(r+i)/(i-r),a.m43=o/(o-s),a.m44=1},t.createTranslation=function(t,e){e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=t.x,e.m42=t.y,e.m43=0,e.m44=1},t.createRotationZ=function(e,n){n=t.Identity;var i=Math.cos(e),r=Math.sin(e);n.m11=i,n.m12=r,n.m21=-r,n.m22=i},t.multiply=function(e,n,i){void 0===i&&(i=new t);var r=e.m11*n.m11+e.m12*n.m21+e.m13*n.m31+e.m14*n.m41,o=e.m11*n.m12+e.m12*n.m22+e.m13*n.m32+e.m14*n.m42,s=e.m11*n.m13+e.m12*n.m23+e.m13*n.m33+e.m14*n.m43,a=e.m11*n.m14+e.m12*n.m24+e.m13*n.m34+e.m14*n.m44,c=e.m21*n.m11+e.m22*n.m21+e.m23*n.m31+e.m24*n.m41,u=e.m21*n.m12+e.m22*n.m22+e.m23*n.m32+e.m24*n.m42,h=e.m21*n.m13+e.m22*n.m23+e.m23*n.m33+e.m24*n.m43,l=e.m21*n.m14+e.m22*n.m24+e.m23*n.m34+e.m24*n.m44,p=e.m31*n.m11+e.m32*n.m21+e.m33*n.m31+e.m34*n.m41,f=e.m31*n.m12+e.m32*n.m22+e.m33*n.m32+e.m34*n.m42,d=e.m31*n.m13+e.m32*n.m23+e.m33*n.m33+e.m34*n.m43,y=e.m31*n.m14+e.m32*n.m24+e.m33*n.m34+e.m34*n.m44,m=e.m41*n.m11+e.m42*n.m21+e.m43*n.m31+e.m44*n.m41,g=e.m41*n.m12+e.m42*n.m22+e.m43*n.m32+e.m44*n.m42,_=e.m41*n.m13+e.m42*n.m23+e.m43*n.m33+e.m44*n.m43,v=e.m41*n.m14+e.m42*n.m24+e.m43*n.m34+e.m44*n.m44;i.m11=r,i.m12=o,i.m13=s,i.m14=a,i.m21=c,i.m22=u,i.m23=h,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=y,i.m41=m,i.m42=g,i.m43=_,i.m44=v},t.identity=new t(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t}();t.Matrix=e}(es||(es={})),function(t){var e=function(){function e(){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0}return Object.defineProperty(e,"identity",{get:function(){return(new e).setIdentity()},enumerable:!0,configurable:!0}),e.prototype.setIdentity=function(){return this.setValues(1,0,0,1,0,0)},e.prototype.setValues=function(t,e,n,i,r,o){return this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=r,this.m32=o,this},Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m22=t.y},enumerable:!0,configurable:!0}),e.createRotation=function(t,e){e.setIdentity();var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-1*i,e.m22=n},e.createRotationOut=function(t,e){var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-i,e.m22=n},e.createScale=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createScaleOut=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createTranslation=function(t,e,n){return n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=t,n.m32=e,n},e.createTranslationOut=function(t,e){e.m11=1,e.m12=0,e.m21=0,e.m22=1,e.m31=t.x,e.m32=t.y},e.invert=function(t){var e=1/t.determinant(),n=this.identity;return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.multiply=function(t,e,n){var i=t.m11*e.m11+t.m12*e.m21,r=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,s=t.m21*e.m12+t.m22*e.m22,a=t.m31*e.m11+t.m32*e.m21+e.m31,c=t.m31*e.m12+t.m32*e.m22+e.m32;n.m11=i,n.m12=r,n.m21=o,n.m22=s,n.m31=a,n.m32=c},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,n){return t.m11=t.m11+(e.m11-t.m11)*n,t.m12=t.m12+(e.m12-t.m12)*n,t.m21=t.m21+(e.m21-t.m21)*n,t.m22=t.m22+(e.m22-t.m22)*n,t.m31=t.m31+(e.m31-t.m31)*n,t.m32=t.m32+(e.m32-t.m32)*n,t},e.transpose=function(t){var e=this.identity;return e.m11=t.m11,e.m12=t.m21,e.m21=t.m12,e.m22=t.m22,e.m31=0,e.m32=0,e},e.prototype.mutiplyTranslation=function(n,i){var r=new e;return e.createTranslation(n,i,r),t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var n=new t.Matrix;return n.m11=e.m11,n.m12=e.m12,n.m13=0,n.m14=0,n.m21=e.m21,n.m22=e.m22,n.m23=0,n.m24=0,n.m31=0,n.m32=0,n.m33=1,n.m34=0,n.m41=e.m31,n.m42=e.m32,n.m43=0,n.m44=1,n},e.prototype.toString=function(){return"{m11:"+this.m11+" m12:"+this.m12+" m21:"+this.m21+" m22:"+this.m22+" m31:"+this.m31+" m32:"+this.m32+"}"},e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(){function e(){}return e.add=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11+n.m11,i.m12=e.m12+n.m12,i.m21=e.m21+n.m21,i.m22=e.m22+n.m22,i.m31=e.m31+n.m31,i.m32=e.m32+n.m32,i},e.divide=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11/n.m11,i.m12=e.m12/n.m12,i.m21=e.m21/n.m21,i.m22=e.m22/n.m22,i.m31=e.m31/n.m31,i.m32=e.m32/n.m32,i},e.mutiply=function(e,n){var i=t.Matrix2D.identity;if(n instanceof t.Matrix2D){var r=e.m11*n.m11+e.m12*n.m21,o=n.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,u=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=u}else"number"==typeof n&&(i.m11=e.m11*n,i.m12=e.m12*n,i.m21=e.m21*n,i.m22=e.m22*n,i.m31=e.m31*n,i.m32=e.m32*n);return i},e.subtract=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11-n.m11,i.m12=e.m12-n.m12,i.m21=e.m21-n.m21,i.m22=e.m22-n.m22,i.m31=e.m31-n.m31,i.m32=e.m32-n.m32,i},e}();t.MatrixHelper=e}(es||(es={})),function(t){var e=function(){function e(e,n,i,r){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),void 0===r&&(r=0),this.x=0,this.y=0,this.width=0,this.height=0,this._tempMat=new t.Matrix2D,this._transformMat=new t.Matrix2D,this.x=e,this.y=n,this.width=i,this.height=r}return Object.defineProperty(e,"empty",{get:function(){return new e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"maxRect",{get:function(){return new e(Number.MIN_VALUE/2,Number.MIN_VALUE/2,Number.MAX_VALUE,Number.MAX_VALUE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.isEmpty=function(){return 0==this.width&&0==this.height&&0==this.x&&0==this.y},Object.defineProperty(e.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),e.fromMinMax=function(t,n,i,r){return new e(t,n,i-t,r-n)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;oi&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return i}else{var o=1/t.direction.x,s=(this.x-t.start.x)*o,a=(this.x+this.width-t.start.x)*o;if(s>a&&(a=(e=__read([s,a],2))[0],s=e[1]),i.distance=Math.max(s,i.distance),r=Math.min(a,r),i.distance>r)return i}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return i}else{var c=1/t.direction.y,u=(this.y-t.start.y)*c,h=(this.y+this.height-t.start.y)*c;if(u>h&&(h=(n=__read([u,h],2))[0],u=n[1]),i.distance=Math.max(u,i.distance),r=Math.min(h,r),i.distance>r)return i}return i.intersected=!0,i},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(h)>=p)return t.Vector2.zero;var f=u>0?l-u:-l-u,d=h>0?p-h:-p-h;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return Math.trunc(this.x)^Math.trunc(this.y)^Math.trunc(this.width)^Math.trunc(this.height)},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.PairSet,this._previousTriggerIntersections=new t.PairSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){var e=[],n=this.getColliders();if(n.length>0)for(var i=0;i=t.Collider.lateSortOrder?e.push(c):this.notifyTriggerListeners(c,!0)),this._activeTriggerIntersections.add(c)}}if(e.length>0)for(i=0;i0)for(var n=0;n0)for(var i=0;i0)for(var o=0;o1)return!1;var u=(a.x*r.y-a.y*r.x)/s;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r,o){void 0===o&&(o=t.Vector2.zero),o.x=0,o.y=0;var s=n.sub(e),a=r.sub(i),c=s.x*a.y-s.y*a.x;if(0==c)return!1;var u=i.sub(e),h=(u.x*a.y-u.y*a.x)/c;if(h<0||h>1)return!1;var l=(u.x*s.y-u.y*s.x)/c;if(l<0||l>1)return!1;var p=e.add(s.scale(h));return o.x=p.x,o.y=p.y,!0},n.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scale(o))},n.circleToCircle=function(e,n,i,r){return t.Vector2.sqrDistance(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.sqrDistance(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setAllValues=function(t,e,n,i,r){this.collider=t,this.fraction=e,this.distance=n,this.point=i,this.normal=r},e.prototype.setValues=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.clone=function(){var t=new e;return t.setAllValues(this.collider,this.fraction,this.distance,this.point,this.normal),t},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset(),this._colliderArray[0]=null},e.clear=function(){this._spatialHash.clear()},e.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){return void 0===i&&(i=this.allLayers),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var n=t.bounds;return this._spatialHash.aabbBroadphase(n,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,n,i,r){void 0===r&&(r=e.allLayers);var o=t.bounds.getSweptBroadphaseBounds(n,i);return this._spatialHash.aabbBroadphase(o,t,r)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.linecast=function(t,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._hitArray[0].reset(),e.linecastAll(t,n,this._hitArray,i,r),this._hitArray[0]},e.linecastAll=function(t,e,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._spatialHash.linecast(t,e,n,i,r)},e.overlapRectangle=function(t,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,n),this._colliderArray[0]},e.overlapRectangleAll=function(t,n,i){return void 0===i&&(i=e.allLayers),0==n.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,n,i)},e.gravity=new t.Vector2(0,-300),e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e.debugRender=!1,e._hitArray=[new t.RaycastHit],e._colliderArray=[null],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(t,e){this._start=t.clone(),this._end=e.clone(),this._direction=this._end.sub(this._start)}return Object.defineProperty(t.prototype,"start",{get:function(){return this._start},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"end",{get:function(){return this._end},enumerable:!0,configurable:!0}),t}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestBox=new t.Box(0,0),this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds.clone();e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(e){for(var n=e.registeredPhysicsBounds.clone(),i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom),o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){var a=this.cellAtPosition(o,s);t.Insist.isNotNull(a,"从不存在碰撞器的单元格中移除碰撞器: ["+e+"]"),null!=a&&new t.List(a).remove(e)}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.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(c&&c.length>0)for(var u=0;u0)for(var c=0;c=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;ri&&(i=o,n=r)}return t[n]},n.getClosestPointOnPolygonToPoint=function(e,n){for(var i={distanceSquared:Number.MAX_VALUE,edgeNormal:t.Vector2.zero,closestPoint:t.Vector2.zero},r=0,o=0;ot.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;oi&&(n.copyFrom(r),i=o),r.setTo(-this.width/2,-this.height/2),(o=r.dot(e))>i&&(n.copyFrom(r),i=o),r.setTo(this.width/2,-this.height/2),(o=r.dot(e))>i&&(n.copyFrom(r),i=o),n},n}(t.Polygon);t.Box=e}(es||(es={})),function(t){var e=function(e){function n(t){var n=e.call(this)||this;return n.radius=t,n._originalRadius=t,n}return __extends(n,e),n.prototype.recalculateBounds=function(e){if(this.center=e.localOffset,e.shouldColliderScaleAndRotateWithTransform){var n=e.entity.transform.scale,i=1===n.x&&1===n.y,r=Math.max(n.x,n.y);if(this.radius=this._originalRadius*r,0!==e.entity.transform.rotation){var o=Math.atan2(e.localOffset.y,e.localOffset.x)*t.MathHelper.Rad2Deg,s=i?e._localOffsetLength:e.localOffset.multiply(e.entity.transform.scale).magnitude();this.center=t.MathHelper.pointOnCircle(t.Vector2.zero,s,e.entity.transform.rotation+o)}}this.position=e.transform.position.add(this.center),this.bounds=new t.Rectangle(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},n.prototype.overlaps=function(e){var i=new t.Out;if(e instanceof t.Box&&e.isUnrotated)return t.Collisions.rectToCircle(e.bounds,this.position,this.radius);if(e instanceof n)return t.Collisions.circleToCircle(this.position,this.radius,e.position,e.radius);if(e instanceof t.Polygon)return t.ShapeCollisionsCircle.circleToPolygon(this,e,i);throw new Error("overlaps of circle to "+e+" are not supported")},n.prototype.collidesWithShape=function(e,i){if(e instanceof t.Box&&e.isUnrotated)return t.ShapeCollisionsCircle.circleToBox(this,e,i);if(e instanceof n)return t.ShapeCollisionsCircle.circleToCircle(this,e,i);if(e instanceof t.Polygon)return t.ShapeCollisionsCircle.circleToPolygon(this,e,i);throw new Error("Collisions of Circle to "+e+" are not supported")},n.prototype.collidesWithLine=function(e,n,i){return t.ShapeCollisionsLine.lineToCircle(e,n,this,i)},n.prototype.getPointAlongEdge=function(e){return new t.Vector2(this.position.x+this.radius*Math.cos(e),this.position.y+this.radius*Math.sin(e))},n.prototype.containsPoint=function(t){return t.sub(this.position).lengthSquared()<=this.radius*this.radius},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.pointToCircle(e,this,n)},n}(t.Shape);t.Circle=e}(es||(es={})),function(t){var e=function(){function e(){this.normal=t.Vector2.zero,this.minimumTranslationVector=t.Vector2.zero,this.point=t.Vector2.zero}return e.prototype.reset=function(){this.collider=null,this.normal.setTo(0,0),this.minimumTranslationVector.setTo(0,0),this.point&&this.point.setTo(0,0)},e.prototype.cloneTo=function(e){e.collider=this.collider,e.normal.setTo(this.normal.x,this.normal.y),e.minimumTranslationVector.setTo(this.minimumTranslationVector.x,this.minimumTranslationVector.y),this.point&&(e.point||(e.point=new t.Vector2(0,0)),e.point.setTo(this.point.x,this.point.y))},e.prototype.removeHorizontalTranslation=function(e){if(Math.sign(this.normal.x)!==Math.sign(e.x)||0===e.x&&0!==this.normal.x){var n=this.minimumTranslationVector.magnitude()/this.normal.y;1!=Math.abs(this.normal.x)&&Math.abs(n)this.end.dot(t)?this.start:this.end},e.prototype.getClosestPoint=function(t,e){var n=e.copyFrom(this.end).sub(this.start),i=t.sub(this.start).dot(n)/n.lengthSquared();return i<0?e.copyFrom(this.start):i>1?e.copyFrom(this.end):e.copyFrom(n).multiplyScaler(i).add(this.start)},e}();t.Line=e}(es||(es={})),function(t){var e=function(){function t(){this.min=Number.MAX_VALUE,this.max=-Number.MAX_VALUE}return t.prototype.project=function(t,e){for(var n=e.points,i=t.dot(n[0]),r=i,o=1;or&&(r=a)}this.min=i,this.max=r},t.prototype.overlap=function(t){return this.max>=t.min&&t.max>=this.min},t.prototype.getOverlap=function(t){return Math.min(this.max,t.max)-Math.max(this.min,t.min)},t}();t.Projection=e}(es||(es={})),function(t){var e=function(){function e(){}return e.intersectMovingCircleBox=function(e,n,i,r){var o=n.bounds;o.inflate(e.radius,e.radius);var s=new t.Ray2D(e.position.sub(i),e.position),a=o.rayIntersects(s);if(!a.intersected&&a.distance>1)return!1;var c,u=s.start.add(s.direction.scale(r)),h=0;u.xn.bounds.right&&(h|=1),u.yn.bounds.bottom&&(h|=2);var l=c+h;return 3==l&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,n){var i=t.Vector2.zero;return i.x=0==(1&n)?e.right:e.left,i.y=0==(1&n)?e.bottom:e.top,i},e.testCircleBox=function(t,e,n){var i=e.bounds.getClosestPointOnRectangleToPoint(t.position).sub(t.position);return i.dot(i)<=t.radius*t.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(e){function n(t,n,i,r){var o=e.call(this)||this;return o.center=t,o.radius=n,o.startAngle=i,o.endAngle=r,o.angle=r-i,o.radiusSquared=n*n,o.points=o.getPoints(),o.calculateProperties(),o}return __extends(n,e),Object.defineProperty(n.prototype,"sectorAngle",{get:function(){var t=this.endAngle-this.startAngle;return t<0&&(t+=360),t},enumerable:!0,configurable:!0}),n.prototype.getCentroid=function(){var e=(Math.cos(this.startAngle)+Math.cos(this.endAngle))*this.radius/3,n=(Math.sin(this.startAngle)+Math.sin(this.endAngle))*this.radius/3;return new t.Vector2(e+this.center.x,n+this.center.y)},n.prototype.getAngle=function(){return this.startAngle},n.prototype.recalculateBounds=function(e){var n=this.center.add(e.localOffset),i=n.x-this.radius,r=n.y-this.radius,o=2*this.radius,s=2*this.radius,a=new t.Rectangle(i,r,o,s);this.bounds=a,this.center=n},n.prototype.overlaps=function(e){var n=new t.Out;if(e instanceof t.Polygon)return t.ShapeCollisionSector.sectorToPolygon(this,e,n);if(e instanceof t.Circle)return!!t.ShapeCollisionSector.sectorToCircle(this,e,n)&&(n.value.invertResult(),!0);throw new Error("overlaps of Sector to "+e+" are not supported")},n.prototype.collidesWithShape=function(e,n){if(e instanceof t.Box)return t.ShapeCollisionSector.sectorToBox(this,e,n);if(e instanceof t.Polygon)return t.ShapeCollisionSector.sectorToPolygon(this,e,n);if(e instanceof t.Circle)return t.ShapeCollisionSector.sectorToCircle(this,e,n);throw new Error("overlaps of Polygon to "+e+" are not supported")},n.prototype.collidesWithLine=function(e,n,i){var r=e.sub(this.center),o=n.sub(this.center),s=r.getAngle(),a=o.getAngle()-s;if(a>Math.PI?a-=2*Math.PI:a<-Math.PI&&(a+=2*Math.PI),a>=this.startAngle&&a<=this.endAngle){var c=r.getLength(),u=this.startAngle-s,h=c*Math.cos(u),l=c*Math.sin(u),p=new t.Vector2(h,l);if(p.isBetween(e,n)){var f=p.sub(e).getLength(),d=f/e.getDistance(n),y=p.sub(this.center).normalize(),m=p.add(this.center),g=new t.RaycastHit;return g.setValues(d,f,m,y),i.value=g,!0}}return!1},n.prototype.containsPoint=function(t){var e=t.sub(this.center);if(e.lengthSquared()>this.radiusSquared)return!1;var n=e.getAngle(),i=this.startAngle,r=(this.angle,n-i);return r<0&&(r+=2*Math.PI),!(r>this.angle)},n.prototype.pointCollidesWithShape=function(e,n){return this.containsPoint(e)?(n&&(n.value=new t.CollisionResult,n.value.normal=e.sub(this.center).normalize(),n.value.minimumTranslationVector=n.value.normal.scale(this.radius-e.sub(this.center).getLength()),n.value.point=e),!0):(n&&(n.value=null),!1)},n.prototype.getPoints=function(){for(var e=new Array(this.numberOfPoints),n=0;nn&&(n=o,i.copyFrom(this.points[r]))}return i},n}(t.Shape);t.Sector=e}(es||(es={})),function(t){var e=function(){function e(){}return e.sectorToPolygon=function(e,n,i){for(var r=n.points.length,o=!1,s=new t.Vector2,a=new t.Vector2,c=new t.Out,u=0;u0)return!1;i.value&&Math.abs(u)e.radius*e.radius&&!a)return!1;if(a)s=i.value.normal.scale(Math.sqrt(o.distanceSquared)-e.radius);else if(0===o.distanceSquared)s=i.value.normal.scale(e.radius);else{var c=Math.sqrt(o.distanceSquared);s=r.sub(o.closestPoint).scale((e.radius-c)/c*-1)}return i.value.minimumTranslationVector=s,i.value.point=o.closestPoint.add(n.position),!0},e.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scaleEqual(o))},e}();t.ShapeCollisionsCircle=e}(es||(es={})),function(t){var e=function(){function e(){}return e.lineToPoly=function(n,i,r,o){o.value=new t.RaycastHit;for(var s=t.Vector2.zero,a=t.Vector2.zero,c=Number.MAX_VALUE,u=!1,h=r.points.length-1,l=0;l1)return!1;var h=(c.x*o.y-c.y*o.x)/a;if(h<0||h>1)return!1;var l=t.add(o.scale(u));return r.x=l.x,r.y=l.y,!0},e.lineToCircle=function(e,n,i,r){r.value=new t.RaycastHit;var o=t.Vector2.distance(e,n),s=t.Vector2.divideScaler(n.sub(e),o),a=e.sub(i.position),c=a.dot(s),u=a.dot(a)-i.radius*i.radius;if(u>0&&c>0)return!1;var h=c*c-u;return!(h<0)&&(r.value.fraction=-c-Math.sqrt(h),r.value.fraction<0&&(r.value.fraction=0),r.value.point=e.add(s.scale(r.value.fraction)),r.value.distance=t.Vector2.distance(e,r.value.point),r.value.normal=r.value.point.sub(i.position).normalize(),r.value.fraction=r.value.distance/o,!0)},e}();t.ShapeCollisionsLine=e}(es||(es={})),function(t){var e=function(){function e(){}return e.pointToCircle=function(e,n,i){i.value=new t.CollisionResult;var r=t.Vector2.sqrDistance(e,n.position),o=1+n.radius;if(r0&&(o=!1),!o)return!1;(p=Math.abs(p))i.max&&(i.max=n);return i},e.intervalDistance=function(t,e,n,i){return t=0&&this._elapsedTime<=this._duration&&this.updateValue(),this._loopType!=e.none&&this._tweenState==n.complete&&0!=this._loops&&this.handleLooping(t);var i=this.calculateDeltaTime();return this.updateElapsedTime(i),this._tweenState==n.complete&&(this.handleCompletion(),!0)},i.prototype.calculateElapsedTimeExcess=function(){var t=0;return!this._isRunningInReverse&&this._elapsedTime>=this._duration?(t=this._elapsedTime-this._duration,this._elapsedTime=this._duration,this._tweenState=n.complete):this._isRunningInReverse&&this._elapsedTime<=0&&(t=0-this._elapsedTime,this._elapsedTime=0,this._tweenState=n.complete),t},i.prototype.calculateDeltaTime=function(){var e=this._isTimeScaleIndependent?t.Time.unscaledDeltaTime:t.Time.deltaTime;return e*=this._timeScale,this._isRunningInReverse&&(e=-e),e},i.prototype.updateElapsedTime=function(t){this._elapsedTime+=t,this._isRunningInReverse?(this._elapsedTime=Math.max(0,this._elapsedTime),this._elapsedTime=Math.min(this._elapsedTime,this._duration)):this._elapsedTime=Math.min(this._elapsedTime,this._duration)},i.prototype.handleCompletion=function(){this._completionHandler&&this._completionHandler(this),null!=this._nextTween&&(this._nextTween.start(),this._nextTween=null)},i.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._target=null,this._nextTween=null)},i.prototype.isRunning=function(){return this._tweenState==n.running},i.prototype.start=function(){this._isFromValueOverridden||(this._fromValue=this._target.getTweenedValue()),this._tweenState==n.complete&&(this._tweenState=n.running,t.TweenManager.addTween(this))},i.prototype.pause=function(){this._tweenState=n.paused},i.prototype.resume=function(){this._tweenState=n.running},i.prototype.stop=function(i){void 0===i&&(i=!1),this._tweenState=n.complete,i?(this._elapsedTime=this._isRunningInReverse?0:this._duration,this._loopType=e.none,this._loops=0):t.TweenManager.removeTween(this)},i.prototype.jumpToElapsedTime=function(e){this._elapsedTime=t.MathHelper.clamp(e,0,this._duration),this.updateValue()},i.prototype.reverseTween=function(){this._isRunningInReverse=!this._isRunningInReverse},i.prototype.waitForCompletion=function(){return __generator(this,function(t){switch(t.label){case 0:return this._tweenState==n.complete?[3,2]:[4,null];case 1:return t.sent(),[3,0];case 2:return[2]}})},i.prototype.getTargetObject=function(){return this._target.getTargetObject()},i.prototype.resetState=function(){this.context=null,this._completionHandler=this._loopCompleteHandler=null,this._isFromValueOverridden=!1,this._isTimeScaleIndependent=!1,this._tweenState=n.complete,this._isRelative=!1,this._easeType=t.TweenManager.defaultEaseType,null!=this._nextTween&&(this._nextTween.recycleSelf(),this._nextTween=null),this._delay=0,this._duration=0,this._timeScale=1,this._elapsedTime=0,this._loopType=e.none,this._delayBetweenLoops=0,this._loops=0,this._isRunningInReverse=!1},i.prototype.initialize=function(t,e,n){this.resetState(),this._target=t,this._toValue=e,this._duration=n},i.prototype.handleLooping=function(t){this._loops--,this._loopType==e.pingpong&&this.reverseTween(),this._loopType!=e.restartFromBeginning&&this._loops%2!=0||this._loopCompleteHandler&&this._completionHandler(this),0!=this._loops&&(this._tweenState=n.running,this._loopType==e.restartFromBeginning?this._elapsedTime=t-this._delayBetweenLoops:this._isRunningInReverse?this._elapsedTime+=this._delayBetweenLoops-t:this._elapsedTime=t-this._delayBetweenLoops,0==this._delayBetweenLoops&&t>0&&this.updateValue())},i}();t.Tween=i}(es||(es={})),function(t){var e=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheNumberTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue+=this._fromValue,this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheNumberTweens&&t.Pool.free(n,this)},n}(t.Tween);t.NumberTween=e;var n=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheVector2Tweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue.add(this._fromValue),this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheVector2Tweens&&t.Pool.free(n,this)},n}(t.Tween);t.Vector2Tween=n;var i=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheRectTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue=new t.Rectangle(this._toValue.x+this._fromValue.x,this._toValue.y+this._fromValue.y,this._toValue.width+this._fromValue.width,this._toValue.height+this._fromValue.height),this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheRectTweens&&t.Pool.free(n,this)},n}(t.Tween);t.RectangleTween=i}(es||(es={})),function(t){var e;!function(t){t[t.position=0]="position",t[t.localPosition=1]="localPosition",t[t.scale=2]="scale",t[t.localScale=3]="localScale",t[t.rotationDegrees=4]="rotationDegrees",t[t.localRotationDegrees=5]="localRotationDegrees"}(e=t.TransformTargetType||(t.TransformTargetType={}));var n=function(n){function i(){return null!==n&&n.apply(this,arguments)||this}return __extends(i,n),i.prototype.setTweenedValue=function(t){switch(this._targetType){case e.position:this._transform.position=t;break;case e.localPosition:this._transform.localPosition=t;break;case e.scale:this._transform.scale=t;break;case e.localScale:this._transform.localScale=t;break;case e.rotationDegrees:this._transform.rotationDegrees=t.x;case e.localRotationDegrees:this._transform.localRotationDegrees=t.x}},i.prototype.getTweenedValue=function(){switch(this._targetType){case e.position:return this._transform.position;case e.localPosition:return this._transform.localPosition;case e.scale:return this._transform.scale;case e.localScale:return this._transform.localScale;case e.rotationDegrees:return new t.Vector2(this._transform.rotationDegrees,this._transform.rotationDegrees);case e.localRotationDegrees:return new t.Vector2(this._transform.localRotationDegrees,0)}},i.prototype.getTargetObject=function(){return this._transform},i.prototype.setTargetAndType=function(t,e){this._transform=t,this._targetType=e},i.prototype.updateValue=function(){this._targetType!=e.rotationDegrees&&this._targetType!=e.localRotationDegrees||this._isRelative?this.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration)):this.setTweenedValue(t.Lerps.easeAngle(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},i.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._target=null,this._nextTween=null,this._transform=null,t.Pool.free(t.Vector2Tween,this))},i}(t.Vector2Tween);t.TransformVector2Tween=n}(es||(es={})),function(t){var e;!function(t){t[t.linear=0]="linear",t[t.sineIn=1]="sineIn",t[t.sineOut=2]="sineOut",t[t.sineInOut=3]="sineInOut",t[t.quadIn=4]="quadIn",t[t.quadOut=5]="quadOut",t[t.quadInOut=6]="quadInOut",t[t.quintIn=7]="quintIn",t[t.quintOut=8]="quintOut",t[t.quintInOut=9]="quintInOut",t[t.cubicIn=10]="cubicIn",t[t.cubicOut=11]="cubicOut",t[t.cubicInOut=12]="cubicInOut",t[t.quartIn=13]="quartIn",t[t.quartOut=14]="quartOut",t[t.quartInOut=15]="quartInOut",t[t.expoIn=16]="expoIn",t[t.expoOut=17]="expoOut",t[t.expoInOut=18]="expoInOut",t[t.circleIn=19]="circleIn",t[t.circleOut=20]="circleOut",t[t.circleInOut=21]="circleInOut",t[t.elasticIn=22]="elasticIn",t[t.elasticOut=23]="elasticOut",t[t.elasticInOut=24]="elasticInOut",t[t.punch=25]="punch",t[t.backIn=26]="backIn",t[t.backOut=27]="backOut",t[t.backInOut=28]="backInOut",t[t.bounceIn=29]="bounceIn",t[t.bounceOut=30]="bounceOut",t[t.bounceInOut=31]="bounceInOut"}(e=t.EaseType||(t.EaseType={}));var n=function(){function n(){}return n.oppositeEaseType=function(t){switch(t){case e.linear:return t;case e.backIn:return e.backOut;case e.backOut:return e.backIn;case e.backInOut:return t;case e.bounceIn:return e.bounceOut;case e.bounceOut:return e.bounceIn;case e.bounceInOut:return t;case e.circleIn:return e.circleOut;case e.circleOut:return e.circleIn;case e.circleInOut:return t;case e.cubicIn:return e.cubicOut;case e.cubicOut:return e.cubicIn;case e.circleInOut:case e.punch:return t;case e.expoIn:return e.expoOut;case e.expoOut:return e.expoIn;case e.expoInOut:return t;case e.quadIn:return e.quadOut;case e.quadOut:return e.quadIn;case e.quadInOut:return t;case e.quartIn:return e.quadOut;case e.quartOut:return e.quartIn;case e.quadInOut:return t;case e.sineIn:return e.sineOut;case e.sineOut:return e.sineIn;case e.sineInOut:default:return t}},n.ease=function(n,i,r){switch(n){case e.linear:return t.Easing.Linear.easeNone(i,r);case e.backIn:return t.Easing.Back.easeIn(i,r);case e.backOut:return t.Easing.Back.easeOut(i,r);case e.backInOut:return t.Easing.Back.easeInOut(i,r);case e.bounceIn:return t.Easing.Bounce.easeIn(i,r);case e.bounceOut:return t.Easing.Bounce.easeOut(i,r);case e.bounceInOut:return t.Easing.Bounce.easeInOut(i,r);case e.circleIn:return t.Easing.Circular.easeIn(i,r);case e.circleOut:return t.Easing.Circular.easeOut(i,r);case e.circleInOut:return t.Easing.Circular.easeInOut(i,r);case e.cubicIn:return t.Easing.Cubic.easeIn(i,r);case e.cubicOut:return t.Easing.Cubic.easeOut(i,r);case e.cubicInOut:return t.Easing.Cubic.easeInOut(i,r);case e.elasticIn:return t.Easing.Elastic.easeIn(i,r);case e.elasticOut:return t.Easing.Elastic.easeOut(i,r);case e.elasticInOut:return t.Easing.Elastic.easeInOut(i,r);case e.punch:return t.Easing.Elastic.punch(i,r);case e.expoIn:return t.Easing.Exponential.easeIn(i,r);case e.expoOut:return t.Easing.Exponential.easeOut(i,r);case e.expoInOut:return t.Easing.Exponential.easeInOut(i,r);case e.quadIn:return t.Easing.Quadratic.easeIn(i,r);case e.quadOut:return t.Easing.Quadratic.easeOut(i,r);case e.quadInOut:return t.Easing.Quadratic.easeInOut(i,r);case e.quintIn:return t.Easing.Quintic.easeIn(i,r);case e.quintOut:return t.Easing.Quintic.easeOut(i,r);case e.quintInOut:return t.Easing.Quintic.easeInOut(i,r);case e.sineIn:return t.Easing.Sinusoidal.easeIn(i,r);case e.sineOut:return t.Easing.Sinusoidal.easeOut(i,r);case e.sineInOut:return t.Easing.Sinusoidal.easeInOut(i,r);default:return t.Easing.Linear.easeNone(i,r)}},n}();t.EaseHelper=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(e){function n(){var t=e.call(this)||this;return t._activeTweens=[],t._tempTweens=[],n._instance=t,t}return __extends(n,e),Object.defineProperty(n,"activeTweens",{get:function(){return this._instance._activeTweens},enumerable:!0,configurable:!0}),n.prototype.update=function(){this._isUpdating=!0;for(var e=this._activeTweens.length-1;e>=0;--e){var n=this._activeTweens[e];n.tick()&&this._tempTweens.push(n)}this._isUpdating=!1;for(e=0;e=0;--e)n._instance._activeTweens[e].stop(t)},n.allTweensWithContext=function(t){for(var e=[],i=0;i=0;--i)n._instance._activeTweens[i].context==t&&n._instance._activeTweens[i].stop(e)},n.allTweenWithTarget=function(t){for(var e=[],i=0;i=0;--i)if(n._instance._activeTweens[i]){var r=n._instance._activeTweens[i];r.getTargetObject()==t&&r.stop(e)}},n.defaultEaseType=t.EaseType.quartIn,n.removeAllTweensOnLevelLoad=!1,n.cacheNumberTweens=!0,n.cacheVector2Tweens=!0,n.cacheColorTweens=!0,n.cacheRectTweens=!1,n}(t.GlobalManager);t.TweenManager=e}(es||(es={})),function(t){!function(t){var e=function(){function t(){}return t.easeNone=function(t,e){return t/e},t}();t.Linear=e;var n=function(){function t(){}return t.easeIn=function(t,e){return(t/=e)*t},t.easeOut=function(t,e){return-1*(t/=e)*(t-2)},t.easeInOut=function(t,e){return(t/=e/2)<1?.5*t*t:-.5*(--t*(t-2)-1)},t}();t.Quadratic=n;var i=function(){function t(){}return t.easeIn=function(t,e,n){return void 0===n&&(n=1.70158),(t/=e)*t*((n+1)*t-n)},t.easeOut=function(t,e,n){return void 0===n&&(n=1.70158),(t=t/e-1)*t*((n+1)*t+n)+1},t.easeInOut=function(t,e,n){return void 0===n&&(n=1.70158),(t/=e/2)<1?t*t*(((n*=1.525)+1)*t-n)*.5:.5*((t-=2)*t*(((n*=1.525)+1)*t+n)+2)},t}();t.Back=i;var r=function(){function t(){}return t.easeOut=function(t,e){return(t/=e)<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},t.easeIn=function(t,e){return 1-this.easeOut(e-t,e)},t.easeInOut=function(t,e){return t= 2");if(t.sort(function(t,e){return t.t-e.t}),0!==t[0].t)throw new Error("curve must start with 0");if(1!==t[t.length-1].t)throw new Error("curve must end with 1");this._points=t}return Object.defineProperty(e.prototype,"points",{get:function(){return this._points},enumerable:!0,configurable:!0}),e.prototype.lerp=function(e){for(var n=1;n>7,n+=n<<3,n^=n>>17,n+=n<<5},t}();t.Hash=e}(es||(es={})),function(t){var e=function(){function t(){this._listeners=[]}return t.prototype.addListener=function(t,e){-1===this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t})&&this._listeners.push({caller:t,callback:e})},t.prototype.removeListener=function(t,e){var n=this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t});n>=0&&this._listeners.splice(n,1)},t.prototype.clearListener=function(){this._listeners=[]},t.prototype.clearListenerWithCaller=function(t){for(var e=this._listeners.length-1;e>=0;e--){this._listeners[e].caller===t&&this._listeners.splice(e,1)}},t.prototype.notify=function(){for(var t,e=[],n=0;n=0;i--){var r=this._listeners[i];r.caller?(t=r.callback).call.apply(t,__spread([r.caller],e)):r.callback.apply(r,__spread(e))}},t}();t.Observable=e;var n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e){t.prototype.notify.call(this,e)},e}(e);t.ObservableT=n;var i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e,n){t.prototype.notify.call(this,e,n)},e}(e);t.ObservableTT=i;var r=function(){function t(t,n){this.bindAction(t,n),this._onExec=new e}return t.prototype.bindAction=function(t,e){this._caller=t,this._action=e},t.prototype.dispatch=function(){for(var t,e=[],n=0;n3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],u=n[s],h=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,u,h)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,u,h)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.length>8&255]+e[t>>16&255]+e[t>>24&255]+"-"+e[255&n]+e[n>>8&255]+"-"+e[n>>16&15|64]+e[n>>24&255]+"-"+e[63&i|128]+e[i>>8&255]+"-"+e[i>>16&255]+e[i>>24&255]+e[255&r]+e[r>>8&255]+e[r>>16&255]+e[r>>24&255]},t}();t.UUID=n}(es||(es={})),function(t){t.getClassName=function(t){return t.className||t.name}}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return __spread(this._completeSlices,[this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(es||(es={})),function(t){var e=function(){function t(t){void 0===t&&(t=64),this.size_=0,this.length=0,this.array=[],this.length=t}return t.prototype.removeAt=function(t){var e=this.array[t];return this.array[t]=this.array[--this.size_],this.array[this.size_]=null,e},t.prototype.remove=function(t){var e,n=this.size_;for(e=0;e0){var t=this.array[--this.size_];return this.array[this.size_]=null,t}return null},t.prototype.contains=function(t){var e,n;for(e=0,n=this.size_;n>e;e++)if(t===this.array[e])return!0;return!1},t.prototype.removeAll=function(t){var e,n,i,r,o=!1;for(e=0,i=t.size();e=this.length)throw new Error("ArrayIndexOutOfBoundsException");return this.array[t]},t.prototype.safeGet=function(t){return t>=this.length&&this.grow(7*t/4+1),this.array[t]},t.prototype.size=function(){return this.size_},t.prototype.getCapacity=function(){return this.length},t.prototype.isIndexWithinBounds=function(t){return t=this.length&&this.grow(2*t),this.size_=t+1,this.array[t]=e},t.prototype.grow=function(t){void 0===t&&(t=1+~~(3*this.length/2)),this.length=~~t},t.prototype.ensureCapacity=function(t){t>=this.length&&this.grow(2*t)},t.prototype.clear=function(){var t,e;for(t=0,e=this.size_;te;e++)this.add(t.get(e))},t}();t.Bag=e}(es||(es={})),function(t){var e=function(){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 n=0;nthis._objectQueue.get(t).length;)this._objectQueue.get(t).splice(0,1)},t.clearCache=function(t){this.checkCreate(t),this._objectQueue.get(t).length=0},t.obtain=function(t){return this.checkCreate(t),this._objectQueue.get(t).length>0?this._objectQueue.get(t).shift():[]},t.free=function(t,e){this.checkCreate(t),this._objectQueue.get(t).push(e),e.length=0},t.checkCreate=function(t){this._objectQueue.has(t)||this._objectQueue.set(t,[])},t._objectQueue=new Map,t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first===t.first&&this.second===t.second},t}();t.Pair=e}(es||(es={})),function(t){var e=function(){function t(){this._all=new Array}return Object.defineProperty(t.prototype,"all",{get:function(){return this._all},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return this._all.findIndex(function(e){return e.equals(t)})>-1},t.prototype.add=function(t){this.has(t)||this._all.push(t)},t.prototype.remove=function(t){var e=this._all.findIndex(function(e){return e.equals(t)});if(e>-1){var n=this._all[e];this._all[e]=this._all[this._all.length-1],this._all[this._all.length-1]=n,this._all=this._all.slice(0,this._all.length-1)}},t.prototype.clear=function(){this._all=[]},t.prototype.union=function(t){var e=t.all;if(e.length>0)for(var n=0;n0)for(var n=0;n0)for(var i=0;i0?e.pop():new t},e.free=function(e,n){this.checkCreate(e),this._objectQueue.get(e).push(n),t.isIPoolable(n)&&n.reset()},e.checkCreate=function(t){this._objectQueue.has(t)||this._objectQueue.set(t,[])},e._objectQueue=new Map,e}();t.Pool=e,t.isIPoolable=function(t){return"function"==typeof t.reset}}(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.clearAllCoroutines=function(){for(var n=0;n=0;r--){var o=n[r];if(o.isDone)t.Pool.free(e,o),n.splice(r,1);else{var s=o.waitForCoroutine;if(null!=s){if(!s.isDone){i.push(o);continue}o.waitForCoroutine=null}var a=o.waitTimer;a>0?(o.waitTimer=a-(o.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime),i.push(o)):this.tickCoroutine(o)&&i.push(o)}}n.push.apply(n,__spread(i)),i.length=0,this._isInUpdate=!1},i.prototype.tickCoroutine=function(n){var i=n.enumerator.next(),r=i.value;return i.done||n.isDone?(t.Pool.free(e,n),!1):!r||(r instanceof t.WaitForSeconds?(n.waitTimer=r.waitTime,!0):"number"==typeof r?(n.waitTimer=r,!0):"string"==typeof r?"break"!==r||(t.Pool.free(e,n),!1):"function"==typeof r?(n.waitForCoroutine=this.startCoroutine(r),!0):!(r instanceof e)||(n.waitForCoroutine=r,!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),u=Math.abs(this.freeRectangles[s].height-n),h=Math.min(c,u);(a=n&&this.freeRectangles[s].height>=e){c=Math.abs(this.freeRectangles[s].width-n),u=Math.abs(this.freeRectangles[s].height-e),h=Math.min(c,u);(a=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y)return!1;if(e.xt.x){if(e.y>t.y&&e.yt.y){var n;if(e.x>t.x&&e.x=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height},e}();t.MaxRectsBinPack=e}(es||(es={})),function(t){var e=function(){function e(){}return e.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},e.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},e.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},e.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},e.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},e.cloneList=function(t){return t?t.slice(0,t.length):null},e.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},e.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},e.shuffle=function(e){for(var n=e.length;n>1;){n--;var i=t.RandomUtils.randint(0,n+1),r=e[i];e[i]=e[n],e[n]=r}},e.addIfNotPresent=function(e,n){return!new t.List(e).contains(n)&&(e.push(n),!0)},e.lastItem=function(t){return t[t.length-1]},e.randomItem=function(e){return e[t.RandomUtils.randint(0,e.length-1)]},e.randomItems=function(e,n,i){for(var r=new Set;r.size!=i;){var o=this.randomItem(n);r.has(o)||r.add(o)}var s=t.ListPool.obtain(e);return r.forEach(function(t){return s.push(t)}),s},e}();t.ArrayUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],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=[],u=0;u>2,o=(3&e)<<4|(n=t.charCodeAt(u++))>>4,s=(15&n)<<2|(i=t.charCodeAt(u++))>>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}();t.RandomUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,i.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e.boundsFromPolygonVector=function(e){for(var n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,s=0;sr&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(n,i),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,n){return new t.Rectangle(e.x,e.y,n.x-e.x,n.y-e.y)},e.getSweptBroadphaseBounds=function(e,n,i){var r=t.Rectangle.empty;return r.x=n>0?e.x:e.x+n,r.y=i>0?e.y:e.y+i,r.width=n>0?n+e.width:e.width-n,r.height=i>0?i+e.height:e.height-i,r},e.prototype.collisionCheck=function(t,e,n,i){n.value=i.value=0;var r=e.x-(t.x+t.width),o=e.x+e.width-t.x,s=e.y-(t.y+t.height),a=e.y+e.height-t.y;return!(r>0||o<0||s>0||a<0)&&(n.value=Math.abs(r)=l||Math.abs(h)>=p)return t.Vector2.zero;var f=u>0?l-u:-l-u,d=h>0?p-h:-p-h;return new t.Vector2(f,d)},e.getClosestPointOnBoundsToOrigin=function(e){var n=this.getMax(e),i=Math.abs(e.location.x),r=new t.Vector2(e.location.x,0);return Math.abs(n.x)r&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(t.MathHelper.toInt(n),t.MathHelper.toInt(i)),new t.Vector2(t.MathHelper.toInt(r),t.MathHelper.toInt(o)))},e.calculateBounds=function(e,n,i,r,o,s,a,c){if(0==s)e.x=t.MathHelper.toInt(n.x+i.x-r.x*o.x),e.y=t.MathHelper.toInt(n.y+i.y-r.y*o.y),e.width=t.MathHelper.toInt(a*o.x),e.height=t.MathHelper.toInt(c*o.y);else{var u=n.x+i.x,h=n.y+i.y,l=new t.Matrix2D;t.Matrix2D.createTranslation(-u-r.x,-h-r.y,l),t.Matrix2D.createScale(o.x,o.y,void 0),l=l.multiply(void 0),t.Matrix2D.createRotation(s,void 0),l=l.multiply(void 0),t.Matrix2D.createTranslation(u,h,void 0),l=l.multiply(void 0);var p=new t.Vector2(u,h),f=new t.Vector2(u+a,h),d=new t.Vector2(u,h+c),y=new t.Vector2(u+a,h+c);t.Vector2Ext.transformR(p,l,p),t.Vector2Ext.transformR(f,l,f),t.Vector2Ext.transformR(d,l,d),t.Vector2Ext.transformR(y,l,y);var m=t.MathHelper.toInt(Math.min(p.x,y.x,f.x,d.x)),g=t.MathHelper.toInt(Math.max(p.x,y.x,f.x,d.x)),_=t.MathHelper.toInt(Math.min(p.y,y.y,f.y,d.y)),v=t.MathHelper.toInt(Math.max(p.y,y.y,f.y,d.y));e.location=new t.Vector2(m,_),e.width=t.MathHelper.toInt(g-m),e.height=t.MathHelper.toInt(v-_)}},e.scale=function(e,n){e.x=t.MathHelper.toInt(e.x*n.x),e.y=t.MathHelper.toInt(e.y*n.y),e.width=t.MathHelper.toInt(e.width*n.x),e.height=t.MathHelper.toInt(e.height*n.y)},e.translate=function(t,e){t.location.addEqual(e)},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function t(){}return t.premultiplyAlpha=function(t){for(var e=t[0],n=0;nt.MathHelper.Epsilon?e.divideScaler(n):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){var e=this.sum(t),n=this.count(t);return 0===n?NaN:e/n},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]:null},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){void 0===i&&(i=t.keyComparer(e,!0));var r=this._elements.slice();return r.sort(i),new n(r,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){var e=this.indexOf(t);return-1!==e&&(this.removeAt(e),!0)},e.prototype.removeAll=function(n){return new e(this.where(t.negate(n)).toArray())},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){var o=n.select(t).elementAt(r);return e.addRange(o.toArray())},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.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.bind(n)},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),this._timers.splice(t,1))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Component.ts b/source/src/ECS/Component.ts index da3ae7d3..19e32e52 100644 --- a/source/src/ECS/Component.ts +++ b/source/src/ECS/Component.ts @@ -117,23 +117,48 @@ module es { return this; } + /** + * 添加组件 + * @param component 要添加的组件实例 + * @returns 返回添加的组件实例 + */ public addComponent(component: T): T { return this.entity.addComponent(component); } - public getComponent(type: new (...args: any[])=>T): T { + /** + * 获取组件 + * @param type 组件类型 + * @returns 返回获取到的组件实例 + */ + public getComponent(type: new (...args: any[]) => T): T { return this.entity.getComponent(type); } - public getComponents(typeName: any, componentList?: any[]) { + /** + * 获取一组指定类型的组件 + * @param typeName 组件类型名 + * @param componentList 可选参数,存储组件实例的数组 + * @returns 返回指定类型的组件实例数组 + */ + public getComponents(typeName: any, componentList?: any[]): any[] { return this.entity.getComponents(typeName, componentList); } - public hasComponent(type: new (...args: any[])=>Component) { + /** + * 判断实体是否包含指定类型的组件 + * @param type 组件类型 + * @returns 如果实体包含指定类型的组件,返回 true,否则返回 false。 + */ + public hasComponent(type: new (...args: any[]) => Component): boolean { return this.entity.hasComponent(type); } - public removeComponent(component?: Component) { + /** + * 删除组件 + * @param component 可选参数,要删除的组件实例。如果未指定该参数,则删除当前实例上的组件。 + */ + public removeComponent(component?: Component): void { if (component) { this.entity.removeComponent(component); } else { diff --git a/source/src/ECS/Systems/EntitySystem.ts b/source/src/ECS/Systems/EntitySystem.ts index 411147f0..a9e9ffdd 100644 --- a/source/src/ECS/Systems/EntitySystem.ts +++ b/source/src/ECS/Systems/EntitySystem.ts @@ -1,7 +1,7 @@ /// module es { /** - * 追踪实体的子集,但不实现任何排序或迭代。 + * 实体系统的基类,用于处理一组实体。 */ export abstract class EntitySystem { private _entities: Entity[] = []; @@ -9,7 +9,7 @@ module es { private _startTime = 0; private _endTime = 0; private _useTime = 0; - + /** 获取系统在当前帧所消耗的时间 仅在debug模式下生效 */ public get useTime() { return this._useTime; @@ -53,9 +53,9 @@ module es { /** * 设置更新时序 - * @param order + * @param order 更新时序 */ - public setUpdateOrder(order: number) { + public setUpdateOrder(order: number) { this._updateOrder = order; this.scene.entityProcessors.setDirty(); } @@ -80,14 +80,16 @@ module es { this.onAdded(entity); } - public onAdded(entity: Entity) { } + public onAdded(entity: Entity) { + } public remove(entity: Entity) { new es.List(this._entities).remove(entity); this.onRemoved(entity); } - public onRemoved(entity: Entity) { } + public onRemoved(entity: Entity) { + } public update() { if (this.checkProcessing()) { @@ -107,21 +109,23 @@ module es { * 在系统处理开始前调用 * 在下一个系统开始处理或新的处理回合开始之前(以先到者为准),使用此方法创建的任何实体都不会激活 */ - protected begin() { + protected begin() { if (!Core.Instance.debug) return; this._startTime = Date.now(); } - protected process(entities: Entity[]) { } + protected process(entities: Entity[]) { + } - protected lateProcess(entities: Entity[]) { } + protected lateProcess(entities: Entity[]) { + } /** * 系统处理完毕后调用 */ - protected end() { + protected end() { if (!Core.Instance.debug) return; @@ -131,7 +135,7 @@ module es { /** * 系统是否需要处理 - * + * * 在启用系统时有用,但仅偶尔需要处理 * 这只影响处理,不影响事件或订阅列表 * @returns 如果系统应该处理,则为true,如果不处理则为false。 diff --git a/source/src/ECS/Systems/IntervalIteratingSystem.ts b/source/src/ECS/Systems/IntervalIteratingSystem.ts index ffde462b..5d9fd306 100644 --- a/source/src/ECS/Systems/IntervalIteratingSystem.ts +++ b/source/src/ECS/Systems/IntervalIteratingSystem.ts @@ -1,13 +1,10 @@ /// module es { /** - * 每x个ticks处理一个实体的子集 - * - * 典型的用法是每隔一定的时间间隔重新生成弹药或生命值 - * 而无需在每个游戏循环中都进行 - * 而是每100毫秒一次或每秒 + * 定时遍历处理实体的系统,用于按指定的时间间隔遍历并处理感兴趣的实体。 */ export abstract class IntervalIteratingSystem extends IntervalSystem { + constructor(matcher: Matcher, interval: number) { super(matcher, interval); } @@ -18,6 +15,10 @@ module es { */ public abstract processEntity(entity: Entity); + /** + * 遍历处理实体。 + * @param entities 本系统感兴趣的实体列表 + */ protected process(entities: Entity[]) { entities.forEach(entity => this.processEntity(entity)); } diff --git a/source/src/ECS/Utils/Bits.ts b/source/src/ECS/Utils/Bits.ts index e0af7f3b..09bf9eef 100644 --- a/source/src/ECS/Utils/Bits.ts +++ b/source/src/ECS/Utils/Bits.ts @@ -1,14 +1,28 @@ module es { + /** + * 位操作类,用于操作一个位数组。 + */ export class Bits { - private _bit: {[index: number]: number} = {}; + private _bit: { [index: number]: number } = {}; + /** + * 设置指定位置的位值。 + * @param index 位置索引 + * @param value 位值(0 或 1) + */ public set(index: number, value: number) { this._bit[index] = value; } + /** + * 获取指定位置的位值。 + * @param index 位置索引 + * @returns 位值(0 或 1) + */ public get(index: number): number { let v = this._bit[index]; return v == null ? 0 : v; } } + } \ No newline at end of file diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index ac6088ac..e4a0734e 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -2,37 +2,61 @@ module es { export class ComponentList { /** - * 组件列表的全局updateOrder排序 + * 比较IUpdatable对象的更新顺序。 */ public static compareUpdatableOrder: IUpdatableComparer = new IUpdatableComparer(); public _entity: Entity; - /** - * 添加到实体的组件列表 + * 实体的组件列表。 */ public _components: Component[] = []; + /** - * 所有需要更新的组件列表 + * 可更新的组件列表。 */ public _updatableComponents: IUpdatable[] = []; + /** - * 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 + * 等待添加到实体的组件列表。 */ public _componentsToAdd: { [index: number]: Component } = {}; + /** - * 标记要删除此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 + * 等待从实体中移除的组件列表。 */ public _componentsToRemove: { [index: number]: Component } = {}; - public _componentsToAddList: Component[] = []; - public _componentsToRemoveList: Component[] = []; - public _tempBufferList: Component[] = []; + /** - * 用于确定是否需要对该框架中的组件进行排序的标志 + * 等待添加到实体的组件列表(作为数组)。 + */ + public _componentsToAddList: Component[] = []; + + /** + * 等待从实体中移除的组件列表(作为数组)。 + */ + public _componentsToRemoveList: Component[] = []; + + /** + * 临时的组件缓冲列表。 + */ + public _tempBufferList: Component[] = []; + + /** + * 指示组件列表是否已排序的标志。 */ public _isComponentListUnsorted: boolean; + + /** + * 按组件类型组织的组件列表字典。 + */ private componentsByType = new Map Component, es.Component[]>(); + + /** + * 按组件类型组织的等待添加到实体的组件列表字典。 + */ private componentsToAddByType = new Map Component, es.Component[]>(); + constructor(entity: Entity) { this._entity = entity; } @@ -49,32 +73,45 @@ module es { this._isComponentListUnsorted = true; } + /** + * 将组件添加到实体的组件列表中,并添加到组件类型字典中。 + * @param component 要添加的组件。 + */ public add(component: Component) { + // 将组件添加到_componentsToAdd和_componentsToAddList中,并添加到相应的组件类型字典中 this._componentsToAdd[component.id] = component; this._componentsToAddList.push(component); this.addComponentsToAddByType(component); } + /** + * 从实体的组件列表中移除组件,并从相应的组件类型字典中移除组件。 + * @param component 要从实体中移除的组件。 + */ public remove(component: Component) { + // 如果组件在_componentsToAdd中,则将其从_componentsToAddList中移除,并从相应的组件类型字典中移除组件 if (this._componentsToAdd[component.id]) { - let index = this._componentsToAddList.findIndex(c => c.id == component.id); - if (index != -1) + const index = this._componentsToAddList.findIndex((c) => c.id === component.id); + if (index !== -1) { this._componentsToAddList.splice(index, 1); + } delete this._componentsToAdd[component.id]; this.removeComponentsToAddByType(component); return; } + // 如果组件不在_componentsToAdd中,则将其添加到_componentsToRemove和_componentsToRemoveList中 this._componentsToRemove[component.id] = component; this._componentsToRemoveList.push(component); } + /** * 立即从组件列表中删除所有组件 */ public removeAllComponents() { if (this._components.length > 0) { - for (let i = 0, s = this._components.length; i < s; ++ i) { + for (let i = 0, s = this._components.length; i < s; ++i) { this.handleRemove(this._components[i]); } } @@ -89,193 +126,272 @@ module es { this._componentsToRemoveList.length = 0; } + /** + * 从实体的所有组件上注销并从相关数据结构中删除它们。 + */ public deregisterAllComponents() { if (this._components.length > 0) { - for (let i = 0, s = this._components.length; i < s; ++ i) { - let component = this._components[i]; - if (!component) continue; - + for (const component of this._components) { // 处理IUpdatable - if (isIUpdatable(component)) + if (isIUpdatable(component)) { + // 创建一个新的List实例,从_updatableComponents中移除组件,以避免并发修改异常 new es.List(this._updatableComponents).remove(component); - + } + + // 从位掩码中减去组件类型的索引,通知实体处理器一个组件已被移除 this.decreaseBits(component); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); } } } + /** + * 注册实体的所有组件,并将它们添加到相应的数据结构中。 + */ public registerAllComponents() { if (this._components.length > 0) { - for (let i = 0, s = this._components.length; i < s; ++ i) { - let component = this._components[i]; - if (isIUpdatable(component)) + for (const component of this._components) { + if (isIUpdatable(component)) { + // 如果组件是可更新的,则将其添加到_updatableComponents中 this._updatableComponents.push(component); - + } + + // 将组件类型的索引添加到实体的位掩码中,通知实体处理器一个组件已被添加 this.addBits(component); this._entity.scene.entityProcessors.onComponentAdded(this._entity); } } } + /** + * 从实体的位掩码中减去组件类型的索引。 + * @param component 要从实体中删除的组件。 + */ private decreaseBits(component: Component) { - let bits = this._entity.componentBits; - let typeIndex = ComponentTypeManager.getIndexFor(TypeUtils.getType(component)); + const bits = this._entity.componentBits; + + // 获取组件类型的索引,将其对应位掩码减1 + const typeIndex = ComponentTypeManager.getIndexFor(TypeUtils.getType(component)); bits.set(typeIndex, bits.get(typeIndex) - 1); } + /** + * 在实体的位掩码中添加组件类型的索引。 + * @param component 要添加到实体的组件。 + */ private addBits(component: Component) { - let bits = this._entity.componentBits; - let typeIndex = ComponentTypeManager.getIndexFor(TypeUtils.getType(component)); + const bits = this._entity.componentBits; + + // 获取组件类型的索引,将其对应位掩码加1 + const typeIndex = ComponentTypeManager.getIndexFor(TypeUtils.getType(component)); bits.set(typeIndex, bits.get(typeIndex) + 1); } /** - * 处理任何需要删除或添加的组件 + * 更新实体的组件列表和相关数据结构。 + * 如果有组件要添加或删除,它将相应地更新组件列表和其他数据结构。 */ public updateLists() { + // 处理要删除的组件 if (this._componentsToRemoveList.length > 0) { - for (let i = 0, l = this._componentsToRemoveList.length; i < l; ++ i) { - let component = this._componentsToRemoveList[i]; + for (const component of this._componentsToRemoveList) { + // 从实体中删除组件,从组件列表和相关数据结构中删除组件 this.handleRemove(component); - let index = this._components.findIndex(c => c.id == component.id); - if (index != -1) + + // 从_components数组中删除组件 + const index = this._components.findIndex((c) => c.id === component.id); + if (index !== -1) { this._components.splice(index, 1); + } + + // 从组件类型字典中删除组件 this.removeComponentsByType(component); } - + + // 清空_componentsToRemove和_componentsToRemoveList this._componentsToRemove = {}; this._componentsToRemoveList.length = 0; } + // 处理要添加的组件 if (this._componentsToAddList.length > 0) { - for (let i = 0, l = this._componentsToAddList.length; i < l; ++ i) { - let component = this._componentsToAddList[i]; - - if (isIUpdatable(component)) + for (const component of this._componentsToAddList) { + // 如果组件可以更新,则添加到可更新组件列表中 + if (isIUpdatable(component)) { this._updatableComponents.push(component); - + } + + // 更新实体的组件位掩码,通知实体处理器一个组件已经添加 this.addBits(component); this._entity.scene.entityProcessors.onComponentAdded(this._entity); - + + // 将组件添加到相应类型的fastList中,将组件添加到_components数组中 this.addComponentsByType(component); this._components.push(component); + + // 将组件添加到_tempBufferList中,稍后调用onAddedToEntity和onEnabled this._tempBufferList.push(component); } - - // 在调用onAddedToEntity之前清除,以防添加更多组件 + + // 清空_componentsToAdd、_componentsToAddList和componentsToAddByType,设置_isComponentListUnsorted标志 this._componentsToAdd = {}; this._componentsToAddList.length = 0; this.componentsToAddByType.clear(); this._isComponentListUnsorted = true; } + // 调用新添加组件的onAddedToEntity和onEnabled方法 if (this._tempBufferList.length > 0) { - // 现在所有的组件都添加到了场景中,我们再次循环并调用onAddedToEntity/onEnabled - for (let i = 0, l = this._tempBufferList.length; i < l; ++ i) { - let component = this._tempBufferList[i]; + for (const component of this._tempBufferList) { component.onAddedToEntity(); - // enabled检查实体和组件 + // 如果组件已启用,则调用onEnabled方法 if (component.enabled) { component.onEnabled(); } } + // 清空_tempBufferList this._tempBufferList.length = 0; } } public handleRemove(component: Component) { + // 如果组件可以更新,从可更新组件列表中删除该组件 if (isIUpdatable(component) && this._updatableComponents.length > 0) { - let index = this._updatableComponents.findIndex((c) => (c as Component).id == component.id); - if (index != -1) + const index = this._updatableComponents.findIndex((c) => (c as Component).id === component.id); + if (index !== -1) { this._updatableComponents.splice(index, 1); + } } - + + // 更新实体的组件位掩码 this.decreaseBits(component); + + // 通知实体处理器一个组件已被删除 this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + // 调用组件的onRemovedFromEntity方法,将其entity属性设置为null component.onRemovedFromEntity(); component.entity = null; } private removeComponentsByType(component: Component) { - let fastList = this.componentsByType.get(TypeUtils.getType(component)); - let fastIndex = fastList.findIndex(c => c.id == component.id); - if (fastIndex != -1) { - fastList.splice(fastIndex, 1); + // 获取存储指定类型组件的fastList数组 + const fastList = this.componentsByType.get(TypeUtils.getType(component)); + + // 在fastList中查找要删除的组件 + const index = fastList.findIndex((c) => c.id === component.id); + if (index !== -1) { + // 找到组件后,使用splice方法将其从fastList中删除 + fastList.splice(index, 1); } } private addComponentsByType(component: Component) { + // 获取存储指定类型组件的fastList数组 let fastList = this.componentsByType.get(TypeUtils.getType(component)); - if (!fastList) fastList = []; + + // 如果fastList不存在,则创建一个空数组 + if (!fastList) { + fastList = []; + } + + // 在fastList中添加组件 fastList.push(component); + + // 更新componentsByType字典,以便它包含fastList数组 this.componentsByType.set(TypeUtils.getType(component), fastList); } + /** + * 从待添加组件列表中移除指定类型的组件。 + * @param component 要移除的组件 + */ private removeComponentsToAddByType(component: Component) { + // 获取待添加组件列表中指定类型的组件列表 let fastList = this.componentsToAddByType.get(TypeUtils.getType(component)); + + // 在该列表中查找指定组件 let fastIndex = fastList.findIndex(c => c.id == component.id); + + // 如果找到了指定组件,则从列表中移除它 if (fastIndex != -1) { fastList.splice(fastIndex, 1); } } + /** + * 向待添加组件列表中添加指定类型的组件。 + * @param component 要添加的组件 + */ private addComponentsToAddByType(component: Component) { + // 获取待添加组件列表中指定类型的组件列表 let fastList = this.componentsToAddByType.get(TypeUtils.getType(component)); + + // 如果指定类型的组件列表不存在,则创建一个新的列表 if (!fastList) fastList = []; + + // 向指定类型的组件列表中添加组件 fastList.push(component); + + // 更新待添加组件列表中指定类型的组件列表 this.componentsToAddByType.set(TypeUtils.getType(component), fastList); } /** - * 获取类型T的第一个组件并返回它 - * 可以选择跳过检查未初始化的组件(尚未调用onAddedToEntity方法的组件) - * 如果没有找到组件,则返回null。 - * @param type - * @param onlyReturnInitializedComponents + * 获取指定类型的第一个组件实例。 + * @param type 组件类型 + * @param onlyReturnInitializedComponents 是否仅返回已初始化的组件 + * @returns 指定类型的第一个组件实例,如果不存在则返回 null */ - public getComponent(type, onlyReturnInitializedComponents: boolean): T { + public getComponent( + type: new (...args: any[]) => T, + onlyReturnInitializedComponents: boolean + ): T { + // 获取指定类型的组件列表 let fastList = this.componentsByType.get(type); - if (fastList && fastList.length > 0) - return fastList[0] as T; - // 我们可以选择检查挂起的组件,以防addComponent和getComponent在同一个框架中被调用 + // 如果指定类型的组件列表存在并且不为空,则返回第一个组件实例 + if (fastList && fastList.length > 0) return fastList[0] as T; + + // 如果不仅返回已初始化的组件,则检查待添加组件列表中是否存在指定类型的组件 if (!onlyReturnInitializedComponents) { let fastToAddList = this.componentsToAddByType.get(type); if (fastToAddList && fastToAddList.length > 0) return fastToAddList[0] as T; } + // 如果指定类型的组件列表为空且待添加组件列表中也不存在该类型的组件,则返回 null return null; } /** - * 获取T类型的所有组件,但不使用列表分配 - * @param typeName - * @param components + * 获取指定类型的所有组件实例。 + * @param typeName 组件类型名称 + * @param components 存储组件实例的数组 + * @returns 存储了指定类型的所有组件实例的数组 */ public getComponents(typeName: any, components?: any[]) { - if (!components) - components = []; + // 如果没有传入组件实例数组,则创建一个新数组 + if (!components) components = []; + // 获取指定类型的组件列表,并将其添加到组件实例数组中 let fastList = this.componentsByType.get(typeName); - if (fastList) - components = components.concat(fastList); + if (fastList) components = components.concat(fastList); + // 获取待添加组件列表中的指定类型的组件列表,并将其添加到组件实例数组中 let fastToAddList = this.componentsToAddByType.get(typeName); - if (fastToAddList) - components = components.concat(fastToAddList); + if (fastToAddList) components = components.concat(fastToAddList); + // 返回存储了指定类型的所有组件实例的数组 return components; } public update() { this.updateLists(); if (this._updatableComponents.length > 0) { - for (let i = 0, s = this._updatableComponents.length; i < s; ++ i) { + for (let i = 0, s = this._updatableComponents.length; i < s; ++i) { let updateComponent = this._updatableComponents[i]; if (updateComponent.enabled) updateComponent.update(); @@ -284,16 +400,16 @@ module es { } public onEntityTransformChanged(comp: ComponentTransform) { - if (this._components.length > 0 ){ - for (let i = 0, s = this._components.length; i < s; ++ i) { + if (this._components.length > 0) { + for (let i = 0, s = this._components.length; i < s; ++i) { let component = this._components[i]; if (component.enabled) component.onEntityTransformChanged(comp); } } - + if (this._componentsToAddList.length > 0) { - for (let i = 0, s = this._componentsToAddList.length; i < s; ++ i) { + for (let i = 0, s = this._componentsToAddList.length; i < s; ++i) { let component = this._componentsToAddList[i]; if (component.enabled) component.onEntityTransformChanged(comp); @@ -303,14 +419,14 @@ module es { public onEntityEnabled() { if (this._components.length > 0) { - for (let i = 0, s = this._components.length; i < s; i ++) + for (let i = 0, s = this._components.length; i < s; i++) this._components[i].onEnabled(); } } public onEntityDisabled() { if (this._components.length > 0) { - for (let i = 0, s = this._components.length; i < s; i ++) + for (let i = 0, s = this._components.length; i < s; i++) this._components[i].onDisabled(); } } diff --git a/source/src/ECS/Utils/EntityList.ts b/source/src/ECS/Utils/EntityList.ts index dcc03d09..037a0bce 100644 --- a/source/src/ECS/Utils/EntityList.ts +++ b/source/src/ECS/Utils/EntityList.ts @@ -1,28 +1,48 @@ module es { export class EntityList { - public scene: Scene; /** - * 场景中添加的实体列表 + * 场景引用 + */ + public scene: Scene; + + /** + * 实体列表 */ public _entities: Entity[] = []; + /** - * 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们 + * 待添加的实体字典 */ - public _entitiesToAdded: {[index: number]: Entity} = {}; + public _entitiesToAdded: { [index: number]: Entity } = {}; + /** - * 本帧被标记为删除的实体列表。用于对实体进行分组,以便我们可以同时处理它们 + * 待移除的实体字典 + */ + public _entitiesToRemove: { [index: number]: Entity } = {}; + + /** + * 待添加的实体列表 */ - public _entitiesToRemove: {[index: number]: Entity} = {}; public _entitiesToAddedList: Entity[] = []; - public _entitiesToRemoveList: Entity[] = []; + /** - * 标志,用于确定我们是否需要在这一帧中对实体进行排序 + * 待移除的实体列表 + */ + public _entitiesToRemoveList: Entity[] = []; + + /** + * 实体列表是否已排序 */ public _isEntityListUnsorted: boolean; + /** - * 通过标签跟踪实体,便于检索 + * 实体字典,以实体标签为键 */ public _entityDict: Map> = new Map>(); + + /** + * 未排序的标签集合 + */ public _unsortedTags: Set = new Set(); constructor(scene: Scene) { @@ -55,140 +75,194 @@ module es { } /** - * 从列表中删除一个实体。所有的生命周期方法将在下一帧中被调用 - * @param entity + * 从场景中移除实体。 + * @param entity 要从场景中移除的实体。 */ public remove(entity: Entity) { - // 防止在同一帧中添加或删除实体 + // 如果实体在添加列表中,则将其从添加列表中移除 if (this._entitiesToAdded[entity.id]) { - let index = this._entitiesToAddedList.findIndex(e => e.id == entity.id); - if (index != -1) + const index = this._entitiesToAddedList.findIndex((e) => e.id === entity.id); + if (index !== -1) { this._entitiesToAddedList.splice(index, 1); + } delete this._entitiesToAdded[entity.id]; return; } + // 如果实体不在添加列表中,则将其添加到移除列表中并将其添加到移除字典中 this._entitiesToRemoveList.push(entity); - if (!this._entitiesToRemove[entity.id]) + if (!this._entitiesToRemove[entity.id]) { this._entitiesToRemove[entity.id] = entity; + } } /** - * 从实体列表中删除所有实体 + * 从场景中移除所有实体。 */ public removeAllEntities() { + // 清除字典和列表,以及是否已排序的标志 this._unsortedTags.clear(); this._entitiesToAdded = {}; this._entitiesToAddedList.length = 0; this._isEntityListUnsorted = false; - // 为什么我们要在这里更新列表?主要是为了处理在场景切换前被分离的实体。 - // 它们仍然会在_entitiesToRemove列表中,这将由updateLists处理。 + // 调用updateLists方法,以处理要移除的实体 this.updateLists(); - for (let i = 0; i < this._entities.length; i++) { - this._entities[i]._isDestroyed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; + // 标记并移除所有实体 + for (const entity of this._entities) { + entity._isDestroyed = true; + entity.onRemovedFromScene(); + entity.scene = null; } + // 清空实体列表和实体字典 this._entities.length = 0; this._entityDict.clear(); } /** - * 检查实体目前是否由这个EntityList管理 - * @param entity + * 检查实体是否已经被添加到场景中。 + * @param entity 要检查的实体 + * @returns 如果实体已经被添加到场景中,则返回true;否则返回false */ public contains(entity: Entity): boolean { + // 检查实体是否存在于_entitiesToAdded字典中 return !!this._entitiesToAdded[entity.id]; } - public getTagList(tag: number) { + /** + * 获取具有指定标签的实体列表。 + * 如果列表不存在,则创建一个新列表并返回。 + * @param tag 实体标签 + * @returns 具有指定标签的实体列表 + */ + public getTagList(tag: number): Set { + // 尝试从_entityDict中获取具有指定标签的实体列表 let list = this._entityDict.get(tag); + + // 如果列表不存在,则创建一个新的Set实例,并添加到_entityDict中 if (!list) { - list = new Set(); + list = new Set(); this._entityDict.set(tag, list); } return list; } + /** + * 添加实体到标签列表中。 + * @param entity 实体 + */ public addToTagList(entity: Entity) { - this.getTagList(entity.tag).add(entity); + // 获取标签列表 + const list = this.getTagList(entity.tag); + + // 将实体添加到标签列表中 + list.add(entity); + + // 添加未排序标志 this._unsortedTags.add(entity.tag); } + /** + * 从标签列表中移除实体。 + * @param entity 实体 + */ public removeFromTagList(entity: Entity) { - let list = this._entityDict.get(entity.tag); - if (list) - list.delete(entity); - } + // 获取实体的标签列表 + const list = this._entityDict.get(entity.tag); - public update() { - for (let i = 0, s = this._entities.length; i < s; ++ i) { - let entity = this._entities[i]; - if (entity.enabled && (entity.updateInterval == 1 || Time.frameCount % entity.updateInterval == 0)) - entity.update(); + // 如果标签列表存在,则从中移除实体 + if (list) { + list.delete(entity); } } + /** + * 更新场景中所有启用的实体的Update方法 + * 如果实体的UpdateInterval为1或Time.frameCount模除UpdateInterval为0,则每帧调用Update + */ + public update() { + for (let i = 0; i < this._entities.length; i++) { + const entity = this._entities[i]; + if (entity.enabled && (entity.updateInterval === 1 || Time.frameCount % entity.updateInterval === 0)) { + entity.update(); + } + } + } + + + /** + * 更新场景中实体的列表。 + */ public updateLists() { + // 处理要移除的实体 if (this._entitiesToRemoveList.length > 0) { - for (let i = 0, s = this._entitiesToRemoveList.length; i < s; ++ i) { - let entity = this._entitiesToRemoveList[i]; + for (const entity of this._entitiesToRemoveList) { + // 从标签列表中删除实体 this.removeFromTagList(entity); - - // 处理常规实体列表 - let index = this._entities.findIndex(e => e.id == entity.id); - if (index != -1) + + // 从场景实体列表中删除实体 + const index = this._entities.findIndex((e) => e.id === entity.id); + if (index !== -1) { this._entities.splice(index, 1); + } + + // 调用实体的onRemovedFromScene方法,并将其scene属性设置为null entity.onRemovedFromScene(); entity.scene = null; - + + // 通知场景实体处理器,一个实体已被移除 this.scene.entityProcessors.onEntityRemoved(entity); } - + + // 清空要移除的实体列表和字典 this._entitiesToRemove = {}; this._entitiesToRemoveList.length = 0; } + // 处理要添加的实体 if (this._entitiesToAddedList.length > 0) { - for (let i = 0, s = this._entitiesToAddedList.length; i < s; ++ i) { - let entity = this._entitiesToAddedList[i]; + // 添加实体到场景实体列表和标签列表中 + for (const entity of this._entitiesToAddedList) { this._entities.push(entity); entity.scene = this.scene; - this.addToTagList(entity); - + } + + // 通知场景实体处理器,有新的实体已添加 + for (const entity of this._entitiesToAddedList) { this.scene.entityProcessors.onEntityAdded(entity); } - - for (let i = 0, s = this._entitiesToAddedList.length; i < s; ++ i) { - let entity = this._entitiesToAddedList[i]; + + // 调用实体的onAddedToScene方法,以允许它们执行任何场景相关的操作 + for (const entity of this._entitiesToAddedList) { entity.onAddedToScene(); } + // 清空要添加的实体列表和字典 this._entitiesToAdded = {}; this._entitiesToAddedList.length = 0; } } + /** * 返回第一个找到的名字为name的实体。如果没有找到则返回null * @param name */ public findEntity(name: string) { if (this._entities.length > 0) { - for (let i = 0, s = this._entities.length; i < s; ++ i) { + for (let i = 0, s = this._entities.length; i < s; ++i) { let entity = this._entities[i]; if (entity.name == name) return entity; } } - + if (this._entitiesToAddedList.length > 0) { - for (let i = 0, s = this._entitiesToAddedList.length; i < s; ++ i) { + for (let i = 0, s = this._entitiesToAddedList.length; i < s; ++i) { let entity = this._entitiesToAddedList[i]; if (entity.name == name) return entity; @@ -199,44 +273,52 @@ module es { } /** - * - * @param id - * @returns + * 通过实体ID在场景中查找对应实体 + * @param id 实体ID + * @returns 返回找到的实体,如果没有找到则返回 null */ public findEntityById(id: number) { + // 遍历场景中所有实体 if (this._entities.length > 0) { - for (let i = 0, s = this._entities.length; i < s; ++ i) { + for (let i = 0, s = this._entities.length; i < s; ++i) { let entity = this._entities[i]; + // 如果实体的ID匹配,返回该实体 if (entity.id == id) return entity; } } - + + // 在未添加的实体列表中查找 return this._entitiesToAdded[id]; } /** - * 返回带有标签的所有实体的列表。如果没有实体有标签,则返回一个空列表。 - * 返回的List可以通过ListPool.free放回池中 - * @param tag + * 获取标签对应的实体列表 + * @param tag 实体的标签 + * @returns 返回所有拥有该标签的实体列表 */ - public entitiesWithTag(tag: number) { - let list = this.getTagList(tag); + public entitiesWithTag(tag: number): Entity[] { + // 从字典中获取对应标签的实体列表 + const list = this.getTagList(tag); + + // 从对象池中获取 Entity 类型的数组 + const returnList = ListPool.obtain(Entity); - let returnList = ListPool.obtain(Entity); if (list.size > 0) { - for (let entity of list) { + // 将实体列表中的实体添加到返回列表中 + for (const entity of list) { returnList.push(entity); } } - + + // 返回已填充好实体的返回列表 return returnList; } /** * 返回第一个找到该tag的实体 - * @param tag - * @returns + * @param tag + * @returns */ public entityWithTag(tag: number) { let list = this.getTagList(tag); @@ -251,113 +333,124 @@ module es { } /** - * 返回在场景中找到的第一个T类型的组件。 - * @param type + * 在场景中查找具有给定类型的组件。 + * @param type 要查找的组件类型。 + * @returns 如果找到,则返回该组件;否则返回null。 */ - public findComponentOfType(type): T { - if (this._entities.length > 0 ){ - for (let i = 0, s = this._entities.length; i < s; i++) { - let entity = this._entities[i]; - if (entity.enabled) { - let comp = entity.getComponent(type); - if (comp) - return comp; - } - } - } - - if (this._entitiesToAddedList.length > 0) { - for (let i = 0; i < this._entitiesToAddedList.length; i++) { - let entity = this._entitiesToAddedList[i]; - if (entity.enabled) { - let comp = entity.getComponent(type); - if (comp) - return comp; + public findComponentOfType(type: new (...args: any[]) => T): T | null { + // 遍历场景中的所有实体,查找具有给定类型的组件 + for (const entity of this._entities) { + if (entity.enabled) { + const comp = entity.getComponent(type); + if (comp) { + return comp; } } } + // 遍历待添加的实体列表中的所有实体,查找具有给定类型的组件 + for (const entity of this._entitiesToAddedList) { + if (entity.enabled) { + const comp = entity.getComponent(type); + if (comp) { + return comp; + } + } + } + + // 如果找不到具有给定类型的组件,则返回null return null; } + /** - * 返回在场景中找到的所有T类型的组件。 - * 返回的List可以通过ListPool.free放回池中。 - * @param type + * 在场景中查找具有给定类型的所有组件。 + * @param type 要查找的组件类型。 + * @returns 具有给定类型的所有组件的列表。 */ - public findComponentsOfType(type): T[] { - let comps = ListPool.obtain(type); - if (this._entities.length > 0) { - for (let i = 0, s = this._entities.length; i < s; i++) { - let entity = this._entities[i]; - if (entity.enabled) - entity.getComponents(type, comps); + public findComponentsOfType(type: new (...args: any[]) => T): T[] { + // 从池中获取一个可重用的组件列表 + const comps = ListPool.obtain(type); + + // 遍历场景中的所有实体,查找具有给定类型的组件并添加到组件列表中 + for (const entity of this._entities) { + if (entity.enabled) { + entity.getComponents(type, comps); } } - if (this._entitiesToAddedList.length > 0) { - for (let i = 0, s = this._entitiesToAddedList.length; i < s; i ++) { - let entity = this._entitiesToAddedList[i]; - if (entity.enabled) - entity.getComponents(type, comps); + // 遍历待添加的实体列表中的所有实体,查找具有给定类型的组件并添加到组件列表中 + for (const entity of this._entitiesToAddedList) { + if (entity.enabled) { + entity.getComponents(type, comps); } } + // 返回具有给定类型的所有组件的列表 return comps; } + /** - * 返回场景中包含特定组件的实体列表 - * @param types - * @returns + * 返回拥有指定类型组件的所有实体 + * @param types 要查询的组件类型列表 + * @returns 返回拥有指定类型组件的所有实体 */ public findEntitiesOfComponent(...types: any[]): Entity[] { - let entities = []; - if (this._entities.length > 0) { - for (let i = 0, s = this._entities.length; i < s; i++) { - if (this._entities[i].enabled) { - let meet = true; - if (types.length > 0) - for (let t = 0, ts = types.length; t < ts; t ++) { - let type = types[t]; - let hasComp = this._entities[i].hasComponent(type); - if (!hasComp) { - meet = false; - break; - } - } - - if (meet) { - entities.push(this._entities[i]); + const entities = []; + + // 遍历所有已存在的实体 + for (const entity of this._entities) { + // 只有启用的实体才会被考虑 + if (entity.enabled) { + // 如果types数组为空,直接将实体添加到结果数组中 + if (types.length === 0) { + entities.push(entity); + continue; + } + + // 对于每个指定的组件类型,检查实体是否具有该组件 + let meet = true; + for (const type of types) { + const hasComp = entity.hasComponent(type); + if (!hasComp) { + meet = false; + break; } } + + // 如果实体满足要求,将其添加到结果数组中 + if (meet) { + entities.push(entity); + } } } - - if (this._entitiesToAddedList.length > 0) { - for (let i = 0, s = this._entitiesToAddedList.length; i < s; i ++) { - let entity = this._entitiesToAddedList[i]; - if (entity.enabled) { - let meet = true; - if (types.length > 0) - for (let t = 0, ts = types.length; t < ts; t ++) { - let type = types[t]; - let hasComp = entity.hasComponent(type); - if (!hasComp) { - meet = false; - break; - } - } - - if (meet) { - entities.push(entity); + + // 遍历所有等待添加的实体,和上面的操作类似 + for (const entity of this._entitiesToAddedList) { + if (entity.enabled) { + if (types.length === 0) { + entities.push(entity); + continue; + } + + let meet = true; + for (const type of types) { + const hasComp = entity.hasComponent(type); + if (!hasComp) { + meet = false; + break; } } + + if (meet) { + entities.push(entity); + } } } - return entities; } + } } diff --git a/source/src/ECS/Utils/EntityProcessorList.ts b/source/src/ECS/Utils/EntityProcessorList.ts index 3bd6cdd0..6e93fbca 100644 --- a/source/src/ECS/Utils/EntityProcessorList.ts +++ b/source/src/ECS/Utils/EntityProcessorList.ts @@ -1,113 +1,181 @@ module es { export class EntityProcessorList { - private _processors: EntitySystem[] = []; - private _orderDirty: boolean = false; - /** 获取系统列表 */ + private _processors: EntitySystem[] = []; // 处理器列表 + private _orderDirty: boolean = false; // 处理器排序标志 + + /** 获取处理器列表 */ public get processors() { return this._processors; } - /** 系统数量 */ + /** 获取处理器数量 */ public get count() { return this._processors.length; } - public add(processor: EntitySystem) { + /** + * 添加处理器 + * @param processor 要添加的处理器 + */ + public add(processor: EntitySystem): void { this._processors.push(processor); } - public remove(processor: EntitySystem) { + /** + * 移除处理器 + * @param processor 要移除的处理器 + */ + public remove(processor: EntitySystem): void { + // 使用 es.List 类的 remove() 方法从处理器列表中移除指定处理器 new es.List(this._processors).remove(processor); } - public onComponentAdded(entity: Entity) { + /** + * 在实体上添加组件时被调用 + * @param entity 添加组件的实体 + */ + public onComponentAdded(entity: Entity): void { this.notifyEntityChanged(entity); } - public onComponentRemoved(entity: Entity) { + /** + * 在实体上移除组件时被调用 + * @param entity 移除组件的实体 + */ + public onComponentRemoved(entity: Entity): void { this.notifyEntityChanged(entity); } - public onEntityAdded(entity: Entity) { + /** + * 在场景中添加实体时被调用 + * @param entity 添加的实体 + */ + public onEntityAdded(entity: Entity): void { this.notifyEntityChanged(entity); } - public onEntityRemoved(entity: Entity) { + /** + * 在场景中移除实体时被调用 + * @param entity 移除的实体 + */ + public onEntityRemoved(entity: Entity): void { this.removeFromProcessors(entity); } - public begin() { - + /** 在处理器列表上开始循环 */ + public begin(): void { } - public update() { - if (this._processors.length == 0) + /** 更新处理器列表 */ + public update(): void { + // 如果处理器列表为空,则直接返回 + if (this._processors.length === 0) { return; + } + // 如果需要重新排序处理器列表 if (this._orderDirty) { - // 进行排序 - this._processors = this._processors.sort((a, b) => a.updateOrder - b.updateOrder); - for (let i = 0, s = this._processors.length; i < s; ++ i) { + // 对处理器列表进行排序 + this._processors.sort((a, b) => a.updateOrder - b.updateOrder); + + // 重新设置处理器的更新顺序 + for (let i = 0, s = this._processors.length; i < s; ++i) { const processor = this._processors[i]; processor.setUpdateOrder(i); } + + // 将标志设置为“未脏” this.clearDirty(); } - for (let i = 0, s = this._processors.length; i < s; ++ i) { - this._processors[i].update(); + // 调用每个处理器的 update() 方法 + for (let i = 0, s = this._processors.length; i < s; ++i) { + const processor = this._processors[i]; + processor.update(); } } - public lateUpdate() { - if (this._processors.length == 0) - return; - - for (let i = 0, s = this._processors.length; i < s; ++ i) { - this._processors[i].lateUpdate(); - } + /** 在处理器列表上完成循环 */ + public end(): void { } - public end() { - - } - - public setDirty() { + /** 设置处理器排序标志 */ + public setDirty(): void { this._orderDirty = true; } - public clearDirty() { + /** 清除处理器排序标志 */ + public clearDirty(): void { this._orderDirty = false; } + /** + * 获取指定类型的处理器 + * @param type 指定类型的构造函数 + * @returns 指定类型的处理器 + */ public getProcessor(type: new (...args: any[]) => T): T { - if (this._processors.length == 0) + // 如果处理器列表为空,则返回null + if (this._processors.length === 0) { return null; - - for (let i = 0, s = this._processors.length; i < s; ++ i) { - let processor = this._processors[i]; - if (processor instanceof type) - return processor as T; } + // 遍历处理器列表,查找指定类型的处理器 + for (let i = 0, s = this._processors.length; i < s; ++i) { + const processor = this._processors[i]; + + // 如果当前处理器是指定类型的实例,则返回当前处理器 + if (processor instanceof type) { + return processor as T; + } + } + + // 如果没有找到指定类型的处理器,则返回null return null; } - protected notifyEntityChanged(entity: Entity) { - if (this._processors.length == 0) + /** + * 通知处理器实体已更改 + * @param entity 发生更改的实体 + */ + protected notifyEntityChanged(entity: Entity): void { + if (this._processors.length === 0) { return; - - for (let i = 0, s = this._processors.length; i < s; ++ i) { - this._processors[i].onChanged(entity); + } + + // 遍历处理器列表,调用每个处理器的 onChanged() 方法 + for (let i = 0, s = this._processors.length; i < s; ++i) { + const processor = this._processors[i]; + processor.onChanged(entity); } } - protected removeFromProcessors(entity: Entity) { - if (this._processors.length == 0) + /** + * 从处理器列表中移除实体 + * @param entity 要移除的实体 + */ + protected removeFromProcessors(entity: Entity): void { + if (this._processors.length === 0) { return; - - for (let i = 0, s = this._processors.length; i < s; ++ i) { - this._processors[i].remove(entity); + } + + // 遍历处理器列表,调用每个处理器的 remove() 方法 + for (let i = 0, s = this._processors.length; i < s; ++i) { + const processor = this._processors[i]; + processor.remove(entity); + } + } + + /** 在处理器列表上进行后期更新 */ + public lateUpdate(): void { + if (this._processors.length === 0) { + return; + } + + // 调用每个处理器的 lateUpdate() 方法 + for (let i = 0, s = this._processors.length; i < s; ++i) { + const processor = this._processors[i]; + processor.lateUpdate(); } } } diff --git a/source/src/ECS/Utils/HashHelper.ts b/source/src/ECS/Utils/HashHelper.ts index 1b832988..93eeab31 100644 --- a/source/src/ECS/Utils/HashHelper.ts +++ b/source/src/ECS/Utils/HashHelper.ts @@ -1,89 +1,96 @@ module es { export class HashHelpers { + // 哈希冲突阈值,超过此值将使用另一种哈希算法 public static readonly hashCollisionThreshold: number = 100; + // 哈希值用于计算哈希表索引的质数 public static readonly hashPrime: number = 101; - - /** - * 用来作为哈希表大小的质数表。 - * 一个典型的调整大小的算法会在这个数组中选取比之前容量大两倍的最小质数。 - * 假设我们的Hashtable当前的容量为x,并且添加了足够多的元素,因此需要进行大小调整。 - * 调整大小首先计算2x,然后在表中找到第一个大于2x的质数,即如果质数的顺序是p_1,p_2,...,p_i,...,则找到p_n,使p_n-1 < 2x < p_n。 - * 双倍对于保持哈希特操作的渐近复杂度是很重要的,比如添加。 - * 拥有一个质数可以保证双倍哈希不会导致无限循环。 IE,你的哈希函数将是h1(key)+i*h2(key),0 <= i < size.h2和size必须是相对质数。 - */ - public static readonly primes = [3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919, + // 一组预定义的质数,用于计算哈希表容量 + public static readonly primes = [ + 3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919, 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591, 17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437, 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263, - 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369]; - - /** - * 这是比Array.MaxArrayLength小的最大质数 - */ + 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369 + ]; + // 可分配的最大数组长度,用于避免 OutOfMemoryException public static readonly maxPrimeArrayLength = 0x7FEFFFFD; + /** + * 判断一个数是否为质数 + * @param candidate 要判断的数 + * @returns 是否为质数 + */ public static isPrime(candidate: number): boolean { - if ((candidate & 1) != 0){ + if ((candidate & 1) !== 0) { // 位运算判断奇偶性 let limit = Math.sqrt(candidate); - for (let divisor = 3; divisor <= limit; divisor += 2){ - if ((candidate & divisor) == 0) + for (let divisor = 3; divisor <= limit; divisor += 2) { // 奇数因子判断 + if ((candidate % divisor) === 0) { return false; + } } return true; } - return (candidate == 2); + return (candidate === 2); // 2是质数 } - public static getPrime(min: number): number{ - if (min < 0) - throw new Error("参数错误 min不能小于0"); - - for (let i = 0; i < this.primes.length; i ++){ - let prime = this.primes[i]; - if (prime >= min) return prime; + /** + * 获取大于等于指定值的最小质数 + * @param min 指定值 + * @returns 大于等于指定值的最小质数 + */ + public static getPrime(min: number): number { + if (min < 0) { + throw new Error("参数错误 min 不能小于0"); } - // 在我们预定义的表之外,计算的方式稍复杂。 - for (let i = (min | 1); i < Number.MAX_VALUE; i += 2){ - if (this.isPrime(i) && ((i - 1) % this.hashPrime != 0)) + for (let i = 0; i < this.primes.length; i++) { + let prime = this.primes[i]; + if (prime >= min) { + return prime; + } + } + + // 在预定义的质数列表之外,需要计算最小的质数 + for (let i = (min | 1); i < Number.MAX_VALUE; i += 2) { // 从 min 向上计算奇数 + if (this.isPrime(i) && ((i - 1) % this.hashPrime !== 0)) { // i是质数且不是hashPrime的倍数 return i; + } } return min; } /** - * - * @param oldSize - * @returns 返回要增长的哈希特表的大小 + * 扩展哈希表容量 + * @param oldSize 原哈希表容量 + * @returns 扩展后的哈希表容量 */ public static expandPrime(oldSize: number): number { let newSize = 2 * oldSize; // 在遇到容量溢出之前,允许哈希特表增长到最大可能的大小 // 请注意,即使当_items.Length溢出时,这项检查也会起作用 - if (newSize > this.maxPrimeArrayLength && this.maxPrimeArrayLength > oldSize){ + if (newSize > this.maxPrimeArrayLength && this.maxPrimeArrayLength > oldSize) { return this.maxPrimeArrayLength; } return this.getPrime(newSize); } - public static getHashCode(str){ - let s; - if (typeof str == 'object'){ - s = JSON.stringify(str); - } else { - s = str.toString(); - } - + /** + * 计算字符串的哈希值 + * @param str 要计算哈希值的字符串 + * @returns 哈希值 + */ + public static getHashCode(str: string): number { let hash = 0; - if (s.length == 0) return hash; - for (let i = 0; i < s.length; i ++){ - let char = s.charCodeAt(i); - hash = ((hash << 5) - hash) + char; - hash = hash & hash; + if (str.length === 0) { + return hash; + } + for (let i = 0; i < str.length; i++) { + let char = str.charCodeAt(i); + hash = ((hash << 5) - hash) + char; // 采用 FNV-1a 哈希算法 + hash = hash & hash; // 将hash值转换为32位整数 } - return hash; } } diff --git a/source/src/ECS/Utils/Time.ts b/source/src/ECS/Utils/Time.ts index c5c6715a..63689130 100644 --- a/source/src/ECS/Utils/Time.ts +++ b/source/src/ECS/Utils/Time.ts @@ -1,59 +1,92 @@ module es { - /** 提供帧定时信息 */ + /** + * 时间管理器,用于管理游戏中的时间相关属性 + */ export class Time { - /** 游戏运行的总时间 */ + /** 游戏运行的总时间,单位为秒 */ public static totalTime: number = 0; - /** deltaTime的未缩放版本。不受时间尺度的影响 */ + + /** deltaTime 的未缩放版本,不受时间尺度的影响 */ public static unscaledDeltaTime: number = 0; + /** 前一帧到当前帧的时间增量,按时间刻度进行缩放 */ public static deltaTime: number = 0; - /** 时间刻度缩放 */ + + /** 时间刻度缩放,可以加快或减慢游戏时间 */ public static timeScale = 1; - /** DeltaTime可以为的最大值 */ + + /** DeltaTime 可以为的最大值,避免游戏出现卡顿情况 */ public static maxDeltaTime = Number.MAX_VALUE; + /** 已传递的帧总数 */ public static frameCount = 0; - /** 自场景加载以来的总时间 */ + + /** 自场景加载以来的总时间,单位为秒 */ public static timeSinceSceneLoad: number = 0; + + /** 上一次记录的时间,用于计算两次调用 update 之间的时间差 */ private static _lastTime = -1; + /** + * 更新时间管理器 + * @param currentTime 当前时间 + * @param useEngineTime 是否使用引擎时间 + */ public static update(currentTime: number, useEngineTime: boolean) { let dt = 0; + if (useEngineTime) { dt = currentTime; } else { - if (currentTime == -1) { + // 如果当前时间为 -1,则表示使用系统时间 + if (currentTime === -1) { currentTime = Date.now(); } - if (this._lastTime == -1) + // 如果上一次记录的时间为 -1,则表示当前为第一次调用 update + if (this._lastTime === -1) { this._lastTime = currentTime; + } + // 计算两次调用 update 之间的时间差,并将其转换为秒 dt = (currentTime - this._lastTime) / 1000; } - - if (dt > this.maxDeltaTime) + + // 如果计算得到的时间差超过了最大时间步长,则将其限制为最大时间步长 + if (dt > this.maxDeltaTime) { dt = this.maxDeltaTime; + } + + // 更新时间管理器的各个属性 this.totalTime += dt; this.deltaTime = dt * this.timeScale; this.unscaledDeltaTime = dt; this.timeSinceSceneLoad += dt; this.frameCount++; + // 记录当前时间,以备下一次调用 update 使用 this._lastTime = currentTime; } + public static sceneChanged() { this.timeSinceSceneLoad = 0; } /** - * 允许在间隔检查。只应该使用高于delta的间隔值,否则它将始终返回true。 - * @param interval + * 检查指定时间间隔是否已过去 + * @param interval 指定时间间隔 + * @returns 是否已过去指定时间间隔 */ - public static checkEvery(interval: number) { - // 我们减去了delta,因为timeSinceSceneLoad已经包含了这个update ticks delta - return MathHelper.toInt(this.timeSinceSceneLoad / interval) > MathHelper.toInt((this.timeSinceSceneLoad - this.deltaTime) / interval); + public static checkEvery(interval: number): boolean { + // 计算当前时刻所经过的完整时间间隔个数(向下取整) + const passedIntervals = Math.floor(this.timeSinceSceneLoad / interval); + + // 计算上一帧到当前帧经过的时间所包含的时间间隔个数(向下取整) + const deltaIntervals = Math.floor(this.deltaTime / interval); + + // 如果当前时刻所经过的时间间隔数比上一帧所经过的时间间隔数多,则说明时间间隔已过去 + return passedIntervals > deltaIntervals; } } } diff --git a/source/src/ECS/Utils/TimeUtils.ts b/source/src/ECS/Utils/TimeUtils.ts index b8277a80..96a7af54 100644 --- a/source/src/ECS/Utils/TimeUtils.ts +++ b/source/src/ECS/Utils/TimeUtils.ts @@ -1,212 +1,242 @@ -class TimeUtils { - /** - * 计算月份ID - * @param d 指定计算日期 - * @returns 月ID - */ - public static monthId(d: Date = null): number { - d = d ? d : new Date(); - let y = d.getFullYear(); - let m = d.getMonth() + 1; - let g = m < 10 ? "0" : ""; - return parseInt(y + g + m); - } +module es { + export class TimeUtils { + /** + * 获取日期对应的年份和月份的数字组合 + * @param d 要获取月份的日期对象,不传则默认为当前时间 + * @returns 返回数字组合的年份和月份 + */ + public static monthId(d: Date = null): number { + // 如果传入了时间,则使用传入的时间,否则使用当前时间 + d = d ? d : new Date(); - /** - * 计算日期ID - * @param d 指定计算日期 - * @returns 日期ID - */ - public static dateId(t: Date = null): number { - t = t ? t : new Date(); - let m: number = t.getMonth() + 1; - let a = m < 10 ? "0" : ""; - let d: number = t.getDate(); - let b = d < 10 ? "0" : ""; - return parseInt(t.getFullYear() + a + m + b + d); - } + // 获取当前年份 + let y = d.getFullYear(); - /** - * 计算周ID - * @param d 指定计算日期 - * @returns 周ID - */ - public static weekId(d: Date = null, first: boolean = true): number { - d = d ? d : new Date(); - let c: Date = new Date(); - c.setTime(d.getTime()); - c.setDate(1); - c.setMonth(0);//当年第一天 + // 获取当前月份,并将月份转化为两位数的字符串格式 + let m = d.getMonth() + 1; + let g = m < 10 ? "0" : ""; - let year: number = c.getFullYear(); - let firstDay: number = c.getDay(); - if (firstDay == 0) { - firstDay = 7; + // 返回年份和月份的数字组合 + return parseInt(y + g + m); } - let max: boolean = false; - if (firstDay <= 4) { - max = firstDay > 1; - c.setDate(c.getDate() - (firstDay - 1)); - } else { - c.setDate(c.getDate() + 7 - firstDay + 1); + + /** + * 获取日期的数字组合 + * @param t - 可选参数,传入时间,若不传入则使用当前时间 + * @returns 数字组合 + */ + public static dateId(t: Date = null): number { + // 如果传入了时间,则使用传入的时间,否则使用当前时间 + t = t ? t : new Date(); + + // 获取当前月份,并将月份转化为两位数的字符串格式 + let m: number = t.getMonth() + 1; + let a = m < 10 ? "0" : ""; + + // 获取当前日期,并将日期转化为两位数的字符串格式 + let d: number = t.getDate(); + let b = d < 10 ? "0" : ""; + + // 返回年份、月份和日期的数字组合 + return parseInt(t.getFullYear() + a + m + b + d); } - let num: number = this.diffDay(d, c, false); - if (num < 0) { + + /** + * 获取当前日期所在周的数字组合 + * @param d - 可选参数,传入日期,若不传入则使用当前日期 + * @param first - 是否将当前周视为本年度的第1周,默认为true + * @returns 数字组合 + */ + public static weekId(d: Date = null, first: boolean = true): number { + d = d ? d : new Date(); + const c: Date = new Date(d.getTime()); // 复制一个新的日期对象,以免改变原始日期对象 c.setDate(1); - c.setMonth(0);//当年第一天 - c.setDate(c.getDate() - 1); - return this.weekId(c, false); - } - let week: number = num / 7; - let weekIdx: number = Math.floor(week) + 1; - if (weekIdx == 53) { - c.setTime(d.getTime()); - c.setDate(c.getDate() - 1); - let endDay: number = c.getDay(); - if (endDay == 0) { - endDay = 7; + c.setMonth(0); // 将日期设置为当年的第一天 + + const year: number = c.getFullYear(); + let firstDay: number = c.getDay(); + if (firstDay == 0) { + firstDay = 7; } - if (first && (!max || endDay < 4)) { - c.setFullYear(c.getFullYear() + 1); + + let max: boolean = false; + if (firstDay <= 4) { + max = firstDay > 1; + c.setDate(c.getDate() - (firstDay - 1)); + } else { + c.setDate(c.getDate() + 7 - firstDay + 1); + } + + let num: number = this.diffDay(d, c, false); // 计算当前日期与本年度的第一个星期一之间的天数 + if (num < 0) { + // 当前日期在本年度第一个星期一之前,则返回上一年度的最后一个星期 c.setDate(1); - c.setMonth(0);//当年第一天 + c.setMonth(0); + c.setDate(c.getDate() - 1); return this.weekId(c, false); } + + // 计算当前日期在本年度中是第几个星期 + const week: number = Math.floor(num / 7); + const weekIdx: number = Math.floor(week) + 1; + if (weekIdx == 53) { + c.setTime(d.getTime()); + c.setDate(c.getDate() - 1); + let endDay: number = c.getDay(); + if (endDay == 0) { + endDay = 7; + } + if (first && (!max || endDay < 4)) { + // 如果当前日期在本年度的最后一个星期并且当前年度的星期数不足53或当前日期在本年度第53周的星期4或更早,则返回下一年度的第1周 + c.setFullYear(c.getFullYear() + 1); + c.setDate(1); + c.setMonth(0); + return this.weekId(c, false); + } + } + const g: string = weekIdx > 9 ? "" : "0"; + const s: string = year + "00" + g + weekIdx; // 加上00防止和月份ID冲突 + return parseInt(s); } - let g: string = weekIdx > 9 ? "" : "0"; - let s: string = year + "00" + g + weekIdx;//加上00防止和月份ID冲突 - return parseInt(s); - } - /** - * 计算俩日期时间差,如果a比b小,返回负数 - */ - public static diffDay(a: Date, b: Date, fixOne: boolean = false): number { - let x = (a.getTime() - b.getTime()) / 86400000; - return fixOne ? Math.ceil(x) : Math.floor(x); - } - - /** - * 获取本周一 凌晨时间 - */ - public static getFirstDayOfWeek(d?: Date): Date { - d = d ? d : new Date(); - let day = d.getDay() || 7; - return new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1 - day, 0, 0, 0, 0); - } - - /** - * 获取当日凌晨时间 - */ - public static getFirstOfDay(d?: Date): Date { - d = d ? d : new Date(); - d.setHours(0, 0, 0, 0); - return d; - } - - /** - * 获取次日凌晨时间 - */ - public static getNextFirstOfDay(d?: Date): Date { - return new Date(this.getFirstOfDay(d).getTime() + 86400000); - } - - /** - * @returns 2018-12-12 - */ - public static formatDate(date: Date): string { - let y = date.getFullYear(); - let m: any = date.getMonth() + 1; - m = m < 10 ? '0' + m : m; - let d: any = date.getDate(); - d = d < 10 ? ('0' + d) : d; - return y + '-' + m + '-' + d; - } - - /** - * @returns 2018-12-12 12:12:12 - */ - public static formatDateTime(date: Date): string { - let y = date.getFullYear(); - let m: any = date.getMonth() + 1; - m = m < 10 ? ('0' + m) : m; - let d: any = date.getDate(); - d = d < 10 ? ('0' + d) : d; - let h = date.getHours(); - let i: any = date.getMinutes(); - i = i < 10 ? ('0' + i) : i; - let s: any = date.getSeconds(); - s = s < 10 ? ('0' + s) : s; - return y + '-' + m + '-' + d + ' ' + h + ':' + i + ":" + s; - } - - /** - * @returns s 2018-12-12 或者 2018-12-12 12:12:12 - */ - public static parseDate(s: string): Date { - let t = Date.parse(s); - if (!isNaN(t)) { - return new Date(Date.parse(s.replace(/-/g, "/"))); - } else { - return new Date(); + /** + * 计算两个日期之间相差的天数 + * @param a 第一个日期 + * @param b 第二个日期 + * @param fixOne 是否将相差天数四舍五入到整数 + * @returns 两个日期之间相差的天数 + */ + public static diffDay(a: Date, b: Date, fixOne: boolean = false): number { + let x = (a.getTime() - b.getTime()) / 86400000; // 计算两个日期相差的毫秒数,然后除以一天的毫秒数,得到相差的天数 + return fixOne ? Math.ceil(x) : Math.floor(x); // 如果 fixOne 参数为 true,则将相差天数四舍五入到整数,否则向下取整 } - } - /** - * 秒数转换为时间形式。 - * @param time 秒数 - * @param partition 分隔符 - * @param showHour 是否显示小时 - * @return 返回一个以分隔符分割的时, 分, 秒 - * - * 比如: time = 4351; secondToTime(time)返回字符串01:12:31; - */ - public static secondToTime(time: number = 0, partition: string = ":", showHour: boolean = true): string { - let hours: number = Math.floor(time / 3600); - let minutes: number = Math.floor(time % 3600 / 60); - let seconds: number = Math.floor(time % 3600 % 60); - - let h: string = hours.toString(); - let m: string = minutes.toString(); - let s: string = seconds.toString(); - - if (hours < 10) h = "0" + h; - if (minutes < 10) m = "0" + m; - if (seconds < 10) s = "0" + s; - - let timeStr: string; - if (showHour) - timeStr = h + partition + m + partition + s; - else - timeStr = m + partition + s; - - return timeStr; - } - - - /** - * 时间形式转换为毫秒数。 - * @param time 以指定分隔符分割的时间字符串 - * @param partition 分隔符 - * @return 毫秒数显示的字符串 - * @throws Error Exception - * - * 用法1 trace(MillisecondTransform.timeToMillisecond("00:60:00")) - * 输出 3600000 - * - * - * 用法2 trace(MillisecondTransform.timeToMillisecond("00.60.00",".")) - * 输出 3600000 - */ - public static timeToMillisecond(time: string, partition: string = ":"): string { - let _ary: any[] = time.split(partition); - let timeNum: number = 0; - let len: number = _ary.length; - for (let i: number = 0; i < len; i++) { - let n: number = _ary[i]; - timeNum += n * Math.pow(60, (len - 1 - i)); + /** + * 获取指定日期所在周的第一天 + * @param d 指定日期,默认值为今天 + * @returns 指定日期所在周的第一天 + */ + public static getFirstDayOfWeek(d: Date = new Date()): Date { + // 获取当前日期是星期几,如果是0,则设置为7 + let dayOfWeek = d.getDay() || 7; + // 计算出指定日期所在周的第一天,即将指定日期减去星期几再加1 + // 这里用1减去dayOfWeek是为了保证星期一为一周的第一天 + return new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1 - dayOfWeek, 0, 0, 0, 0); + } + + /** + * 获取当日凌晨时间 + */ + public static getFirstOfDay(d?: Date): Date { + d = d ? d : new Date(); + d.setHours(0, 0, 0, 0); + return d; + } + + /** + * 获取次日凌晨时间 + */ + public static getNextFirstOfDay(d?: Date): Date { + return new Date(this.getFirstOfDay(d).getTime() + 86400000); + } + + /** + * 格式化日期为 "YYYY-MM-DD" 的字符串形式 + * @param date 要格式化的日期 + * @returns 格式化后的日期字符串 + */ + public static formatDate(date: Date): string { + let y = date.getFullYear(); + let m: any = date.getMonth() + 1; + m = m < 10 ? '0' + m : m; + let d: any = date.getDate(); + d = d < 10 ? ('0' + d) : d; + return y + '-' + m + '-' + d; + } + + + /** + * 将日期对象格式化为 "YYYY-MM-DD HH:mm:ss" 的字符串 + * @param date 日期对象 + * @returns 格式化后的字符串 + */ + public static formatDateTime(date: Date): string { + let y = date.getFullYear(); + let m: any = date.getMonth() + 1; + m = m < 10 ? ('0' + m) : m; + let d: any = date.getDate(); + d = d < 10 ? ('0' + d) : d; + let h = date.getHours(); + let i: any = date.getMinutes(); + i = i < 10 ? ('0' + i) : i; + let s: any = date.getSeconds(); + s = s < 10 ? ('0' + s) : s; + return y + '-' + m + '-' + d + ' ' + h + ':' + i + ":" + s; + } + + /** + * 将字符串解析为Date对象 + * @param s 要解析的日期字符串,例如:2022-01-01 + * @returns 返回解析后的Date对象,如果解析失败,则返回当前时间的Date对象 + */ + public static parseDate(s: string): Date { + let t = Date.parse(s); + if (!isNaN(t)) { + // 如果日期字符串中的分隔符为“-”,则需要先将其转换为“/”,否则解析会失败 + return new Date(Date.parse(s.replace(/-/g, "/"))); + } else { + return new Date(); + } + } + + /** + * 将秒数转换为时分秒的格式 + * @param time 秒数 + * @param partition 分隔符 + * @param showHour 是否显示小时位 + * @returns 转换后的时间字符串 + */ + public static secondToTime(time: number = 0, partition: string = ":", showHour: boolean = true): string { + let hours: number = Math.floor(time / 3600); + let minutes: number = Math.floor(time % 3600 / 60); + let seconds: number = Math.floor(time % 3600 % 60); + + let h: string = hours.toString(); + let m: string = minutes.toString(); + let s: string = seconds.toString(); + + if (hours < 10) h = "0" + h; + if (minutes < 10) m = "0" + m; + if (seconds < 10) s = "0" + s; + + let timeStr: string; + if (showHour) + timeStr = h + partition + m + partition + s; + else + timeStr = m + partition + s; + + return timeStr; + } + + /** + * 将时间字符串转换为毫秒数 + * @param time 时间字符串,如 "01:30:15" 表示 1小时30分钟15秒 + * @param partition 分隔符,默认为 ":" + * @returns 转换后的毫秒数字符串 + */ + public static timeToMillisecond(time: string, partition: string = ":"): string { + let _ary: any[] = time.split(partition); + let timeNum: number = 0; + let len: number = _ary.length; + + // 将时间转换成毫秒数 + for (let i: number = 0; i < len; i++) { + let n: number = _ary[i]; + timeNum += n * Math.pow(60, (len - 1 - i)); + } + timeNum *= 1000; + + return timeNum.toString(); } - timeNum *= 1000; - return timeNum.toString(); } } \ No newline at end of file diff --git a/source/src/Utils/Collections/FasterDictionary.ts b/source/src/Utils/Collections/FasterDictionary.ts deleted file mode 100644 index 73628e54..00000000 --- a/source/src/Utils/Collections/FasterDictionary.ts +++ /dev/null @@ -1,317 +0,0 @@ -module es { - /** - * 创建这个字典的原因只有一个: - * 我需要一个能让我直接以数组的形式对值进行迭代的字典,而不需要生成一个数组或使用迭代器。 - * 对于这个目标是比标准字典快N倍。 - * Faster dictionary在大部分操作上也比标准字典快,但差别可以忽略不计。 - * 唯一较慢的操作是在添加时调整内存大小,因为与标准数组相比,这个实现需要使用两个单独的数组。 - */ - export class FasterDictionary { - public _values: TValue[]; - public _valuesInfo: FastNode[]; - public _buckets: number[]; - public _freeValueCellIndex: number = 0; - public _collisions: number = 0; - - constructor(size: number = 1) { - this._valuesInfo = new Array(size); - this._values = new Array(size); - this._buckets = new Array(HashHelpers.getPrime(size)); - } - - public getValuesArray(count: {value: number}): TValue[] { - count.value = this._freeValueCellIndex; - - return this._values; - } - - public get valuesArray(): TValue[] { - return this._values; - } - - public get count(): number { - return this._freeValueCellIndex; - } - - public add(key: TKey, value: TValue) { - if (!this.addValue(key, value, {value: 0})) - throw new Error("key 已经存在") - } - - public addValue(key: TKey, value: TValue, indexSet: {value: number}) { - let hash = HashHelpers.getHashCode(key); - let bucketIndex = FasterDictionary.reduce(hash, this._buckets.length); - - if (this._freeValueCellIndex == this._values.length) { - let expandPrime = HashHelpers.expandPrime(this._freeValueCellIndex); - - this._values.length = expandPrime; - this._valuesInfo.length = expandPrime; - } - - // buckets值-1表示它是空的 - let valueIndex = NumberExtension.toNumber(this._buckets[bucketIndex]) - 1; - - if (valueIndex == -1) { - // 在最后一个位置创建信息节点,并填入相关信息 - this._valuesInfo[this._freeValueCellIndex] = new FastNode(key, hash); - } else { - { - let currentValueIndex = valueIndex; - do { - // 必须检查键是否已经存在于字典中 - if (this._valuesInfo[currentValueIndex].hashcode == hash && - this._valuesInfo[currentValueIndex].key == key) { - // 键已经存在,只需将其值替换掉即可 - this._values[currentValueIndex] = value; - indexSet.value = currentValueIndex; - return false; - } - - currentValueIndex = this._valuesInfo[currentValueIndex].previous; - } - while (currentValueIndex != -1); // -1表示没有更多的值与相同的哈希值的键 - } - - this._collisions++; - // 创建一个新的节点,该节点之前的索引指向当前指向桶的节点 - this._valuesInfo[this._freeValueCellIndex] = new FastNode(key, hash, valueIndex); - // 更新现有单元格的下一个单元格指向新的单元格,旧的单元格 -> 新的单元格 -> 旧的单元格 <- 下一个单元格 - this._valuesInfo[valueIndex].next = this._freeValueCellIndex; - } - // 重要的是:新的节点总是被桶单元格指向的那个节点,所以我可以假设被桶指向的那个节点总是最后添加的值(next = -1) - // item与这个bucketIndex将指向最后创建的值 - // TODO: 如果相反,我假设原来的那个是bucket中的那个,我就不需要在这里更新bucket了 - this._buckets[bucketIndex] = (this._freeValueCellIndex + 1); - - this._values[this._freeValueCellIndex] = value; - indexSet.value = this._freeValueCellIndex; - - this._freeValueCellIndex++; - - if (this._collisions > this._buckets.length) { - // 我们需要更多的空间和更少的碰撞 - this._buckets = new Array(HashHelpers.expandPrime(this._collisions)); - this._collisions = 0; - // 我们需要得到目前存储的所有值的哈希码,并将它们分布在新的桶长上 - for (let newValueIndex = 0; newValueIndex < this._freeValueCellIndex; newValueIndex++) { - // 获取原始哈希码,并根据新的长度找到新的bucketIndex - bucketIndex = FasterDictionary.reduce(this._valuesInfo[newValueIndex].hashcode, this._buckets.length); - // bucketsIndex可以是-1或下一个值。 - // 如果是-1意味着没有碰撞。 - // 如果有碰撞,我们创建一个新节点,它的上一个指向旧节点。 - // 旧节点指向新节点,新节点指向旧节点,旧节点指向新节点,现在bucket指向新节点,这样我们就可以重建linkedlist. - // 获取当前值Index,如果没有碰撞,则为-1。 - let existingValueIndex = NumberExtension.toNumber(this._buckets[bucketIndex]) - 1; - // 将bucket索引更新为共享bucketIndex的当前项目的索引(最后找到的总是bucket中的那个) - this._buckets[bucketIndex] = newValueIndex + 1; - if (existingValueIndex != -1) { - // 这个单元格已经指向了新的bucket list中的一个值,这意味着有一个碰撞,出了问题 - this._collisions++; - // bucket将指向这个值,所以新的值将使用以前的索引 - this._valuesInfo[newValueIndex].previous = existingValueIndex; - this._valuesInfo[newValueIndex].next = -1; - // 并将之前的下一个索引更新为新的索引 - this._valuesInfo[existingValueIndex].next = newValueIndex; - } else { - // 什么都没有被索引,桶是空的。我们需要更新之前的 next 和 previous 的值。 - this._valuesInfo[newValueIndex].next = -1; - this._valuesInfo[newValueIndex].previous = -1; - } - } - } - - return true; - } - - public remove(key: TKey): boolean { - let hash = FasterDictionary.hash(key); - let bucketIndex = FasterDictionary.reduce(hash, this._buckets.length); - - // 找桶 - let indexToValueToRemove = NumberExtension.toNumber(this._buckets[bucketIndex]) - 1; - - // 第一部分:在bucket list中寻找实际的键,如果找到了,我就更新bucket list,使它不再指向要删除的单元格。 - while (indexToValueToRemove != -1) { - if (this._valuesInfo[indexToValueToRemove].hashcode == hash && - this._valuesInfo[indexToValueToRemove].key == key) { - // 如果找到了密钥,并且桶直接指向了要删除的节点 - if (this._buckets[bucketIndex] - 1 == indexToValueToRemove){ - if (this._valuesInfo[indexToValueToRemove].next != -1) - throw new Error("如果 bucket 指向单元格,那么 next 必须不存在。"); - - // 如果前一个单元格存在,它的下一个指针必须被更新! - //<---迭代顺序 - // B(ucket总是指向最后一个) - // ------- ------- ------- - // 1 | | | | 2 | | | 3 | //bucket不能有下一个,只能有上一个。 - // ------- ------- ------- - //--> 插入 - let value = this._valuesInfo[indexToValueToRemove].previous; - this._buckets[bucketIndex] = value + 1; - }else{ - if (this._valuesInfo[indexToValueToRemove].next == -1) - throw new Error("如果 bucket 指向另一个单元格,则 NEXT 必须存在"); - } - - FasterDictionary.updateLinkedList(indexToValueToRemove, this._valuesInfo); - - break; - } - - indexToValueToRemove = this._valuesInfo[indexToValueToRemove].previous; - } - - if (indexToValueToRemove == -1) - return false; // 未找到 - - this._freeValueCellIndex --; // 少了一个需要反复计算的值 - - // 第二部分 - // 这时节点指针和水桶会被更新,但_values数组会被更新仍然有要删除的值 - // 这个字典的目标是能够做到像数组一样对数值进行迭代,所以数值数组必须始终是最新的 - - // 如果要删除的单元格是列表中的最后一个,我们可以执行较少的操作(不需要交换),否则我们要将最后一个值的单元格移到要删除的值上。 - if (indexToValueToRemove != this._freeValueCellIndex){ - // 我们可以将两个数组的最后一个值移到要删除的数组中。 - // 为了做到这一点,我们需要确保 bucket 指针已经更新了 - // 首先我们在桶列表中找到指向要移动的单元格的指针的索引 - let movingBucketIndex = FasterDictionary.reduce(this._valuesInfo[this._freeValueCellIndex].hashcode, this._buckets.length); - - // 如果找到了键,并且桶直接指向要删除的节点,现在必须指向要移动的单元格。 - if (this._buckets[movingBucketIndex] - 1 == this._freeValueCellIndex) - this._buckets[movingBucketIndex] = (indexToValueToRemove + 1); - - // 否则意味着有多个键具有相同的哈希值(碰撞),所以我们需要更新链接列表和它的指针 - let next = this._valuesInfo[this._freeValueCellIndex].next; - let previous = this._valuesInfo[this._freeValueCellIndex].previous; - - // 现在它们指向最后一个值被移入的单元格 - if (next != -1) - this._valuesInfo[next].previous = indexToValueToRemove; - if (previous != -1) - this._valuesInfo[previous].next = indexToValueToRemove; - - // 最后,实际上是移动值 - this._valuesInfo[indexToValueToRemove] = this._valuesInfo[this._freeValueCellIndex]; - this._values[indexToValueToRemove] = this._values[this._freeValueCellIndex]; - } - - return true; - } - - public trim(){ - let expandPrime = HashHelpers.expandPrime(this._freeValueCellIndex); - - if (expandPrime < this._valuesInfo.length){ - this._values.length = expandPrime; - this._valuesInfo.length = expandPrime; - } - } - - public clear(){ - if (this._freeValueCellIndex == 0) return; - - this._freeValueCellIndex = 0; - this._buckets.length = 0; - this._values.length = 0; - this._valuesInfo.length = 0; - } - - public fastClear(){ - if (this._freeValueCellIndex == 0) return; - - this._freeValueCellIndex = 0; - - this._buckets.length = 0; - this._valuesInfo.length = 0; - } - - public containsKey(key: TKey){ - if (this.tryFindIndex(key, {value: 0})){ - return true; - } - - return false; - } - - public tryGetValue(key: TKey): TValue { - let findIndex = {value: 0}; - if (this.tryFindIndex(key, findIndex)){ - return this._values[findIndex.value]; - } - - return null; - } - - public tryFindIndex(key: TKey, findIndex: {value: number}){ - // 我把所有的索引都用偏移量+1来存储,这样在bucket list中0就意味着实际上不存在 - // 当读取时,偏移量必须再偏移-1才是真实的 - // 这样我就避免了将数组初始化为-1 - let hash = FasterDictionary.hash(key); - let bucketIndex = FasterDictionary.reduce(hash, this._buckets.length); - - let valueIndex = NumberExtension.toNumber(this._buckets[bucketIndex]) - 1; - - // 即使我们找到了一个现有的值,我们也需要确定它是我们所要求的值 - while (valueIndex != -1){ - if (this._valuesInfo[valueIndex].hashcode == hash && this._valuesInfo[valueIndex].key == key){ - findIndex.value = valueIndex; - return true; - } - - valueIndex = this._valuesInfo[valueIndex].previous; - } - - findIndex.value = 0; - return false; - } - - public getDirectValue(index: number): TValue { - return this._values[index]; - } - - public getIndex(key: TKey): number { - let findIndex = {value: 0}; - if (this.tryFindIndex(key, findIndex)) - return findIndex.value; - - throw new Error("未找到key"); - } - - public static updateLinkedList(index: number, valuesInfo: FastNode[]){ - let next = valuesInfo[index].next; - let previous = valuesInfo[index].previous; - - if (next != -1) - valuesInfo[next].previous = previous; - if (previous != -1) - valuesInfo[previous].next = next; - } - - public static hash(key) { - return HashHelpers.getHashCode(key); - } - - public static reduce(x: number, n: number) { - if (x >= n) - return x % n; - - return x; - } - } - - export class FastNode { - readonly key; - readonly hashcode: number; - previous: number; - next: number; - - constructor(key, hash: number, previousNode: number = -1) { - this.key = key; - this.hashcode = hash; - this.previous = previousNode; - this.next = -1; - } - } -} \ No newline at end of file