Skip to content

Commit bc6920f

Browse files
committed
优化getComponent与getComponents性能
1 parent d576a95 commit bc6920f

File tree

7 files changed

+215
-127
lines changed

7 files changed

+215
-127
lines changed

source/bin/framework.d.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ declare module es {
408408
* @param typeName
409409
* @param componentList
410410
*/
411-
getComponents(typeName: any, componentList?: any): any;
411+
getComponents(typeName: any, componentList?: any): any[];
412412
/**
413413
* 从组件列表中删除组件
414414
* @param component
@@ -647,6 +647,7 @@ declare module es {
647647
* @param name
648648
*/
649649
findEntity(name: string): Entity;
650+
findEntityById(id: number): Entity;
650651
/**
651652
* 返回具有给定标记的所有实体
652653
* @param tag
@@ -1713,6 +1714,9 @@ declare module es {
17131714
* 添加到实体的组件列表
17141715
*/
17151716
_components: Component[];
1717+
/** 记录component的快速读取列表 */
1718+
fastComponentsMap: Map<new (...args: any[]) => Component, Component[]>;
1719+
fastComponentsToAddMap: Map<new (...args: any[]) => Component, Component[]>;
17161720
/**
17171721
* 所有需要更新的组件列表
17181722
*/
@@ -1751,6 +1755,10 @@ declare module es {
17511755
*/
17521756
updateLists(): void;
17531757
handleRemove(component: Component): void;
1758+
private removeFastComponent;
1759+
private addFastComponent;
1760+
private removeFastComponentToAdd;
1761+
private addFastComponentToAdd;
17541762
/**
17551763
* 获取类型T的第一个组件并返回它
17561764
* 可以选择跳过检查未初始化的组件(尚未调用onAddedToEntity方法的组件)
@@ -1764,7 +1772,7 @@ declare module es {
17641772
* @param typeName
17651773
* @param components
17661774
*/
1767-
getComponents(typeName: any, components?: any): any;
1775+
getComponents(typeName: any, components?: any[]): any[];
17681776
update(): void;
17691777
onEntityTransformChanged(comp: transform.Component): void;
17701778
onEntityEnabled(): void;
@@ -1850,6 +1858,12 @@ declare module es {
18501858
* @param name
18511859
*/
18521860
findEntity(name: string): Entity;
1861+
/**
1862+
*
1863+
* @param id
1864+
* @returns
1865+
*/
1866+
findEntityById(id: number): Entity;
18531867
/**
18541868
* 返回带有标签的所有实体的列表。如果没有实体有标签,则返回一个空列表。
18551869
* 返回的List可以通过ListPool.free放回池中

0 commit comments

Comments
 (0)