移除fastlist(经测试比Array并没有快)
This commit is contained in:
Submodule demo/egret_demo updated: b478905960...297d63dfec
Submodule demo/laya_demo updated: ef025467dc...b18de7a1aa
89
source/bin/framework.d.ts
vendored
89
source/bin/framework.d.ts
vendored
@@ -95,7 +95,7 @@ declare module es {
|
|||||||
/**
|
/**
|
||||||
* 全局访问系统
|
* 全局访问系统
|
||||||
*/
|
*/
|
||||||
_globalManagers: FastList<GlobalManager>;
|
_globalManagers: GlobalManager[];
|
||||||
_timerManager: TimerManager;
|
_timerManager: TimerManager;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
@@ -206,6 +206,9 @@ declare module es {
|
|||||||
* 指定应该调用这个entity update方法的频率。1表示每一帧,2表示每一帧,以此类推
|
* 指定应该调用这个entity update方法的频率。1表示每一帧,2表示每一帧,以此类推
|
||||||
*/
|
*/
|
||||||
updateInterval: number;
|
updateInterval: number;
|
||||||
|
/**
|
||||||
|
* 返回一个BitSet实例,包含实体拥有的组件的位
|
||||||
|
*/
|
||||||
componentBits: BitSet;
|
componentBits: BitSet;
|
||||||
constructor(name: string);
|
constructor(name: string);
|
||||||
_isDestroyed: boolean;
|
_isDestroyed: boolean;
|
||||||
@@ -351,7 +354,7 @@ declare module es {
|
|||||||
* 管理所有实体处理器
|
* 管理所有实体处理器
|
||||||
*/
|
*/
|
||||||
readonly entityProcessors: EntityProcessorList;
|
readonly entityProcessors: EntityProcessorList;
|
||||||
readonly _sceneComponents: FastList<SceneComponent>;
|
readonly _sceneComponents: SceneComponent[];
|
||||||
_didSceneBegin: any;
|
_didSceneBegin: any;
|
||||||
constructor();
|
constructor();
|
||||||
/**
|
/**
|
||||||
@@ -1041,7 +1044,10 @@ declare module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class EntitySystem {
|
/**
|
||||||
|
* 追踪实体的子集,但不实现任何排序或迭代。
|
||||||
|
*/
|
||||||
|
abstract class EntitySystem {
|
||||||
private _entities;
|
private _entities;
|
||||||
constructor(matcher?: Matcher);
|
constructor(matcher?: Matcher);
|
||||||
private _scene;
|
private _scene;
|
||||||
@@ -1065,6 +1071,9 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
/**
|
/**
|
||||||
* 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础
|
* 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础
|
||||||
|
*
|
||||||
|
* 按实体引用遍历实体订阅成员实体的系统
|
||||||
|
* 当你需要处理与Matcher相匹配的实体,并且你更喜欢使用Entity的时候,可以使用这个功能。
|
||||||
*/
|
*/
|
||||||
abstract class EntityProcessingSystem extends EntitySystem {
|
abstract class EntityProcessingSystem extends EntitySystem {
|
||||||
constructor(matcher: Matcher);
|
constructor(matcher: Matcher);
|
||||||
@@ -1129,11 +1138,11 @@ declare module es {
|
|||||||
/**
|
/**
|
||||||
* 添加到实体的组件列表
|
* 添加到实体的组件列表
|
||||||
*/
|
*/
|
||||||
_components: FastList<Component>;
|
_components: Component[];
|
||||||
/**
|
/**
|
||||||
* 所有需要更新的组件列表
|
* 所有需要更新的组件列表
|
||||||
*/
|
*/
|
||||||
_updatableComponents: FastList<IUpdatable>;
|
_updatableComponents: IUpdatable[];
|
||||||
/**
|
/**
|
||||||
* 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工
|
* 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工
|
||||||
*/
|
*/
|
||||||
@@ -1197,7 +1206,7 @@ declare module es {
|
|||||||
/**
|
/**
|
||||||
* 场景中添加的实体列表
|
* 场景中添加的实体列表
|
||||||
*/
|
*/
|
||||||
_entities: FastList<Entity>;
|
_entities: Entity[];
|
||||||
/**
|
/**
|
||||||
* 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们
|
* 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们
|
||||||
*/
|
*/
|
||||||
@@ -1217,7 +1226,7 @@ declare module es {
|
|||||||
_unsortedTags: Set<number>;
|
_unsortedTags: Set<number>;
|
||||||
constructor(scene: Scene);
|
constructor(scene: Scene);
|
||||||
readonly count: number;
|
readonly count: number;
|
||||||
readonly buffer: FastList<Entity>;
|
readonly buffer: Entity[];
|
||||||
markEntityListUnsorted(): void;
|
markEntityListUnsorted(): void;
|
||||||
markTagUnsorted(tag: number): void;
|
markTagUnsorted(tag: number): void;
|
||||||
/**
|
/**
|
||||||
@@ -1592,7 +1601,7 @@ declare module es {
|
|||||||
* 提供了一系列立方贝塞尔点,并提供了帮助方法来访问贝塞尔
|
* 提供了一系列立方贝塞尔点,并提供了帮助方法来访问贝塞尔
|
||||||
*/
|
*/
|
||||||
class BezierSpline {
|
class BezierSpline {
|
||||||
_points: FastList<Vector2>;
|
_points: Vector2[];
|
||||||
_curveCount: number;
|
_curveCount: number;
|
||||||
/**
|
/**
|
||||||
* 在这个过程中,t被修改为在曲线段的范围内。
|
* 在这个过程中,t被修改为在曲线段的范围内。
|
||||||
@@ -3199,70 +3208,6 @@ declare namespace stopwatch {
|
|||||||
readonly duration: number;
|
readonly duration: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
/**
|
|
||||||
* 围绕一个数组的非常基本的包装,当它达到容量时自动扩展。
|
|
||||||
* 注意,在迭代时应该这样直接访问缓冲区,但使用FastList.length字段。
|
|
||||||
*
|
|
||||||
* @tutorial
|
|
||||||
* for( var i = 0; i <= list.length; i++ )
|
|
||||||
* var item = list.buffer[i];
|
|
||||||
*/
|
|
||||||
class FastList<T> {
|
|
||||||
/**
|
|
||||||
* 直接访问后备缓冲区。
|
|
||||||
* 不要使用buffer.Length! 使用FastList.length
|
|
||||||
*/
|
|
||||||
buffer: T[];
|
|
||||||
/**
|
|
||||||
* 直接访问缓冲区内填充项的长度。不要改变。
|
|
||||||
*/
|
|
||||||
length: number;
|
|
||||||
constructor(size?: number);
|
|
||||||
/**
|
|
||||||
* 清空列表并清空缓冲区中的所有项目
|
|
||||||
*/
|
|
||||||
clear(): void;
|
|
||||||
/**
|
|
||||||
* 和clear的工作原理一样,只是它不会将缓冲区中的所有项目清空。
|
|
||||||
*/
|
|
||||||
reset(): void;
|
|
||||||
/**
|
|
||||||
* 将该项目添加到列表中
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
add(item: T): void;
|
|
||||||
/**
|
|
||||||
* 从列表中删除该项目
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
remove(item: T): void;
|
|
||||||
/**
|
|
||||||
* 从列表中删除给定索引的项目。
|
|
||||||
* @param index
|
|
||||||
*/
|
|
||||||
removeAt(index: number): void;
|
|
||||||
/**
|
|
||||||
* 检查项目是否在FastList中
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
contains(item: T): boolean;
|
|
||||||
/**
|
|
||||||
* 如果缓冲区达到最大,将分配更多的空间来容纳额外的ItemCount。
|
|
||||||
* @param additionalItemCount
|
|
||||||
*/
|
|
||||||
ensureCapacity(additionalItemCount?: number): void;
|
|
||||||
/**
|
|
||||||
* 添加数组中的所有项目
|
|
||||||
* @param array
|
|
||||||
*/
|
|
||||||
addRange(array: T[]): void;
|
|
||||||
/**
|
|
||||||
* 对缓冲区中的所有项目进行排序,长度不限。
|
|
||||||
*/
|
|
||||||
sort(comparer: IComparer<T>): void;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
/**
|
/**
|
||||||
* 创建这个字典的原因只有一个:
|
* 创建这个字典的原因只有一个:
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ var es;
|
|||||||
/**
|
/**
|
||||||
* 全局访问系统
|
* 全局访问系统
|
||||||
*/
|
*/
|
||||||
this._globalManagers = new es.FastList();
|
this._globalManagers = [];
|
||||||
this._timerManager = new es.TimerManager();
|
this._timerManager = new es.TimerManager();
|
||||||
this._frameCounterElapsedTime = 0;
|
this._frameCounterElapsedTime = 0;
|
||||||
this._frameCounter = 0;
|
this._frameCounter = 0;
|
||||||
@@ -256,7 +256,7 @@ var es;
|
|||||||
* @param manager
|
* @param manager
|
||||||
*/
|
*/
|
||||||
Core.registerGlobalManager = function (manager) {
|
Core.registerGlobalManager = function (manager) {
|
||||||
this._instance._globalManagers.add(manager);
|
this._instance._globalManagers.push(manager);
|
||||||
manager.enabled = true;
|
manager.enabled = true;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -264,7 +264,7 @@ var es;
|
|||||||
* @param manager
|
* @param manager
|
||||||
*/
|
*/
|
||||||
Core.unregisterGlobalManager = function (manager) {
|
Core.unregisterGlobalManager = function (manager) {
|
||||||
this._instance._globalManagers.remove(manager);
|
new linq.List(this._instance._globalManagers).remove(manager);
|
||||||
manager.enabled = false;
|
manager.enabled = false;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -273,8 +273,8 @@ var es;
|
|||||||
*/
|
*/
|
||||||
Core.getGlobalManager = function (type) {
|
Core.getGlobalManager = function (type) {
|
||||||
for (var i = 0; i < this._instance._globalManagers.length; i++) {
|
for (var i = 0; i < this._instance._globalManagers.length; i++) {
|
||||||
if (this._instance._globalManagers.buffer[i] instanceof type)
|
if (this._instance._globalManagers[i] instanceof type)
|
||||||
return this._instance._globalManagers.buffer[i];
|
return this._instance._globalManagers[i];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@@ -339,8 +339,8 @@ var es;
|
|||||||
es.Time.update(currentTime);
|
es.Time.update(currentTime);
|
||||||
if (this._scene != null) {
|
if (this._scene != null) {
|
||||||
for (i = this._globalManagers.length - 1; i >= 0; i--) {
|
for (i = this._globalManagers.length - 1; i >= 0; i--) {
|
||||||
if (this._globalManagers.buffer[i].enabled)
|
if (this._globalManagers[i].enabled)
|
||||||
this._globalManagers.buffer[i].update();
|
this._globalManagers[i].update();
|
||||||
}
|
}
|
||||||
this._scene.update();
|
this._scene.update();
|
||||||
if (this._nextScene != null) {
|
if (this._nextScene != null) {
|
||||||
@@ -795,7 +795,7 @@ var es;
|
|||||||
/** 场景 */
|
/** 场景 */
|
||||||
var Scene = /** @class */ (function () {
|
var Scene = /** @class */ (function () {
|
||||||
function Scene() {
|
function Scene() {
|
||||||
this._sceneComponents = new es.FastList();
|
this._sceneComponents = [];
|
||||||
this.entities = new es.EntityList(this);
|
this.entities = new es.EntityList(this);
|
||||||
if (es.Core.entitySystemsEnabled)
|
if (es.Core.entitySystemsEnabled)
|
||||||
this.entityProcessors = new es.EntityProcessorList();
|
this.entityProcessors = new es.EntityProcessorList();
|
||||||
@@ -834,9 +834,9 @@ var es;
|
|||||||
es.Core.emitter.removeObserver(es.CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
es.Core.emitter.removeObserver(es.CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
for (var i = 0; i < this._sceneComponents.length; i++) {
|
for (var i = 0; i < this._sceneComponents.length; i++) {
|
||||||
this._sceneComponents.buffer[i].onRemovedFromScene();
|
this._sceneComponents[i].onRemovedFromScene();
|
||||||
}
|
}
|
||||||
this._sceneComponents.clear();
|
this._sceneComponents.length = 0;
|
||||||
es.Physics.clear();
|
es.Physics.clear();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.end();
|
this.entityProcessors.end();
|
||||||
@@ -848,8 +848,8 @@ var es;
|
|||||||
// 更新我们的列表,以防它们有任何变化
|
// 更新我们的列表,以防它们有任何变化
|
||||||
this.entities.updateLists();
|
this.entities.updateLists();
|
||||||
for (var i = this._sceneComponents.length - 1; i >= 0; i--) {
|
for (var i = this._sceneComponents.length - 1; i >= 0; i--) {
|
||||||
if (this._sceneComponents.buffer[i].enabled)
|
if (this._sceneComponents[i].enabled)
|
||||||
this._sceneComponents.buffer[i].update();
|
this._sceneComponents[i].update();
|
||||||
}
|
}
|
||||||
// 更新我们的实体解析器
|
// 更新我们的实体解析器
|
||||||
if (this.entityProcessors != null)
|
if (this.entityProcessors != null)
|
||||||
@@ -866,8 +866,8 @@ var es;
|
|||||||
Scene.prototype.addSceneComponent = function (component) {
|
Scene.prototype.addSceneComponent = function (component) {
|
||||||
component.scene = this;
|
component.scene = this;
|
||||||
component.onEnabled();
|
component.onEnabled();
|
||||||
this._sceneComponents.add(component);
|
this._sceneComponents.push(component);
|
||||||
this._sceneComponents.sort(component);
|
this._sceneComponents.sort(component.compare);
|
||||||
return component;
|
return component;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -876,7 +876,7 @@ var es;
|
|||||||
*/
|
*/
|
||||||
Scene.prototype.getSceneComponent = function (type) {
|
Scene.prototype.getSceneComponent = function (type) {
|
||||||
for (var i = 0; i < this._sceneComponents.length; i++) {
|
for (var i = 0; i < this._sceneComponents.length; i++) {
|
||||||
var component = this._sceneComponents.buffer[i];
|
var component = this._sceneComponents[i];
|
||||||
if (component instanceof type)
|
if (component instanceof type)
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
@@ -897,11 +897,11 @@ var es;
|
|||||||
* @param component
|
* @param component
|
||||||
*/
|
*/
|
||||||
Scene.prototype.removeSceneComponent = function (component) {
|
Scene.prototype.removeSceneComponent = function (component) {
|
||||||
if (!this._sceneComponents.contains(component)) {
|
if (!new linq.List(this._sceneComponents).contains(component)) {
|
||||||
console.warn("SceneComponent" + component + "\u4E0D\u5728SceneComponents\u5217\u8868\u4E2D!");
|
console.warn("SceneComponent" + component + "\u4E0D\u5728SceneComponents\u5217\u8868\u4E2D!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._sceneComponents.remove(component);
|
new linq.List(this._sceneComponents).remove(component);
|
||||||
component.onRemovedFromScene();
|
component.onRemovedFromScene();
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -917,7 +917,7 @@ var es;
|
|||||||
* @param entity
|
* @param entity
|
||||||
*/
|
*/
|
||||||
Scene.prototype.addEntity = function (entity) {
|
Scene.prototype.addEntity = function (entity) {
|
||||||
if (this.entities.buffer.contains(entity))
|
if (new linq.List(this.entities.buffer).contains(entity))
|
||||||
console.warn("\u60A8\u8BD5\u56FE\u5C06\u540C\u4E00\u5B9E\u4F53\u6DFB\u52A0\u5230\u573A\u666F\u4E24\u6B21: " + entity);
|
console.warn("\u60A8\u8BD5\u56FE\u5C06\u540C\u4E00\u5B9E\u4F53\u6DFB\u52A0\u5230\u573A\u666F\u4E24\u6B21: " + entity);
|
||||||
this.entities.add(entity);
|
this.entities.add(entity);
|
||||||
entity.scene = this;
|
entity.scene = this;
|
||||||
@@ -1579,7 +1579,7 @@ var es;
|
|||||||
SceneComponent.prototype.setUpdateOrder = function (updateOrder) {
|
SceneComponent.prototype.setUpdateOrder = function (updateOrder) {
|
||||||
if (this.updateOrder != updateOrder) {
|
if (this.updateOrder != updateOrder) {
|
||||||
this.updateOrder = updateOrder;
|
this.updateOrder = updateOrder;
|
||||||
es.Core.scene._sceneComponents.sort(this);
|
es.Core.scene._sceneComponents.sort(this.compare);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@@ -1850,18 +1850,37 @@ var es;
|
|||||||
function TriggerListenerHelper() {
|
function TriggerListenerHelper() {
|
||||||
}
|
}
|
||||||
TriggerListenerHelper.getITriggerListener = function (entity, components) {
|
TriggerListenerHelper.getITriggerListener = function (entity, components) {
|
||||||
for (var i = 0; i < entity.components._components.length; i++) {
|
var e_2, _a, e_3, _b;
|
||||||
var component = entity.components._components.buffer[i];
|
try {
|
||||||
|
for (var _c = __values(entity.components._components), _d = _c.next(); !_d.done; _d = _c.next()) {
|
||||||
|
var component = _d.value;
|
||||||
if (es.isITriggerListener(component)) {
|
if (es.isITriggerListener(component)) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var i = 0; i < entity.components._componentsToAdd.length; i++) {
|
}
|
||||||
var component = entity.components._componentsToAdd[i];
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
||||||
|
}
|
||||||
|
finally { if (e_2) throw e_2.error; }
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
for (var _e = __values(entity.components._componentsToAdd), _f = _e.next(); !_f.done; _f = _e.next()) {
|
||||||
|
var component = _f.value;
|
||||||
if (es.isITriggerListener(component)) {
|
if (es.isITriggerListener(component)) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
||||||
|
}
|
||||||
|
finally { if (e_3) throw e_3.error; }
|
||||||
|
}
|
||||||
return components;
|
return components;
|
||||||
};
|
};
|
||||||
return TriggerListenerHelper;
|
return TriggerListenerHelper;
|
||||||
@@ -1977,7 +1996,7 @@ var es;
|
|||||||
* @param motion
|
* @param motion
|
||||||
*/
|
*/
|
||||||
ProjectileMover.prototype.move = function (motion) {
|
ProjectileMover.prototype.move = function (motion) {
|
||||||
var e_2, _a;
|
var e_4, _a;
|
||||||
if (this._collider == null)
|
if (this._collider == null)
|
||||||
return false;
|
return false;
|
||||||
var didCollide = false;
|
var didCollide = false;
|
||||||
@@ -1994,12 +2013,12 @@ var es;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (neighbors_2_1 && !neighbors_2_1.done && (_a = neighbors_2.return)) _a.call(neighbors_2);
|
if (neighbors_2_1 && !neighbors_2_1.done && (_a = neighbors_2.return)) _a.call(neighbors_2);
|
||||||
}
|
}
|
||||||
finally { if (e_2) throw e_2.error; }
|
finally { if (e_4) throw e_4.error; }
|
||||||
}
|
}
|
||||||
return didCollide;
|
return didCollide;
|
||||||
};
|
};
|
||||||
@@ -2378,6 +2397,9 @@ var es;
|
|||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
|
/**
|
||||||
|
* 追踪实体的子集,但不实现任何排序或迭代。
|
||||||
|
*/
|
||||||
var EntitySystem = /** @class */ (function () {
|
var EntitySystem = /** @class */ (function () {
|
||||||
function EntitySystem(matcher) {
|
function EntitySystem(matcher) {
|
||||||
this._entities = [];
|
this._entities = [];
|
||||||
@@ -2449,6 +2471,9 @@ var es;
|
|||||||
(function (es) {
|
(function (es) {
|
||||||
/**
|
/**
|
||||||
* 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础
|
* 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础
|
||||||
|
*
|
||||||
|
* 按实体引用遍历实体订阅成员实体的系统
|
||||||
|
* 当你需要处理与Matcher相匹配的实体,并且你更喜欢使用Entity的时候,可以使用这个功能。
|
||||||
*/
|
*/
|
||||||
var EntityProcessingSystem = /** @class */ (function (_super) {
|
var EntityProcessingSystem = /** @class */ (function (_super) {
|
||||||
__extends(EntityProcessingSystem, _super);
|
__extends(EntityProcessingSystem, _super);
|
||||||
@@ -2639,11 +2664,11 @@ var es;
|
|||||||
/**
|
/**
|
||||||
* 添加到实体的组件列表
|
* 添加到实体的组件列表
|
||||||
*/
|
*/
|
||||||
this._components = new es.FastList();
|
this._components = [];
|
||||||
/**
|
/**
|
||||||
* 所有需要更新的组件列表
|
* 所有需要更新的组件列表
|
||||||
*/
|
*/
|
||||||
this._updatableComponents = new es.FastList();
|
this._updatableComponents = [];
|
||||||
/**
|
/**
|
||||||
* 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工
|
* 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工
|
||||||
*/
|
*/
|
||||||
@@ -2664,7 +2689,7 @@ var es;
|
|||||||
});
|
});
|
||||||
Object.defineProperty(ComponentList.prototype, "buffer", {
|
Object.defineProperty(ComponentList.prototype, "buffer", {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this._components.buffer;
|
return this._components;
|
||||||
},
|
},
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
@@ -2694,35 +2719,55 @@ var es;
|
|||||||
for (var i = 0; i < this._components.length; i++) {
|
for (var i = 0; i < this._components.length; i++) {
|
||||||
this.handleRemove(this._components[i]);
|
this.handleRemove(this._components[i]);
|
||||||
}
|
}
|
||||||
this._components.clear();
|
this._components.length = 0;
|
||||||
this._updatableComponents.clear();
|
this._updatableComponents.length = 0;
|
||||||
this._componentsToAdd.length = 0;
|
this._componentsToAdd.length = 0;
|
||||||
this._componentsToRemove.length = 0;
|
this._componentsToRemove.length = 0;
|
||||||
};
|
};
|
||||||
ComponentList.prototype.deregisterAllComponents = function () {
|
ComponentList.prototype.deregisterAllComponents = function () {
|
||||||
for (var i = 0; i < this._components.length; i++) {
|
var e_5, _a;
|
||||||
var component = this._components.buffer[i];
|
try {
|
||||||
|
for (var _b = __values(this._components), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||||
|
var component = _c.value;
|
||||||
if (!component)
|
if (!component)
|
||||||
continue;
|
continue;
|
||||||
// 处理IUpdatable
|
// 处理IUpdatable
|
||||||
if (es.isIUpdatable(component))
|
if (es.isIUpdatable(component))
|
||||||
this._updatableComponents.remove(component);
|
new linq.List(this._updatableComponents).remove(component);
|
||||||
if (es.Core.entitySystemsEnabled) {
|
if (es.Core.entitySystemsEnabled) {
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)), false);
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||||
|
}
|
||||||
|
finally { if (e_5) throw e_5.error; }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
ComponentList.prototype.registerAllComponents = function () {
|
ComponentList.prototype.registerAllComponents = function () {
|
||||||
for (var i = 0; i < this._components.length; i++) {
|
var e_6, _a;
|
||||||
var component = this._components.buffer[i];
|
try {
|
||||||
|
for (var _b = __values(this._components), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||||
|
var component = _c.value;
|
||||||
if (es.isIUpdatable(component))
|
if (es.isIUpdatable(component))
|
||||||
this._updatableComponents.add(component);
|
this._updatableComponents.push(component);
|
||||||
if (es.Core.entitySystemsEnabled) {
|
if (es.Core.entitySystemsEnabled) {
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)));
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||||
|
}
|
||||||
|
finally { if (e_6) throw e_6.error; }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 处理任何需要删除或添加的组件
|
* 处理任何需要删除或添加的组件
|
||||||
@@ -2731,7 +2776,7 @@ var es;
|
|||||||
if (this._componentsToRemove.length > 0) {
|
if (this._componentsToRemove.length > 0) {
|
||||||
for (var i = 0; i < this._componentsToRemove.length; i++) {
|
for (var i = 0; i < this._componentsToRemove.length; i++) {
|
||||||
this.handleRemove(this._componentsToRemove[i]);
|
this.handleRemove(this._componentsToRemove[i]);
|
||||||
this._components.remove(this._componentsToRemove[i]);
|
new linq.List(this._components).remove(this._componentsToRemove[i]);
|
||||||
}
|
}
|
||||||
this._componentsToRemove.length = 0;
|
this._componentsToRemove.length = 0;
|
||||||
}
|
}
|
||||||
@@ -2739,12 +2784,12 @@ var es;
|
|||||||
for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
||||||
var component = this._componentsToAdd[i];
|
var component = this._componentsToAdd[i];
|
||||||
if (es.isIUpdatable(component))
|
if (es.isIUpdatable(component))
|
||||||
this._updatableComponents.add(component);
|
this._updatableComponents.push(component);
|
||||||
if (es.Core.entitySystemsEnabled) {
|
if (es.Core.entitySystemsEnabled) {
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)));
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
this._components.add(component);
|
this._components.push(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
}
|
}
|
||||||
// 在调用onAddedToEntity之前清除,以防添加更多组件
|
// 在调用onAddedToEntity之前清除,以防添加更多组件
|
||||||
@@ -2762,7 +2807,7 @@ var es;
|
|||||||
this._tempBufferList.length = 0;
|
this._tempBufferList.length = 0;
|
||||||
}
|
}
|
||||||
if (this._isComponentListUnsorted) {
|
if (this._isComponentListUnsorted) {
|
||||||
this._updatableComponents.sort(ComponentList.compareUpdatableOrder);
|
this._updatableComponents.sort(ComponentList.compareUpdatableOrder.compare);
|
||||||
this._isComponentListUnsorted = false;
|
this._isComponentListUnsorted = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2770,7 +2815,7 @@ var es;
|
|||||||
if (!component)
|
if (!component)
|
||||||
return;
|
return;
|
||||||
if (es.isIUpdatable(component))
|
if (es.isIUpdatable(component))
|
||||||
this._updatableComponents.remove(component);
|
new linq.List(this._updatableComponents).remove(component);
|
||||||
if (es.Core.entitySystemsEnabled) {
|
if (es.Core.entitySystemsEnabled) {
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)), false);
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(es.TypeUtils.getType(component)), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
@@ -2786,19 +2831,38 @@ var es;
|
|||||||
* @param onlyReturnInitializedComponents
|
* @param onlyReturnInitializedComponents
|
||||||
*/
|
*/
|
||||||
ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) {
|
ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) {
|
||||||
for (var i = 0; i < this._components.length; i++) {
|
var e_7, _a, e_8, _b;
|
||||||
var component = this._components.buffer[i];
|
try {
|
||||||
|
for (var _c = __values(this._components), _d = _c.next(); !_d.done; _d = _c.next()) {
|
||||||
|
var component = _d.value;
|
||||||
if (component instanceof type)
|
if (component instanceof type)
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
||||||
|
}
|
||||||
|
finally { if (e_7) throw e_7.error; }
|
||||||
|
}
|
||||||
// 我们可以选择检查挂起的组件,以防addComponent和getComponent在同一个框架中被调用
|
// 我们可以选择检查挂起的组件,以防addComponent和getComponent在同一个框架中被调用
|
||||||
if (!onlyReturnInitializedComponents) {
|
if (!onlyReturnInitializedComponents) {
|
||||||
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
try {
|
||||||
var component = this._componentsToAdd[i];
|
for (var _e = __values(this._componentsToAdd), _f = _e.next(); !_f.done; _f = _e.next()) {
|
||||||
|
var component = _f.value;
|
||||||
if (component instanceof type)
|
if (component instanceof type)
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
||||||
|
}
|
||||||
|
finally { if (e_8) throw e_8.error; }
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -2807,34 +2871,53 @@ var es;
|
|||||||
* @param components
|
* @param components
|
||||||
*/
|
*/
|
||||||
ComponentList.prototype.getComponents = function (typeName, components) {
|
ComponentList.prototype.getComponents = function (typeName, components) {
|
||||||
|
var e_9, _a, e_10, _b;
|
||||||
if (!components)
|
if (!components)
|
||||||
components = [];
|
components = [];
|
||||||
for (var i = 0; i < this._components.length; i++) {
|
try {
|
||||||
var component = this._components.buffer[i];
|
for (var _c = __values(this._components), _d = _c.next(); !_d.done; _d = _c.next()) {
|
||||||
|
var component = _d.value;
|
||||||
if (component instanceof typeName) {
|
if (component instanceof typeName) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
||||||
|
}
|
||||||
|
finally { if (e_9) throw e_9.error; }
|
||||||
|
}
|
||||||
|
try {
|
||||||
// 我们还检查了待处理的组件,以防在同一帧中调用addComponent和getComponent
|
// 我们还检查了待处理的组件,以防在同一帧中调用addComponent和getComponent
|
||||||
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
for (var _e = __values(this._componentsToAdd), _f = _e.next(); !_f.done; _f = _e.next()) {
|
||||||
var component = this._componentsToAdd[i];
|
var component = _f.value;
|
||||||
if (component instanceof typeName) {
|
if (component instanceof typeName) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
||||||
|
}
|
||||||
|
finally { if (e_10) throw e_10.error; }
|
||||||
|
}
|
||||||
return components;
|
return components;
|
||||||
};
|
};
|
||||||
ComponentList.prototype.update = function () {
|
ComponentList.prototype.update = function () {
|
||||||
this.updateLists();
|
this.updateLists();
|
||||||
for (var i = 0; i < this._updatableComponents.length; i++) {
|
for (var i = 0; i < this._updatableComponents.length; i++) {
|
||||||
if (this._updatableComponents.buffer[i].enabled)
|
if (this._updatableComponents[i].enabled)
|
||||||
this._updatableComponents.buffer[i].update();
|
this._updatableComponents[i].update();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ComponentList.prototype.onEntityTransformChanged = function (comp) {
|
ComponentList.prototype.onEntityTransformChanged = function (comp) {
|
||||||
for (var i = 0; i < this._components.length; i++) {
|
for (var i = 0; i < this._components.length; i++) {
|
||||||
if (this._components.buffer[i].enabled)
|
if (this._components[i].enabled)
|
||||||
this._components.buffer[i].onEntityTransformChanged(comp);
|
this._components[i].onEntityTransformChanged(comp);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
||||||
if (this._componentsToAdd[i].enabled)
|
if (this._componentsToAdd[i].enabled)
|
||||||
@@ -2843,11 +2926,11 @@ var es;
|
|||||||
};
|
};
|
||||||
ComponentList.prototype.onEntityEnabled = function () {
|
ComponentList.prototype.onEntityEnabled = function () {
|
||||||
for (var i = 0; i < this._components.length; i++)
|
for (var i = 0; i < this._components.length; i++)
|
||||||
this._components.buffer[i].onEnabled();
|
this._components[i].onEnabled();
|
||||||
};
|
};
|
||||||
ComponentList.prototype.onEntityDisabled = function () {
|
ComponentList.prototype.onEntityDisabled = function () {
|
||||||
for (var i = 0; i < this._components.length; i++)
|
for (var i = 0; i < this._components.length; i++)
|
||||||
this._components.buffer[i].onDisabled();
|
this._components[i].onDisabled();
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 组件列表的全局updateOrder排序
|
* 组件列表的全局updateOrder排序
|
||||||
@@ -2889,7 +2972,7 @@ var es;
|
|||||||
/**
|
/**
|
||||||
* 场景中添加的实体列表
|
* 场景中添加的实体列表
|
||||||
*/
|
*/
|
||||||
this._entities = new es.FastList();
|
this._entities = [];
|
||||||
/**
|
/**
|
||||||
* 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们
|
* 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们
|
||||||
*/
|
*/
|
||||||
@@ -2960,11 +3043,11 @@ var es;
|
|||||||
// 它们仍然会在_entitiesToRemove列表中,这将由updateLists处理。
|
// 它们仍然会在_entitiesToRemove列表中,这将由updateLists处理。
|
||||||
this.updateLists();
|
this.updateLists();
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
this._entities.buffer[i]._isDestroyed = true;
|
this._entities[i]._isDestroyed = true;
|
||||||
this._entities.buffer[i].onRemovedFromScene();
|
this._entities[i].onRemovedFromScene();
|
||||||
this._entities.buffer[i].scene = null;
|
this._entities[i].scene = null;
|
||||||
}
|
}
|
||||||
this._entities.clear();
|
this._entities.length = 0;
|
||||||
this._entityDict.clear();
|
this._entityDict.clear();
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -2972,7 +3055,7 @@ var es;
|
|||||||
* @param entity
|
* @param entity
|
||||||
*/
|
*/
|
||||||
EntityList.prototype.contains = function (entity) {
|
EntityList.prototype.contains = function (entity) {
|
||||||
return this._entities.contains(entity) || this._entitiesToAdded.contains(entity);
|
return new linq.List(this._entities).contains(entity) || this._entitiesToAdded.contains(entity);
|
||||||
};
|
};
|
||||||
EntityList.prototype.getTagList = function (tag) {
|
EntityList.prototype.getTagList = function (tag) {
|
||||||
var list = this._entityDict.get(tag);
|
var list = this._entityDict.get(tag);
|
||||||
@@ -2996,11 +3079,21 @@ var es;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
EntityList.prototype.update = function () {
|
EntityList.prototype.update = function () {
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
var e_11, _a;
|
||||||
var entity = this._entities.buffer[i];
|
try {
|
||||||
|
for (var _b = __values(this._entities), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||||
|
var entity = _c.value;
|
||||||
if (entity.enabled && (entity.updateInterval == 1 || es.Time.frameCount % entity.updateInterval == 0))
|
if (entity.enabled && (entity.updateInterval == 1 || es.Time.frameCount % entity.updateInterval == 0))
|
||||||
entity.update();
|
entity.update();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||||
|
}
|
||||||
|
finally { if (e_11) throw e_11.error; }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
EntityList.prototype.updateLists = function () {
|
EntityList.prototype.updateLists = function () {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
@@ -3009,7 +3102,7 @@ var es;
|
|||||||
// 处理标签列表
|
// 处理标签列表
|
||||||
_this.removeFromTagList(entity);
|
_this.removeFromTagList(entity);
|
||||||
// 处理常规实体列表
|
// 处理常规实体列表
|
||||||
_this._entities.remove(entity);
|
new linq.List(_this._entities).remove(entity);
|
||||||
entity.onRemovedFromScene();
|
entity.onRemovedFromScene();
|
||||||
entity.scene = null;
|
entity.scene = null;
|
||||||
if (es.Core.entitySystemsEnabled)
|
if (es.Core.entitySystemsEnabled)
|
||||||
@@ -3019,7 +3112,7 @@ var es;
|
|||||||
}
|
}
|
||||||
if (this._entitiesToAdded.getCount() > 0) {
|
if (this._entitiesToAdded.getCount() > 0) {
|
||||||
this._entitiesToAdded.toArray().forEach(function (entity) {
|
this._entitiesToAdded.toArray().forEach(function (entity) {
|
||||||
_this._entities.add(entity);
|
_this._entities.push(entity);
|
||||||
entity.scene = _this.scene;
|
entity.scene = _this.scene;
|
||||||
_this.addToTagList(entity);
|
_this.addToTagList(entity);
|
||||||
if (es.Core.entitySystemsEnabled)
|
if (es.Core.entitySystemsEnabled)
|
||||||
@@ -3032,7 +3125,7 @@ var es;
|
|||||||
this._isEntityListUnsorted = true;
|
this._isEntityListUnsorted = true;
|
||||||
}
|
}
|
||||||
if (this._isEntityListUnsorted) {
|
if (this._isEntityListUnsorted) {
|
||||||
this._entities.sort(es.Entity.entityComparer);
|
this._entities.sort(es.Entity.entityComparer.compare);
|
||||||
this._isEntityListUnsorted = false;
|
this._isEntityListUnsorted = false;
|
||||||
}
|
}
|
||||||
// 根据需要对标签列表进行排序
|
// 根据需要对标签列表进行排序
|
||||||
@@ -3047,8 +3140,8 @@ var es;
|
|||||||
*/
|
*/
|
||||||
EntityList.prototype.findEntity = function (name) {
|
EntityList.prototype.findEntity = function (name) {
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities.buffer[i].name == name)
|
if (this._entities[i].name == name)
|
||||||
return this._entities.buffer[i];
|
return this._entities[i];
|
||||||
}
|
}
|
||||||
for (var i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
for (var i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
||||||
var entity = this._entitiesToAdded.toArray()[i];
|
var entity = this._entitiesToAdded.toArray()[i];
|
||||||
@@ -3078,8 +3171,8 @@ var es;
|
|||||||
EntityList.prototype.entitiesOfType = function (type) {
|
EntityList.prototype.entitiesOfType = function (type) {
|
||||||
var list = es.ListPool.obtain();
|
var list = es.ListPool.obtain();
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities.buffer[i] instanceof type)
|
if (this._entities[i] instanceof type)
|
||||||
list.push(this._entities.buffer[i]);
|
list.push(this._entities[i]);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
for (var i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
||||||
var entity = this._entitiesToAdded.toArray()[i];
|
var entity = this._entitiesToAdded.toArray()[i];
|
||||||
@@ -3095,8 +3188,8 @@ var es;
|
|||||||
*/
|
*/
|
||||||
EntityList.prototype.findComponentOfType = function (type) {
|
EntityList.prototype.findComponentOfType = function (type) {
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities.buffer[i].enabled) {
|
if (this._entities[i].enabled) {
|
||||||
var comp = this._entities.buffer[i].getComponent(type);
|
var comp = this._entities[i].getComponent(type);
|
||||||
if (comp)
|
if (comp)
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
@@ -3119,8 +3212,8 @@ var es;
|
|||||||
EntityList.prototype.findComponentsOfType = function (type) {
|
EntityList.prototype.findComponentsOfType = function (type) {
|
||||||
var comps = es.ListPool.obtain();
|
var comps = es.ListPool.obtain();
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities.buffer[i].enabled)
|
if (this._entities[i].enabled)
|
||||||
this._entities.buffer[i].getComponents(type, comps);
|
this._entities[i].getComponents(type, comps);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
for (var i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
||||||
var entity = this._entitiesToAdded.toArray()[i];
|
var entity = this._entitiesToAdded.toArray()[i];
|
||||||
@@ -3950,7 +4043,7 @@ var es;
|
|||||||
*/
|
*/
|
||||||
var BezierSpline = /** @class */ (function () {
|
var BezierSpline = /** @class */ (function () {
|
||||||
function BezierSpline() {
|
function BezierSpline() {
|
||||||
this._points = new es.FastList();
|
this._points = [];
|
||||||
this._curveCount = 0;
|
this._curveCount = 0;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -3978,13 +4071,13 @@ var es;
|
|||||||
*/
|
*/
|
||||||
BezierSpline.prototype.setControlPoint = function (index, point) {
|
BezierSpline.prototype.setControlPoint = function (index, point) {
|
||||||
if (index % 3 == 0) {
|
if (index % 3 == 0) {
|
||||||
var delta = es.Vector2.subtract(point, this._points.buffer[index]);
|
var delta = es.Vector2.subtract(point, this._points[index]);
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
this._points.buffer[index - 1].add(delta);
|
this._points[index - 1].add(delta);
|
||||||
if (index + 1 < this._points.length)
|
if (index + 1 < this._points.length)
|
||||||
this._points.buffer[index + 1].add(delta);
|
this._points[index + 1].add(delta);
|
||||||
}
|
}
|
||||||
this._points.buffer[index] = point;
|
this._points[index] = point;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 得到时间t的贝塞尔曲线上的点
|
* 得到时间t的贝塞尔曲线上的点
|
||||||
@@ -3992,7 +4085,7 @@ var es;
|
|||||||
*/
|
*/
|
||||||
BezierSpline.prototype.getPointAtTime = function (t) {
|
BezierSpline.prototype.getPointAtTime = function (t) {
|
||||||
var i = this.pointIndexAtTime(new es.Ref(t));
|
var i = this.pointIndexAtTime(new es.Ref(t));
|
||||||
return es.Bezier.getPointThree(this._points.buffer[i], this._points.buffer[i + 1], this._points.buffer[i + 2], this._points.buffer[i + 3], t);
|
return es.Bezier.getPointThree(this._points[i], this._points[i + 1], this._points[i + 2], this._points[i + 3], t);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 得到贝塞尔在时间t的速度(第一导数)
|
* 得到贝塞尔在时间t的速度(第一导数)
|
||||||
@@ -4000,7 +4093,7 @@ var es;
|
|||||||
*/
|
*/
|
||||||
BezierSpline.prototype.getVelocityAtTime = function (t) {
|
BezierSpline.prototype.getVelocityAtTime = function (t) {
|
||||||
var i = this.pointIndexAtTime(new es.Ref(t));
|
var i = this.pointIndexAtTime(new es.Ref(t));
|
||||||
return es.Bezier.getFirstDerivativeThree(this._points.buffer[i], this._points.buffer[i + 1], this._points.buffer[i + 2], this._points.buffer[i + 3], t);
|
return es.Bezier.getFirstDerivativeThree(this._points[i], this._points[i + 1], this._points[i + 2], this._points[i + 3], t);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 得到时间t时贝塞尔的方向(归一化第一导数)
|
* 得到时间t时贝塞尔的方向(归一化第一导数)
|
||||||
@@ -4019,17 +4112,17 @@ var es;
|
|||||||
BezierSpline.prototype.addCurve = function (start, firstControlPoint, secondControlPoint, end) {
|
BezierSpline.prototype.addCurve = function (start, firstControlPoint, secondControlPoint, end) {
|
||||||
// 只有当这是第一条曲线时,我们才会添加起始点。对于其他所有的曲线,前一个曲线的终点应该等于新曲线的起点。
|
// 只有当这是第一条曲线时,我们才会添加起始点。对于其他所有的曲线,前一个曲线的终点应该等于新曲线的起点。
|
||||||
if (this._points.length == 0)
|
if (this._points.length == 0)
|
||||||
this._points.add(start);
|
this._points.push(start);
|
||||||
this._points.add(firstControlPoint);
|
this._points.push(firstControlPoint);
|
||||||
this._points.add(secondControlPoint);
|
this._points.push(secondControlPoint);
|
||||||
this._points.add(end);
|
this._points.push(end);
|
||||||
this._curveCount = (this._points.length - 1) / 3;
|
this._curveCount = (this._points.length - 1) / 3;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 重置bezier,移除所有点
|
* 重置bezier,移除所有点
|
||||||
*/
|
*/
|
||||||
BezierSpline.prototype.reset = function () {
|
BezierSpline.prototype.reset = function () {
|
||||||
this._points.clear();
|
this._points.length = 0;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 将splitine分解成totalSegments部分,并返回使用线条绘制所需的所有点
|
* 将splitine分解成totalSegments部分,并返回使用线条绘制所需的所有点
|
||||||
@@ -6142,7 +6235,7 @@ var es;
|
|||||||
* @param layerMask
|
* @param layerMask
|
||||||
*/
|
*/
|
||||||
SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) {
|
SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) {
|
||||||
var e_3, _a;
|
var e_12, _a;
|
||||||
var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);
|
var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);
|
||||||
this._overlapTestCircle.radius = radius;
|
this._overlapTestCircle.radius = radius;
|
||||||
this._overlapTestCircle.position = circleCenter;
|
this._overlapTestCircle.position = circleCenter;
|
||||||
@@ -6175,12 +6268,12 @@ var es;
|
|||||||
return resultCounter;
|
return resultCounter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (potentials_1_1 && !potentials_1_1.done && (_a = potentials_1.return)) _a.call(potentials_1);
|
if (potentials_1_1 && !potentials_1_1.done && (_a = potentials_1.return)) _a.call(potentials_1);
|
||||||
}
|
}
|
||||||
finally { if (e_3) throw e_3.error; }
|
finally { if (e_12) throw e_12.error; }
|
||||||
}
|
}
|
||||||
return resultCounter;
|
return resultCounter;
|
||||||
};
|
};
|
||||||
@@ -7793,121 +7886,6 @@ var stopwatch;
|
|||||||
var _defaultSystemTimeGetter = Date.now;
|
var _defaultSystemTimeGetter = Date.now;
|
||||||
})(stopwatch || (stopwatch = {}));
|
})(stopwatch || (stopwatch = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
|
||||||
/**
|
|
||||||
* 围绕一个数组的非常基本的包装,当它达到容量时自动扩展。
|
|
||||||
* 注意,在迭代时应该这样直接访问缓冲区,但使用FastList.length字段。
|
|
||||||
*
|
|
||||||
* @tutorial
|
|
||||||
* for( var i = 0; i <= list.length; i++ )
|
|
||||||
* var item = list.buffer[i];
|
|
||||||
*/
|
|
||||||
var FastList = /** @class */ (function () {
|
|
||||||
function FastList(size) {
|
|
||||||
if (size === void 0) { size = 5; }
|
|
||||||
/**
|
|
||||||
* 直接访问缓冲区内填充项的长度。不要改变。
|
|
||||||
*/
|
|
||||||
this.length = 0;
|
|
||||||
this.buffer = new Array(size);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 清空列表并清空缓冲区中的所有项目
|
|
||||||
*/
|
|
||||||
FastList.prototype.clear = function () {
|
|
||||||
this.buffer.length = 0;
|
|
||||||
this.length = 0;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 和clear的工作原理一样,只是它不会将缓冲区中的所有项目清空。
|
|
||||||
*/
|
|
||||||
FastList.prototype.reset = function () {
|
|
||||||
this.length = 0;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 将该项目添加到列表中
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
FastList.prototype.add = function (item) {
|
|
||||||
if (this.length == this.buffer.length)
|
|
||||||
this.buffer.length = Math.max(this.buffer.length << 1, 10);
|
|
||||||
this.buffer[this.length++] = item;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 从列表中删除该项目
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
FastList.prototype.remove = function (item) {
|
|
||||||
var comp = es.EqualityComparer.default();
|
|
||||||
for (var i = 0; i < this.length; ++i) {
|
|
||||||
if (comp.equals(this.buffer[i], item)) {
|
|
||||||
this.removeAt(i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 从列表中删除给定索引的项目。
|
|
||||||
* @param index
|
|
||||||
*/
|
|
||||||
FastList.prototype.removeAt = function (index) {
|
|
||||||
if (index >= this.length)
|
|
||||||
throw new Error("index超出范围!");
|
|
||||||
this.length--;
|
|
||||||
new linq.List(this.buffer).removeAt(index);
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 检查项目是否在FastList中
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
FastList.prototype.contains = function (item) {
|
|
||||||
var comp = es.EqualityComparer.default();
|
|
||||||
for (var i = 0; i < this.length; ++i) {
|
|
||||||
if (comp.equals(this.buffer[i], item))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 如果缓冲区达到最大,将分配更多的空间来容纳额外的ItemCount。
|
|
||||||
* @param additionalItemCount
|
|
||||||
*/
|
|
||||||
FastList.prototype.ensureCapacity = function (additionalItemCount) {
|
|
||||||
if (additionalItemCount === void 0) { additionalItemCount = 1; }
|
|
||||||
if (this.length + additionalItemCount >= this.buffer.length)
|
|
||||||
this.buffer.length = Math.max(this.buffer.length << 1, this.length + additionalItemCount);
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 添加数组中的所有项目
|
|
||||||
* @param array
|
|
||||||
*/
|
|
||||||
FastList.prototype.addRange = function (array) {
|
|
||||||
var e_4, _a;
|
|
||||||
try {
|
|
||||||
for (var array_1 = __values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
|
|
||||||
var item = array_1_1.value;
|
|
||||||
this.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
||||||
finally {
|
|
||||||
try {
|
|
||||||
if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
|
|
||||||
}
|
|
||||||
finally { if (e_4) throw e_4.error; }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 对缓冲区中的所有项目进行排序,长度不限。
|
|
||||||
*/
|
|
||||||
FastList.prototype.sort = function (comparer) {
|
|
||||||
this.buffer.sort(comparer.compare);
|
|
||||||
};
|
|
||||||
return FastList;
|
|
||||||
}());
|
|
||||||
es.FastList = FastList;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
(function (es) {
|
||||||
/**
|
/**
|
||||||
* 创建这个字典的原因只有一个:
|
* 创建这个字典的原因只有一个:
|
||||||
@@ -10083,7 +10061,7 @@ var linq;
|
|||||||
* 创建一个Set从一个Enumerable.List< T>。
|
* 创建一个Set从一个Enumerable.List< T>。
|
||||||
*/
|
*/
|
||||||
List.prototype.toSet = function () {
|
List.prototype.toSet = function () {
|
||||||
var e_5, _a;
|
var e_13, _a;
|
||||||
var result = new Set();
|
var result = new Set();
|
||||||
try {
|
try {
|
||||||
for (var _b = __values(this._elements), _c = _b.next(); !_c.done; _c = _b.next()) {
|
for (var _b = __values(this._elements), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||||
@@ -10091,12 +10069,12 @@ var linq;
|
|||||||
result.add(x);
|
result.add(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||||
}
|
}
|
||||||
finally { if (e_5) throw e_5.error; }
|
finally { if (e_13) throw e_13.error; }
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@@ -10345,7 +10323,7 @@ var es;
|
|||||||
* 计算可见性多边形,并返回三角形扇形的顶点(减去中心顶点)。返回的数组来自ListPool
|
* 计算可见性多边形,并返回三角形扇形的顶点(减去中心顶点)。返回的数组来自ListPool
|
||||||
*/
|
*/
|
||||||
VisibilityComputer.prototype.end = function () {
|
VisibilityComputer.prototype.end = function () {
|
||||||
var e_6, _a;
|
var e_14, _a;
|
||||||
var output = es.ListPool.obtain();
|
var output = es.ListPool.obtain();
|
||||||
this.updateSegments();
|
this.updateSegments();
|
||||||
this._endPoints.sort(this._radialComparer.compare);
|
this._endPoints.sort(this._radialComparer.compare);
|
||||||
@@ -10384,12 +10362,12 @@ var es;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||||
}
|
}
|
||||||
finally { if (e_6) throw e_6.error; }
|
finally { if (e_14) throw e_14.error; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VisibilityComputer._openSegments.clear();
|
VisibilityComputer._openSegments.clear();
|
||||||
@@ -10505,7 +10483,7 @@ var es;
|
|||||||
* 处理片段,以便我们稍后对它们进行分类
|
* 处理片段,以便我们稍后对它们进行分类
|
||||||
*/
|
*/
|
||||||
VisibilityComputer.prototype.updateSegments = function () {
|
VisibilityComputer.prototype.updateSegments = function () {
|
||||||
var e_7, _a;
|
var e_15, _a;
|
||||||
try {
|
try {
|
||||||
for (var _b = __values(this._segments), _c = _b.next(); !_c.done; _c = _b.next()) {
|
for (var _b = __values(this._segments), _c = _b.next(); !_c.done; _c = _b.next()) {
|
||||||
var segment = _c.value;
|
var segment = _c.value;
|
||||||
@@ -10523,12 +10501,12 @@ var es;
|
|||||||
segment.p2.begin = !segment.p1.begin;
|
segment.p2.begin = !segment.p1.begin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
||||||
}
|
}
|
||||||
finally { if (e_7) throw e_7.error; }
|
finally { if (e_15) throw e_15.error; }
|
||||||
}
|
}
|
||||||
// 如果我们有一个聚光灯,我们需要存储前两个段的角度。
|
// 如果我们有一个聚光灯,我们需要存储前两个段的角度。
|
||||||
// 这些是光斑的边界,我们将用它们来过滤它们之外的任何顶点。
|
// 这些是光斑的边界,我们将用它们来过滤它们之外的任何顶点。
|
||||||
|
|||||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -23,15 +23,13 @@ module es {
|
|||||||
|
|
||||||
export class TriggerListenerHelper {
|
export class TriggerListenerHelper {
|
||||||
public static getITriggerListener(entity: Entity, components: ITriggerListener[]){
|
public static getITriggerListener(entity: Entity, components: ITriggerListener[]){
|
||||||
for (let i = 0; i < entity.components._components.length; i++) {
|
for (let component of entity.components._components) {
|
||||||
let component = entity.components._components.buffer[i];
|
|
||||||
if (isITriggerListener(component)) {
|
if (isITriggerListener(component)) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < entity.components._componentsToAdd.length; i++) {
|
for (let component of entity.components._componentsToAdd) {
|
||||||
let component = entity.components._componentsToAdd[i];
|
|
||||||
if (isITriggerListener(component)) {
|
if (isITriggerListener(component)) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ module es {
|
|||||||
public setUpdateOrder(updateOrder: number){
|
public setUpdateOrder(updateOrder: number){
|
||||||
if (this.updateOrder != updateOrder){
|
if (this.updateOrder != updateOrder){
|
||||||
this.updateOrder = updateOrder;
|
this.updateOrder = updateOrder;
|
||||||
Core.scene._sceneComponents.sort(this);
|
Core.scene._sceneComponents.sort(this.compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ module es {
|
|||||||
/**
|
/**
|
||||||
* 全局访问系统
|
* 全局访问系统
|
||||||
*/
|
*/
|
||||||
public _globalManagers: FastList<GlobalManager> = new FastList<GlobalManager>();
|
public _globalManagers: GlobalManager[] = [];
|
||||||
public _timerManager: TimerManager = new TimerManager();
|
public _timerManager: TimerManager = new TimerManager();
|
||||||
public width: number;
|
public width: number;
|
||||||
public height: number;
|
public height: number;
|
||||||
@@ -98,7 +98,7 @@ module es {
|
|||||||
* @param manager
|
* @param manager
|
||||||
*/
|
*/
|
||||||
public static registerGlobalManager(manager: es.GlobalManager) {
|
public static registerGlobalManager(manager: es.GlobalManager) {
|
||||||
this._instance._globalManagers.add(manager);
|
this._instance._globalManagers.push(manager);
|
||||||
manager.enabled = true;
|
manager.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ module es {
|
|||||||
* @param manager
|
* @param manager
|
||||||
*/
|
*/
|
||||||
public static unregisterGlobalManager(manager: es.GlobalManager) {
|
public static unregisterGlobalManager(manager: es.GlobalManager) {
|
||||||
this._instance._globalManagers.remove(manager);
|
new linq.List(this._instance._globalManagers).remove(manager);
|
||||||
manager.enabled = false;
|
manager.enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,8 +117,8 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public static getGlobalManager<T extends es.GlobalManager>(type): T {
|
public static getGlobalManager<T extends es.GlobalManager>(type): T {
|
||||||
for (let i = 0; i < this._instance._globalManagers.length; i++) {
|
for (let i = 0; i < this._instance._globalManagers.length; i++) {
|
||||||
if (this._instance._globalManagers.buffer[i] instanceof type)
|
if (this._instance._globalManagers[i] instanceof type)
|
||||||
return this._instance._globalManagers.buffer[i] as T;
|
return this._instance._globalManagers[i] as T;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -183,8 +183,8 @@ module es {
|
|||||||
if (currentTime != null) Time.update(currentTime);
|
if (currentTime != null) Time.update(currentTime);
|
||||||
if (this._scene != null) {
|
if (this._scene != null) {
|
||||||
for (let i = this._globalManagers.length - 1; i >= 0; i--) {
|
for (let i = this._globalManagers.length - 1; i >= 0; i--) {
|
||||||
if (this._globalManagers.buffer[i].enabled)
|
if (this._globalManagers[i].enabled)
|
||||||
this._globalManagers.buffer[i].update();
|
this._globalManagers[i].update();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._scene.update();
|
this._scene.update();
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ module es {
|
|||||||
* 指定应该调用这个entity update方法的频率。1表示每一帧,2表示每一帧,以此类推
|
* 指定应该调用这个entity update方法的频率。1表示每一帧,2表示每一帧,以此类推
|
||||||
*/
|
*/
|
||||||
public updateInterval: number = 1;
|
public updateInterval: number = 1;
|
||||||
|
/**
|
||||||
|
* 返回一个BitSet实例,包含实体拥有的组件的位
|
||||||
|
*/
|
||||||
public componentBits: BitSet;
|
public componentBits: BitSet;
|
||||||
|
|
||||||
constructor(name: string) {
|
constructor(name: string) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public readonly entityProcessors: EntityProcessorList;
|
public readonly entityProcessors: EntityProcessorList;
|
||||||
|
|
||||||
public readonly _sceneComponents: FastList<SceneComponent> = new FastList<SceneComponent>();
|
public readonly _sceneComponents: SceneComponent[] = [];
|
||||||
public _didSceneBegin;
|
public _didSceneBegin;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -66,9 +66,9 @@ module es {
|
|||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
|
|
||||||
for (let i = 0; i < this._sceneComponents.length; i++) {
|
for (let i = 0; i < this._sceneComponents.length; i++) {
|
||||||
this._sceneComponents.buffer[i].onRemovedFromScene();
|
this._sceneComponents[i].onRemovedFromScene();
|
||||||
}
|
}
|
||||||
this._sceneComponents.clear();
|
this._sceneComponents.length = 0;
|
||||||
|
|
||||||
Physics.clear();
|
Physics.clear();
|
||||||
|
|
||||||
@@ -87,8 +87,8 @@ module es {
|
|||||||
this.entities.updateLists();
|
this.entities.updateLists();
|
||||||
|
|
||||||
for (let i = this._sceneComponents.length - 1; i >= 0; i--) {
|
for (let i = this._sceneComponents.length - 1; i >= 0; i--) {
|
||||||
if (this._sceneComponents.buffer[i].enabled)
|
if (this._sceneComponents[i].enabled)
|
||||||
this._sceneComponents.buffer[i].update();
|
this._sceneComponents[i].update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新我们的实体解析器
|
// 更新我们的实体解析器
|
||||||
@@ -109,8 +109,8 @@ module es {
|
|||||||
public addSceneComponent<T extends SceneComponent>(component: T): T {
|
public addSceneComponent<T extends SceneComponent>(component: T): T {
|
||||||
component.scene = this;
|
component.scene = this;
|
||||||
component.onEnabled();
|
component.onEnabled();
|
||||||
this._sceneComponents.add(component);
|
this._sceneComponents.push(component);
|
||||||
this._sceneComponents.sort(component);
|
this._sceneComponents.sort(component.compare);
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public getSceneComponent<T extends SceneComponent>(type) {
|
public getSceneComponent<T extends SceneComponent>(type) {
|
||||||
for (let i = 0; i < this._sceneComponents.length; i++) {
|
for (let i = 0; i < this._sceneComponents.length; i++) {
|
||||||
let component = this._sceneComponents.buffer[i];
|
let component = this._sceneComponents[i];
|
||||||
if (component instanceof type)
|
if (component instanceof type)
|
||||||
return component as T;
|
return component as T;
|
||||||
}
|
}
|
||||||
@@ -145,12 +145,12 @@ module es {
|
|||||||
* @param component
|
* @param component
|
||||||
*/
|
*/
|
||||||
public removeSceneComponent(component: SceneComponent) {
|
public removeSceneComponent(component: SceneComponent) {
|
||||||
if (!this._sceneComponents.contains(component)) {
|
if (!new linq.List(this._sceneComponents).contains(component)) {
|
||||||
console.warn(`SceneComponent${component}不在SceneComponents列表中!`);
|
console.warn(`SceneComponent${component}不在SceneComponents列表中!`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._sceneComponents.remove(component);
|
new linq.List(this._sceneComponents).remove(component);
|
||||||
component.onRemovedFromScene();
|
component.onRemovedFromScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ module es {
|
|||||||
* @param entity
|
* @param entity
|
||||||
*/
|
*/
|
||||||
public addEntity(entity: Entity) {
|
public addEntity(entity: Entity) {
|
||||||
if (this.entities.buffer.contains(entity))
|
if (new linq.List(this.entities.buffer).contains(entity))
|
||||||
console.warn(`您试图将同一实体添加到场景两次: ${entity}`);
|
console.warn(`您试图将同一实体添加到场景两次: ${entity}`);
|
||||||
this.entities.add(entity);
|
this.entities.add(entity);
|
||||||
entity.scene = this;
|
entity.scene = this;
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
module es {
|
module es {
|
||||||
/**
|
/**
|
||||||
* 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础
|
* 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础
|
||||||
|
*
|
||||||
|
* 按实体引用遍历实体订阅成员实体的系统
|
||||||
|
* 当你需要处理与Matcher相匹配的实体,并且你更喜欢使用Entity的时候,可以使用这个功能。
|
||||||
*/
|
*/
|
||||||
export abstract class EntityProcessingSystem extends EntitySystem {
|
export abstract class EntityProcessingSystem extends EntitySystem {
|
||||||
constructor(matcher: Matcher) {
|
constructor(matcher: Matcher) {
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
module es {
|
module es {
|
||||||
export class EntitySystem {
|
/**
|
||||||
|
* 追踪实体的子集,但不实现任何排序或迭代。
|
||||||
|
*/
|
||||||
|
export abstract class EntitySystem {
|
||||||
private _entities: Entity[] = [];
|
private _entities: Entity[] = [];
|
||||||
|
|
||||||
constructor(matcher?: Matcher) {
|
constructor(matcher?: Matcher) {
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ module es {
|
|||||||
/**
|
/**
|
||||||
* 添加到实体的组件列表
|
* 添加到实体的组件列表
|
||||||
*/
|
*/
|
||||||
public _components: FastList<Component> = new FastList<Component>();
|
public _components: Component[] = [];
|
||||||
/**
|
/**
|
||||||
* 所有需要更新的组件列表
|
* 所有需要更新的组件列表
|
||||||
*/
|
*/
|
||||||
public _updatableComponents: FastList<IUpdatable> = new FastList<IUpdatable>();
|
public _updatableComponents: IUpdatable[] = [];
|
||||||
/**
|
/**
|
||||||
* 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工
|
* 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工
|
||||||
*/
|
*/
|
||||||
@@ -38,7 +38,7 @@ module es {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get buffer() {
|
public get buffer() {
|
||||||
return this._components.buffer;
|
return this._components;
|
||||||
}
|
}
|
||||||
|
|
||||||
public markEntityListUnsorted() {
|
public markEntityListUnsorted() {
|
||||||
@@ -72,21 +72,19 @@ module es {
|
|||||||
this.handleRemove(this._components[i]);
|
this.handleRemove(this._components[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._components.clear();
|
this._components.length = 0;
|
||||||
this._updatableComponents.clear();
|
this._updatableComponents.length = 0;
|
||||||
this._componentsToAdd.length = 0;
|
this._componentsToAdd.length = 0;
|
||||||
this._componentsToRemove.length = 0;
|
this._componentsToRemove.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public deregisterAllComponents() {
|
public deregisterAllComponents() {
|
||||||
for (let i = 0; i < this._components.length; i++) {
|
for (let component of this._components) {
|
||||||
let component = this._components.buffer[i];
|
|
||||||
|
|
||||||
if (!component) continue;
|
if (!component) continue;
|
||||||
|
|
||||||
// 处理IUpdatable
|
// 处理IUpdatable
|
||||||
if (isIUpdatable(component))
|
if (isIUpdatable(component))
|
||||||
this._updatableComponents.remove(component);
|
new linq.List(this._updatableComponents).remove(component);
|
||||||
|
|
||||||
if (Core.entitySystemsEnabled) {
|
if (Core.entitySystemsEnabled) {
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)), false);
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)), false);
|
||||||
@@ -96,11 +94,9 @@ module es {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public registerAllComponents() {
|
public registerAllComponents() {
|
||||||
for (let i = 0; i < this._components.length; i++) {
|
for (let component of this._components) {
|
||||||
let component = this._components.buffer[i];
|
|
||||||
|
|
||||||
if (isIUpdatable(component))
|
if (isIUpdatable(component))
|
||||||
this._updatableComponents.add(component);
|
this._updatableComponents.push(component);
|
||||||
|
|
||||||
if (Core.entitySystemsEnabled) {
|
if (Core.entitySystemsEnabled) {
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)));
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)));
|
||||||
@@ -116,7 +112,7 @@ module es {
|
|||||||
if (this._componentsToRemove.length > 0) {
|
if (this._componentsToRemove.length > 0) {
|
||||||
for (let i = 0; i < this._componentsToRemove.length; i++) {
|
for (let i = 0; i < this._componentsToRemove.length; i++) {
|
||||||
this.handleRemove(this._componentsToRemove[i]);
|
this.handleRemove(this._componentsToRemove[i]);
|
||||||
this._components.remove(this._componentsToRemove[i]);
|
new linq.List(this._components).remove(this._componentsToRemove[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._componentsToRemove.length = 0;
|
this._componentsToRemove.length = 0;
|
||||||
@@ -127,14 +123,14 @@ module es {
|
|||||||
let component = this._componentsToAdd[i];
|
let component = this._componentsToAdd[i];
|
||||||
|
|
||||||
if (isIUpdatable(component))
|
if (isIUpdatable(component))
|
||||||
this._updatableComponents.add(component);
|
this._updatableComponents.push(component);
|
||||||
|
|
||||||
if (Core.entitySystemsEnabled) {
|
if (Core.entitySystemsEnabled) {
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)));
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._components.add(component);
|
this._components.push(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +153,7 @@ module es {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this._isComponentListUnsorted) {
|
if (this._isComponentListUnsorted) {
|
||||||
this._updatableComponents.sort(ComponentList.compareUpdatableOrder);
|
this._updatableComponents.sort(ComponentList.compareUpdatableOrder.compare);
|
||||||
this._isComponentListUnsorted = false;
|
this._isComponentListUnsorted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,7 +162,7 @@ module es {
|
|||||||
if (!component) return;
|
if (!component) return;
|
||||||
|
|
||||||
if (isIUpdatable(component))
|
if (isIUpdatable(component))
|
||||||
this._updatableComponents.remove(component);
|
new linq.List(this._updatableComponents).remove(component);
|
||||||
|
|
||||||
if (Core.entitySystemsEnabled) {
|
if (Core.entitySystemsEnabled) {
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)), false);
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)), false);
|
||||||
@@ -186,16 +182,14 @@ module es {
|
|||||||
* @param onlyReturnInitializedComponents
|
* @param onlyReturnInitializedComponents
|
||||||
*/
|
*/
|
||||||
public getComponent<T extends Component>(type, onlyReturnInitializedComponents: boolean): T {
|
public getComponent<T extends Component>(type, onlyReturnInitializedComponents: boolean): T {
|
||||||
for (let i = 0; i < this._components.length; i++) {
|
for (let component of this._components) {
|
||||||
let component = this._components.buffer[i];
|
|
||||||
if (component instanceof type)
|
if (component instanceof type)
|
||||||
return component as T;
|
return component as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 我们可以选择检查挂起的组件,以防addComponent和getComponent在同一个框架中被调用
|
// 我们可以选择检查挂起的组件,以防addComponent和getComponent在同一个框架中被调用
|
||||||
if (!onlyReturnInitializedComponents) {
|
if (!onlyReturnInitializedComponents) {
|
||||||
for (let i = 0; i < this._componentsToAdd.length; i++) {
|
for (let component of this._componentsToAdd) {
|
||||||
let component = this._componentsToAdd[i];
|
|
||||||
if (component instanceof type)
|
if (component instanceof type)
|
||||||
return component as T;
|
return component as T;
|
||||||
}
|
}
|
||||||
@@ -213,16 +207,14 @@ module es {
|
|||||||
if (!components)
|
if (!components)
|
||||||
components = [];
|
components = [];
|
||||||
|
|
||||||
for (let i = 0; i < this._components.length; i++) {
|
for (let component of this._components) {
|
||||||
let component = this._components.buffer[i];
|
|
||||||
if (component instanceof typeName) {
|
if (component instanceof typeName) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 我们还检查了待处理的组件,以防在同一帧中调用addComponent和getComponent
|
// 我们还检查了待处理的组件,以防在同一帧中调用addComponent和getComponent
|
||||||
for (let i = 0; i < this._componentsToAdd.length; i++) {
|
for (let component of this._componentsToAdd) {
|
||||||
let component = this._componentsToAdd[i];
|
|
||||||
if (component instanceof typeName) {
|
if (component instanceof typeName) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
@@ -234,15 +226,15 @@ module es {
|
|||||||
public update() {
|
public update() {
|
||||||
this.updateLists();
|
this.updateLists();
|
||||||
for (let i = 0; i < this._updatableComponents.length; i++) {
|
for (let i = 0; i < this._updatableComponents.length; i++) {
|
||||||
if (this._updatableComponents.buffer[i].enabled)
|
if (this._updatableComponents[i].enabled)
|
||||||
this._updatableComponents.buffer[i].update();
|
this._updatableComponents[i].update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public onEntityTransformChanged(comp: transform.Component) {
|
public onEntityTransformChanged(comp: transform.Component) {
|
||||||
for (let i = 0; i < this._components.length; i++) {
|
for (let i = 0; i < this._components.length; i++) {
|
||||||
if (this._components.buffer[i].enabled)
|
if (this._components[i].enabled)
|
||||||
this._components.buffer[i].onEntityTransformChanged(comp);
|
this._components[i].onEntityTransformChanged(comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this._componentsToAdd.length; i++) {
|
for (let i = 0; i < this._componentsToAdd.length; i++) {
|
||||||
@@ -253,12 +245,12 @@ module es {
|
|||||||
|
|
||||||
public onEntityEnabled() {
|
public onEntityEnabled() {
|
||||||
for (let i = 0; i < this._components.length; i++)
|
for (let i = 0; i < this._components.length; i++)
|
||||||
this._components.buffer[i].onEnabled();
|
this._components[i].onEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
public onEntityDisabled() {
|
public onEntityDisabled() {
|
||||||
for (let i = 0; i < this._components.length; i++)
|
for (let i = 0; i < this._components.length; i++)
|
||||||
this._components.buffer[i].onDisabled();
|
this._components[i].onDisabled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ module es {
|
|||||||
/**
|
/**
|
||||||
* 场景中添加的实体列表
|
* 场景中添加的实体列表
|
||||||
*/
|
*/
|
||||||
public _entities: FastList<Entity> = new FastList<Entity>();
|
public _entities: Entity[] = [];
|
||||||
/**
|
/**
|
||||||
* 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们
|
* 本帧添加的实体列表。用于对实体进行分组,以便我们可以同时处理它们
|
||||||
*/
|
*/
|
||||||
@@ -84,12 +84,12 @@ module es {
|
|||||||
this.updateLists();
|
this.updateLists();
|
||||||
|
|
||||||
for (let i = 0; i < this._entities.length; i++) {
|
for (let i = 0; i < this._entities.length; i++) {
|
||||||
this._entities.buffer[i]._isDestroyed = true;
|
this._entities[i]._isDestroyed = true;
|
||||||
this._entities.buffer[i].onRemovedFromScene();
|
this._entities[i].onRemovedFromScene();
|
||||||
this._entities.buffer[i].scene = null;
|
this._entities[i].scene = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._entities.clear();
|
this._entities.length = 0;
|
||||||
this._entityDict.clear();
|
this._entityDict.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ module es {
|
|||||||
* @param entity
|
* @param entity
|
||||||
*/
|
*/
|
||||||
public contains(entity: Entity): boolean {
|
public contains(entity: Entity): boolean {
|
||||||
return this._entities.contains(entity) || this._entitiesToAdded.contains(entity);
|
return new linq.List(this._entities).contains(entity) || this._entitiesToAdded.contains(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTagList(tag: number) {
|
public getTagList(tag: number) {
|
||||||
@@ -127,8 +127,7 @@ module es {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public update() {
|
public update() {
|
||||||
for (let i = 0; i < this._entities.length; i++) {
|
for (let entity of this._entities) {
|
||||||
let entity = this._entities.buffer[i];
|
|
||||||
if (entity.enabled && (entity.updateInterval == 1 || Time.frameCount % entity.updateInterval == 0))
|
if (entity.enabled && (entity.updateInterval == 1 || Time.frameCount % entity.updateInterval == 0))
|
||||||
entity.update();
|
entity.update();
|
||||||
}
|
}
|
||||||
@@ -141,7 +140,7 @@ module es {
|
|||||||
this.removeFromTagList(entity);
|
this.removeFromTagList(entity);
|
||||||
|
|
||||||
// 处理常规实体列表
|
// 处理常规实体列表
|
||||||
this._entities.remove(entity);
|
new linq.List(this._entities).remove(entity);
|
||||||
entity.onRemovedFromScene();
|
entity.onRemovedFromScene();
|
||||||
entity.scene = null;
|
entity.scene = null;
|
||||||
|
|
||||||
@@ -153,7 +152,7 @@ module es {
|
|||||||
|
|
||||||
if (this._entitiesToAdded.getCount() > 0) {
|
if (this._entitiesToAdded.getCount() > 0) {
|
||||||
this._entitiesToAdded.toArray().forEach(entity => {
|
this._entitiesToAdded.toArray().forEach(entity => {
|
||||||
this._entities.add(entity);
|
this._entities.push(entity);
|
||||||
entity.scene = this.scene;
|
entity.scene = this.scene;
|
||||||
|
|
||||||
this.addToTagList(entity);
|
this.addToTagList(entity);
|
||||||
@@ -171,7 +170,7 @@ module es {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this._isEntityListUnsorted) {
|
if (this._isEntityListUnsorted) {
|
||||||
this._entities.sort(Entity.entityComparer);
|
this._entities.sort(Entity.entityComparer.compare);
|
||||||
this._isEntityListUnsorted = false;
|
this._isEntityListUnsorted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,8 +188,8 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public findEntity(name: string) {
|
public findEntity(name: string) {
|
||||||
for (let i = 0; i < this._entities.length; i++) {
|
for (let i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities.buffer[i].name == name)
|
if (this._entities[i].name == name)
|
||||||
return this._entities.buffer[i];
|
return this._entities[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this._entitiesToAdded.getCount(); i ++){
|
for (let i = 0; i < this._entitiesToAdded.getCount(); i ++){
|
||||||
@@ -226,8 +225,8 @@ module es {
|
|||||||
public entitiesOfType<T extends Entity>(type): T[] {
|
public entitiesOfType<T extends Entity>(type): T[] {
|
||||||
let list = ListPool.obtain<T>();
|
let list = ListPool.obtain<T>();
|
||||||
for (let i = 0; i < this._entities.length; i++) {
|
for (let i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities.buffer[i] instanceof type)
|
if (this._entities[i] instanceof type)
|
||||||
list.push(this._entities.buffer[i] as T);
|
list.push(this._entities[i] as T);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this._entitiesToAdded.getCount(); i ++){
|
for (let i = 0; i < this._entitiesToAdded.getCount(); i ++){
|
||||||
@@ -246,8 +245,8 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public findComponentOfType<T extends Component>(type): T {
|
public findComponentOfType<T extends Component>(type): T {
|
||||||
for (let i = 0; i < this._entities.length; i++) {
|
for (let i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities.buffer[i].enabled) {
|
if (this._entities[i].enabled) {
|
||||||
let comp = this._entities.buffer[i].getComponent<T>(type);
|
let comp = this._entities[i].getComponent<T>(type);
|
||||||
if (comp)
|
if (comp)
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
@@ -273,8 +272,8 @@ module es {
|
|||||||
public findComponentsOfType<T extends Component>(type): T[] {
|
public findComponentsOfType<T extends Component>(type): T[] {
|
||||||
let comps = ListPool.obtain<T>();
|
let comps = ListPool.obtain<T>();
|
||||||
for (let i = 0; i < this._entities.length; i++) {
|
for (let i = 0; i < this._entities.length; i++) {
|
||||||
if (this._entities.buffer[i].enabled)
|
if (this._entities[i].enabled)
|
||||||
this._entities.buffer[i].getComponents(type, comps);
|
this._entities[i].getComponents(type, comps);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
for (let i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module es {
|
|||||||
* 提供了一系列立方贝塞尔点,并提供了帮助方法来访问贝塞尔
|
* 提供了一系列立方贝塞尔点,并提供了帮助方法来访问贝塞尔
|
||||||
*/
|
*/
|
||||||
export class BezierSpline {
|
export class BezierSpline {
|
||||||
public _points: FastList<Vector2> = new FastList<Vector2>();
|
public _points: Vector2[] = [];
|
||||||
public _curveCount: number = 0;
|
public _curveCount: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,15 +32,15 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public setControlPoint(index: number, point: Vector2) {
|
public setControlPoint(index: number, point: Vector2) {
|
||||||
if (index % 3 == 0) {
|
if (index % 3 == 0) {
|
||||||
let delta = Vector2.subtract(point, this._points.buffer[index]);
|
let delta = Vector2.subtract(point, this._points[index]);
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
this._points.buffer[index - 1].add(delta);
|
this._points[index - 1].add(delta);
|
||||||
|
|
||||||
if (index + 1 < this._points.length)
|
if (index + 1 < this._points.length)
|
||||||
this._points.buffer[index + 1].add(delta);
|
this._points[index + 1].add(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._points.buffer[index] = point;
|
this._points[index] = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,8 +49,8 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public getPointAtTime(t: number): Vector2{
|
public getPointAtTime(t: number): Vector2{
|
||||||
let i = this.pointIndexAtTime(new Ref(t));
|
let i = this.pointIndexAtTime(new Ref(t));
|
||||||
return Bezier.getPointThree(this._points.buffer[i], this._points.buffer[i + 1], this._points.buffer[i + 2],
|
return Bezier.getPointThree(this._points[i], this._points[i + 1], this._points[i + 2],
|
||||||
this._points.buffer[i + 3], t);
|
this._points[i + 3], t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,8 +59,8 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public getVelocityAtTime(t: number): Vector2 {
|
public getVelocityAtTime(t: number): Vector2 {
|
||||||
let i = this.pointIndexAtTime(new Ref(t));
|
let i = this.pointIndexAtTime(new Ref(t));
|
||||||
return Bezier.getFirstDerivativeThree(this._points.buffer[i], this._points.buffer[i + 1], this._points.buffer[i + 2],
|
return Bezier.getFirstDerivativeThree(this._points[i], this._points[i + 1], this._points[i + 2],
|
||||||
this._points.buffer[i + 3], t);
|
this._points[i + 3], t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,11 +81,11 @@ module es {
|
|||||||
public addCurve(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2) {
|
public addCurve(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2) {
|
||||||
// 只有当这是第一条曲线时,我们才会添加起始点。对于其他所有的曲线,前一个曲线的终点应该等于新曲线的起点。
|
// 只有当这是第一条曲线时,我们才会添加起始点。对于其他所有的曲线,前一个曲线的终点应该等于新曲线的起点。
|
||||||
if (this._points.length == 0)
|
if (this._points.length == 0)
|
||||||
this._points.add(start);
|
this._points.push(start);
|
||||||
|
|
||||||
this._points.add(firstControlPoint);
|
this._points.push(firstControlPoint);
|
||||||
this._points.add(secondControlPoint);
|
this._points.push(secondControlPoint);
|
||||||
this._points.add(end);
|
this._points.push(end);
|
||||||
|
|
||||||
this._curveCount = (this._points.length - 1) / 3;
|
this._curveCount = (this._points.length - 1) / 3;
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ module es {
|
|||||||
* 重置bezier,移除所有点
|
* 重置bezier,移除所有点
|
||||||
*/
|
*/
|
||||||
public reset() {
|
public reset() {
|
||||||
this._points.clear();
|
this._points.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,116 +0,0 @@
|
|||||||
module es {
|
|
||||||
/**
|
|
||||||
* 围绕一个数组的非常基本的包装,当它达到容量时自动扩展。
|
|
||||||
* 注意,在迭代时应该这样直接访问缓冲区,但使用FastList.length字段。
|
|
||||||
*
|
|
||||||
* @tutorial
|
|
||||||
* for( var i = 0; i <= list.length; i++ )
|
|
||||||
* var item = list.buffer[i];
|
|
||||||
*/
|
|
||||||
export class FastList<T> {
|
|
||||||
/**
|
|
||||||
* 直接访问后备缓冲区。
|
|
||||||
* 不要使用buffer.Length! 使用FastList.length
|
|
||||||
*/
|
|
||||||
public buffer: T[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 直接访问缓冲区内填充项的长度。不要改变。
|
|
||||||
*/
|
|
||||||
public length: number = 0;
|
|
||||||
|
|
||||||
constructor(size: number = 5) {
|
|
||||||
this.buffer = new Array(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空列表并清空缓冲区中的所有项目
|
|
||||||
*/
|
|
||||||
public clear() {
|
|
||||||
this.buffer.length = 0;
|
|
||||||
this.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 和clear的工作原理一样,只是它不会将缓冲区中的所有项目清空。
|
|
||||||
*/
|
|
||||||
public reset() {
|
|
||||||
this.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将该项目添加到列表中
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
public add(item: T) {
|
|
||||||
if (this.length == this.buffer.length)
|
|
||||||
this.buffer.length = Math.max(this.buffer.length << 1, 10);
|
|
||||||
this.buffer[this.length++] = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从列表中删除该项目
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
public remove(item: T){
|
|
||||||
let comp = EqualityComparer.default<T>();
|
|
||||||
for (let i = 0; i < this.length; ++i){
|
|
||||||
if (comp.equals(this.buffer[i], item)){
|
|
||||||
this.removeAt(i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从列表中删除给定索引的项目。
|
|
||||||
* @param index
|
|
||||||
*/
|
|
||||||
public removeAt(index: number){
|
|
||||||
if (index >= this.length)
|
|
||||||
throw new Error("index超出范围!");
|
|
||||||
|
|
||||||
this.length --;
|
|
||||||
new linq.List(this.buffer).removeAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查项目是否在FastList中
|
|
||||||
* @param item
|
|
||||||
*/
|
|
||||||
public contains(item: T){
|
|
||||||
let comp = EqualityComparer.default<T>();
|
|
||||||
for (let i = 0; i < this.length; ++ i){
|
|
||||||
if (comp.equals(this.buffer[i], item))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果缓冲区达到最大,将分配更多的空间来容纳额外的ItemCount。
|
|
||||||
* @param additionalItemCount
|
|
||||||
*/
|
|
||||||
public ensureCapacity(additionalItemCount: number = 1){
|
|
||||||
if (this.length + additionalItemCount >= this.buffer.length)
|
|
||||||
this.buffer.length = Math.max(this.buffer.length << 1, this.length + additionalItemCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加数组中的所有项目
|
|
||||||
* @param array
|
|
||||||
*/
|
|
||||||
public addRange(array: T[]){
|
|
||||||
for (let item of array)
|
|
||||||
this.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对缓冲区中的所有项目进行排序,长度不限。
|
|
||||||
*/
|
|
||||||
public sort(comparer: IComparer<T>){
|
|
||||||
this.buffer.sort(comparer.compare);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user