@cjhd/cj-ecs 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/assets/common/component/MoveComponent.d.ts +141 -0
  2. package/assets/common/component/NodeComponent.d.ts +98 -0
  3. package/assets/common/system/MoveSystem.d.ts +17 -0
  4. package/assets/ecs/EcsComponent.d.ts +89 -0
  5. package/assets/ecs/{EcsDirty.ts → EcsDirty.d.ts} +340 -459
  6. package/assets/ecs/EcsEntity.d.ts +148 -0
  7. package/assets/ecs/EcsSingleton.d.ts +3 -0
  8. package/assets/ecs/EcsSystem.d.ts +96 -0
  9. package/assets/ecs.d.ts +126 -0
  10. package/assets/lib/EcsCache.d.ts +24 -0
  11. package/assets/lib/EcsFilter.d.ts +57 -0
  12. package/assets/lib/EcsManager.d.ts +251 -0
  13. package/assets/lib/{EcsObject.ts → EcsObject.d.ts} +360 -422
  14. package/assets/lib/EcsTimer.d.ts +119 -0
  15. package/assets/lib/EcsTween.d.ts +168 -0
  16. package/assets/lib/EcsUtils.d.ts +82 -0
  17. package/dist/cocos/assets/common/component/MoveComponent.js +4 -0
  18. package/dist/cocos/assets/common/component/NodeComponent.js +4 -0
  19. package/dist/cocos/assets/common/system/MoveSystem.js +2 -0
  20. package/dist/cocos/assets/ecs/EcsComponent.js +4 -0
  21. package/dist/cocos/assets/ecs/EcsDirty.js +4 -0
  22. package/dist/cocos/assets/ecs/EcsEntity.js +4 -0
  23. package/dist/cocos/assets/ecs/EcsSingleton.js +4 -0
  24. package/dist/cocos/assets/ecs/EcsSystem.js +2 -0
  25. package/dist/cocos/assets/ecs.js +2 -0
  26. package/dist/cocos/assets/lib/EcsCache.js +2 -0
  27. package/dist/cocos/assets/lib/EcsFilter.js +2 -0
  28. package/dist/cocos/assets/lib/EcsManager.js +4 -0
  29. package/dist/cocos/assets/lib/EcsObject.js +4 -0
  30. package/dist/cocos/assets/lib/EcsTimer.js +4 -0
  31. package/dist/cocos/assets/lib/EcsTween.js +4 -0
  32. package/dist/cocos/assets/lib/EcsUtils.js +2 -0
  33. package/dist/cocos/index.js +4 -0
  34. package/{index.ts → index.d.ts} +14 -33
  35. package/package.json +27 -7
  36. package/assets/common/component/MoveComponent.ts +0 -292
  37. package/assets/common/component/MoveComponent.ts.meta +0 -9
  38. package/assets/common/component/NodeComponent.ts +0 -315
  39. package/assets/common/component/NodeComponent.ts.meta +0 -9
  40. package/assets/common/component.meta +0 -12
  41. package/assets/common/system/MoveSystem.ts +0 -108
  42. package/assets/common/system/MoveSystem.ts.meta +0 -9
  43. package/assets/common/system.meta +0 -12
  44. package/assets/common.meta +0 -12
  45. package/assets/ecs/EcsComponent.ts +0 -244
  46. package/assets/ecs/EcsComponent.ts.meta +0 -9
  47. package/assets/ecs/EcsDirty.ts.meta +0 -9
  48. package/assets/ecs/EcsEntity.ts +0 -430
  49. package/assets/ecs/EcsEntity.ts.meta +0 -9
  50. package/assets/ecs/EcsSingleton.ts +0 -6
  51. package/assets/ecs/EcsSingleton.ts.meta +0 -9
  52. package/assets/ecs/EcsSystem.ts +0 -191
  53. package/assets/ecs/EcsSystem.ts.meta +0 -9
  54. package/assets/ecs.meta +0 -12
  55. package/assets/ecs.ts +0 -339
  56. package/assets/ecs.ts.meta +0 -9
  57. package/assets/lib/EcsCache.ts +0 -43
  58. package/assets/lib/EcsCache.ts.meta +0 -9
  59. package/assets/lib/EcsFilter.ts +0 -210
  60. package/assets/lib/EcsFilter.ts.meta +0 -9
  61. package/assets/lib/EcsManager.ts +0 -502
  62. package/assets/lib/EcsManager.ts.meta +0 -9
  63. package/assets/lib/EcsObject.ts.meta +0 -9
  64. package/assets/lib/EcsTimer.ts +0 -239
  65. package/assets/lib/EcsTimer.ts.meta +0 -9
  66. package/assets/lib/EcsTween.ts +0 -486
  67. package/assets/lib/EcsTween.ts.meta +0 -9
  68. package/assets/lib/EcsUtils.ts +0 -352
  69. package/assets/lib/EcsUtils.ts.meta +0 -9
  70. package/assets/lib.meta +0 -12
  71. package/assets.meta +0 -9
  72. package/index.ts.meta +0 -9
  73. package/package.json.meta +0 -11
  74. /package/{.cj-ecs.md → README.md} +0 -0
@@ -0,0 +1,148 @@
1
+ import { Node } from 'cc';
2
+ import { EcsBaseEntity, IComponent, IECS, IEntity, ITypeofComponent } from '../lib/EcsObject';
3
+ import { EcsComponent } from './EcsComponent';
4
+ export declare class EcsEntity extends EcsBaseEntity implements IEntity {
5
+ /**位运算 */
6
+ private flag;
7
+ private instNames;
8
+ /**组件的名字 => 组件数组 */
9
+ private instNameToComps;
10
+ /**组件父类的名字 => 组件数组 */
11
+ private superNameToComps;
12
+ private _isValid;
13
+ /**是否有效 */
14
+ get isValid(): boolean;
15
+ private set isValid(value);
16
+ private _enabled;
17
+ /**标记是否生效 */
18
+ get enabled(): boolean;
19
+ set enabled(value: boolean);
20
+ /**指定ecs */
21
+ private _ecs;
22
+ /**获取对应的ecs */
23
+ protected get ecs(): IECS;
24
+ /**节点 */
25
+ private _node;
26
+ get node(): Node | null;
27
+ set node(value: Node | null);
28
+ /**标记是否已经销毁 */
29
+ private _isDestroyed;
30
+ /**
31
+ * 内部初始化函数
32
+ */
33
+ protected innerInit(ecs: IECS, node?: Node | null): void;
34
+ /**
35
+ * 添加组件(内部调用)
36
+ */
37
+ protected innerAddComponent(com: EcsComponent): void;
38
+ /**
39
+ * 移除组件(内部调用)
40
+ */
41
+ protected innerRemoveComponent(com: EcsComponent): void;
42
+ /**
43
+ * 根据组件名字获取对应的组件数组(先查inst再查询super)
44
+ */
45
+ private getCompsByName;
46
+ /**
47
+ * 根据组件名字获取对应的组件数组(先查inst再查询super)
48
+ */
49
+ private getCompsByName2;
50
+ /**
51
+ * 移除当前所有组件
52
+ */
53
+ private clear;
54
+ /**
55
+ * 销毁
56
+ */
57
+ destroy(): boolean;
58
+ /**添加*/
59
+ protected onAdd(): void;
60
+ /**生效*/
61
+ protected onEnable(): void;
62
+ /**失效*/
63
+ protected onDisable(): void;
64
+ /**移除*/
65
+ protected onRemove(): void;
66
+ /**
67
+ * 检查是否包含全部
68
+ */
69
+ checkFlagAll(flag: number[]): boolean;
70
+ /**
71
+ * 检查是否包含任一
72
+ */
73
+ checkFlagAny(flag: number[]): boolean;
74
+ /**
75
+ * 检查是否仅包含全部
76
+ */
77
+ checkFlagOnly(flag: number[]): boolean;
78
+ /**
79
+ * 根据组件名字检查是否存在启用且有效的组件
80
+ */
81
+ hasEnabledComponentName(componentName: string): boolean;
82
+ /**
83
+ * 添加相应类型的组件
84
+ * @see 同add
85
+ * @param param 类型
86
+ */
87
+ addComponent<T extends ITypeofComponent>(param: T | IComponent): InstanceType<T> | null;
88
+ /**
89
+ * 添加相应类型的组件
90
+ * @param param 类型
91
+ */
92
+ add<T extends ITypeofComponent>(param: T | IComponent): InstanceType<T> | null;
93
+ /**
94
+ * 移除相应类型的第一个组件
95
+ * @see 同remove
96
+ * @param param 类型或实例(当组件开启allowMultiple后,需要传入实例)
97
+ */
98
+ removeComponent(param: ITypeofComponent | IComponent): boolean;
99
+ /**
100
+ * 移除相应类型的第一个组件
101
+ * @param param 类型或实例(当组件开启allowMultiple后,需要传入实例)
102
+ */
103
+ remove(param: ITypeofComponent | IComponent): boolean;
104
+ /**
105
+ * 移除相应组件的所有组件
106
+ * @see 同removeAll
107
+ * @param Com 类型
108
+ */
109
+ removeComponents(Com: ITypeofComponent): boolean;
110
+ /**
111
+ * 移除相应组件的所有组件
112
+ * @param Com 类型
113
+ */
114
+ removeAll(Com: ITypeofComponent): boolean;
115
+ /**
116
+ * 有没有相应类型的组件
117
+ * @see 同has
118
+ * @param Com 类型
119
+ */
120
+ hasComponent(Com: ITypeofComponent): boolean;
121
+ /**
122
+ * 有没有相应类型的组件
123
+ * @param Com 类型
124
+ */
125
+ has(Com: ITypeofComponent): boolean;
126
+ /**
127
+ * 获取相应类型的组件
128
+ * @see 同get
129
+ * @param Com 类型
130
+ */
131
+ getComponent<T extends ITypeofComponent>(Com: T): InstanceType<T> | null;
132
+ /**
133
+ * 获取相应类型的组件
134
+ * @param Com 类型
135
+ */
136
+ get<T extends ITypeofComponent>(Com: T): InstanceType<T> | null;
137
+ /**
138
+ * 获取相应类型的组件
139
+ * @see 同getAll
140
+ * @param Com 类型
141
+ */
142
+ getComponents<T extends ITypeofComponent>(Com: T): InstanceType<T>[];
143
+ /**
144
+ * 获取相应类型的组件
145
+ * @param Com 类型
146
+ */
147
+ getAll<T extends ITypeofComponent>(Com: T): InstanceType<T>[];
148
+ }
@@ -0,0 +1,3 @@
1
+ import { EcsBaseSingleton, ISingleton } from '../lib/EcsObject';
2
+ export declare class EcsSingleton extends EcsBaseSingleton implements ISingleton {
3
+ }
@@ -0,0 +1,96 @@
1
+ import { Node } from 'cc';
2
+ import { EcsBaseSystem, IComponent, IECS, IEntity, IEntityUUID, IFilter, ISystem, ITypeofEntity, ITypeofSingleton } from '../lib/EcsObject';
3
+ import { TimerManager } from '../lib/EcsTimer';
4
+ import { TweenManager } from '../lib/EcsTween';
5
+ import type { IEcsObservedQuery } from './EcsDirty';
6
+ export declare class EcsSystem extends EcsBaseSystem implements ISystem {
7
+ static matchEntity(system: EcsSystem, entity: IEntity): void;
8
+ private _ecs;
9
+ /**获取对应的ecs */
10
+ protected get ecs(): IECS;
11
+ /** observed runtime 查询入口。未安装 cj-ecs-observed 时为 null,系统需要自行兜底。 */
12
+ protected get observed(): IEcsObservedQuery | null;
13
+ private set ecs(value);
14
+ /**
15
+ * Timer管理器
16
+ * @example
17
+ * // 创建timer
18
+ * const timer = new Timer(() => { consoe.log('timer'); });
19
+ * timer.delay(1);
20
+ * timer.repeat(10);
21
+ * // 添加管理
22
+ * this.timer.add(timer);
23
+ * // 迭代一次
24
+ * this.timer.step(dt);
25
+ */
26
+ protected timer: TimerManager;
27
+ /**
28
+ * Tween管理器
29
+ * @example
30
+ * // 创建tween
31
+ * const tween = new Tween(ECS组件实例);
32
+ * tween.to(1, ...);
33
+ * tween.delay(1);
34
+ * tween.by(1, ...);
35
+ * // 添加管理
36
+ * this.tween.add(tween);
37
+ * // 迭代一次
38
+ * this.tween.step(dt);
39
+ */
40
+ protected tween: TweenManager;
41
+ /**
42
+ * 指定ecs
43
+ */
44
+ constructor(ecs: IECS);
45
+ /**添加 */
46
+ protected onAdd(): void;
47
+ /**移除 */
48
+ protected onRemove(): void;
49
+ /**查询实体 */
50
+ protected query<T extends IEntity>(filter: IFilter): T[];
51
+ protected query<T extends IComponent>(filter: IFilter, Component: {
52
+ new (): T;
53
+ }): T[];
54
+ /**查询实体 */
55
+ protected find<T extends IEntity>(filter: IFilter): T | null;
56
+ protected find<T extends IComponent>(filter: IFilter, Component: {
57
+ new (): T;
58
+ }): T | null;
59
+ /**是否存在实体 */
60
+ protected exist(filter: IFilter): boolean;
61
+ /**遍历当前系统 matcher 命中的实体,避免 query(this.matcher) 每帧分配数组 */
62
+ protected forEachMatchedEntity<T extends IEntity = IEntity>(handle: (entity: T) => void): void;
63
+ /**当前系统 matcher 命中的实体数量 */
64
+ protected get matchedEntityCount(): number;
65
+ /**创建实体 */
66
+ protected createEntity<T extends ITypeofEntity>(Entity: T, options?: Node | {
67
+ node?: Node;
68
+ }): InstanceType<T>;
69
+ /**查询实体 */
70
+ protected findByUuid(uuid: IEntityUUID): IEntity;
71
+ /**是否存在实体 */
72
+ protected existByUuid(uuid: IEntityUUID): boolean;
73
+ /**获取单例组件 */
74
+ protected getSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T>;
75
+ /**
76
+ * 过滤实体
77
+ * - 配置后才能响应onEntityEnter、onEntityLeave
78
+ * - 如果query、find、exist方法中的值与matcher中的值相同,则会直接从缓存中获取实体
79
+ */
80
+ protected matcher: IFilter | null;
81
+ /**实体进入系统,会在execute流程最开始调用*/
82
+ protected onEntityEnter(entity: IEntity): void;
83
+ /**实体离开系统,会在execute流程最开始调用*/
84
+ protected onEntityLeave(entity: IEntity): void;
85
+ private matchEntities;
86
+ private matchEntity;
87
+ protected execute(dt?: number, ...args: any[]): void;
88
+ protected beforeExecute(dt?: number, ...args: any[]): void;
89
+ protected afterExecute(dt?: number, ...args: any[]): void;
90
+ protected update(dt?: number, ...args: any[]): void;
91
+ protected beforeUpdate(dt?: number, ...args: any[]): void;
92
+ protected afterUpdate(dt?: number, ...args: any[]): void;
93
+ protected log(...args: any[]): void;
94
+ protected warn(...args: any[]): void;
95
+ protected error(...args: any[]): void;
96
+ }
@@ -0,0 +1,126 @@
1
+ import { Node } from 'cc';
2
+ import type { IEcsComponentDirtySink, IEcsObservedQuery } from './ecs/EcsDirty';
3
+ import { Filter } from './lib/EcsFilter';
4
+ import { IComponent, IECS, IEntity, IEntityUUID, ISingleton, ITypeofEntity, ITypeofSingleton, ITypeofSystem } from './lib/EcsObject';
5
+ export declare class ECS implements IECS {
6
+ static create(): IECS;
7
+ private entityManager;
8
+ private systemManager;
9
+ private componentManager;
10
+ private singletons;
11
+ private mutationDepth;
12
+ private dirtyEntities;
13
+ private dirtySink;
14
+ private observedQuery;
15
+ /**
16
+ * 查询实体
17
+ */
18
+ query<T extends IEntity>(filter: Filter): T[];
19
+ query<T extends IComponent>(filter: Filter, Component: {
20
+ new (): T;
21
+ }): T[];
22
+ /**
23
+ * 查询实体
24
+ */
25
+ find<T extends IEntity>(filter: Filter): T | null;
26
+ find<T extends IComponent>(filter: Filter, Component: {
27
+ new (): T;
28
+ }): T | null;
29
+ /**
30
+ * 查询实体是否存在
31
+ */
32
+ exist(filter: Filter): boolean;
33
+ /**
34
+ * 根据uuid查询实体
35
+ */
36
+ findByUuid(uuid: IEntityUUID): IEntity;
37
+ /**
38
+ * 根据uuid查询实体是否存在
39
+ */
40
+ existByUuid(uuid: IEntityUUID): boolean;
41
+ /**
42
+ * 添加单例组件
43
+ */
44
+ addSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T>;
45
+ addSingleton<T extends ISingleton>(param: T): T;
46
+ /**
47
+ * 获取单例组件
48
+ */
49
+ getSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T> | null;
50
+ /**
51
+ * 移除单例组件
52
+ */
53
+ removeSingleton<T extends ITypeofSingleton>(param: T): InstanceType<T> | null;
54
+ /**
55
+ * 创建一个实体
56
+ */
57
+ createEntity<T extends ITypeofEntity>(Entity: T, options?: Node | {
58
+ node?: Node;
59
+ }): InstanceType<T>;
60
+ /**
61
+ * 移除一个实体
62
+ */
63
+ removeEntity(entity: IEntity): void;
64
+ /**
65
+ * 添加一个组件
66
+ */
67
+ addComponent(entity: IEntity, component: IComponent): void;
68
+ /**
69
+ * 移除一个组件
70
+ */
71
+ removeComponent(component: IComponent): void;
72
+ /**
73
+ * 添加一个系统
74
+ */
75
+ addSystem<T extends ITypeofSystem>(System: T): void;
76
+ /**
77
+ * 移除一个系统
78
+ */
79
+ removeSystem<T extends ITypeofSystem>(System: T): void;
80
+ /**
81
+ * 清理所有数据
82
+ */
83
+ clear(): void;
84
+ /**
85
+ * 安装/卸载 dirty sink。
86
+ * observed runtime 通过这里接管组件 dirty 通知;传 null 后核心 ECS 仍可独立运行。
87
+ */
88
+ setDirtySink(sink: IEcsComponentDirtySink | null): void;
89
+ /** 获取当前 dirty sink,主要给扩展包链式安装/恢复使用。 */
90
+ getDirtySink(): IEcsComponentDirtySink | null;
91
+ /**
92
+ * 安装/卸载 observed 查询入口。
93
+ * 系统内可通过 this.observed 或 ecs.getObservedQuery() 获取 dirty/fieldDirty/index 查询。
94
+ * @param query 查询入口
95
+ */
96
+ setObservedQuery(query: IEcsObservedQuery | null): void;
97
+ /** 获取 observed 查询入口;未安装 observed runtime 时返回 null。
98
+ * @returns 查询入口
99
+ */
100
+ getObservedQuery(): IEcsObservedQuery | null;
101
+ /** 开始批量结构变更,延迟刷新系统 matcher。适合一次性添加/移除多个组件。 */
102
+ beginMutation(): void;
103
+ /** 结束批量结构变更,并统一刷新受影响实体的系统 matcher。 */
104
+ endMutation(): void;
105
+ private markEntityDirty;
106
+ private refreshEntitySystems;
107
+ private executeSystem;
108
+ private beforeExecuteSystem;
109
+ private afterExecuteSystem;
110
+ private updateSystem;
111
+ private beforeUpdateSystem;
112
+ private afterUpdateSystem;
113
+ /**
114
+ * 用于逻辑帧
115
+ * 执行顺序:
116
+ * [系统的beforeExecute] -> [系统的execute] ->[系统的afterExecute]
117
+ */
118
+ execute(dt: number, ...args: any[]): void;
119
+ /**
120
+ * 用于渲染帧
121
+ * 执行顺序:
122
+ * [系统的beforeUpdate] -> [系统的update] -> [系统的afterUpdate]
123
+ */
124
+ update(dt: number, ...args: any[]): void;
125
+ }
126
+ export declare const ecs: IECS;
@@ -0,0 +1,24 @@
1
+ import { IComponent, IEntity } from './EcsObject';
2
+ /**缓存 */
3
+ declare class Cache<V> {
4
+ private cache;
5
+ get(): V;
6
+ put(v: V): void;
7
+ clear(): void;
8
+ }
9
+ /**实体缓存 */
10
+ export declare const entityCache: Cache<IEntity>;
11
+ /**缓存映射 */
12
+ declare class CacheMap<V> {
13
+ /**缓存 */
14
+ private cache;
15
+ /**从指定缓存数组中获取并移除元素 */
16
+ get(k: string): V;
17
+ /**将元素添加到指定缓存数组中 */
18
+ put(k: string, v: V): void;
19
+ /**清空缓存 */
20
+ clear(): void;
21
+ }
22
+ /**组件缓存 */
23
+ export declare const componentCache: CacheMap<IComponent<IEntity>>;
24
+ export {};
@@ -0,0 +1,57 @@
1
+ import { ComponentManager, EntityManager } from './EcsManager';
2
+ import { IEntity, IFilter, ITypeofComponent } from './EcsObject';
3
+ /**
4
+ * 过滤器
5
+ */
6
+ export declare class Filter implements IFilter {
7
+ static check(entity: IEntity, filter: Filter): boolean;
8
+ /**查询实体
9
+ * @param entityManager 实体管理器
10
+ * @param componentManager 组件管理器
11
+ * @param filter 过滤器
12
+ * @returns 符合筛选条件的实体数组
13
+ */
14
+ static query(entityManager: EntityManager, componentManager: ComponentManager, filter: Filter): IEntity[];
15
+ /**查询实体
16
+ * @param entityManager 实体管理器
17
+ * @param componentManager 组件管理器
18
+ * @param filter 过滤器
19
+ * @returns 符合筛选条件的实体
20
+ */
21
+ static find(entityManager: EntityManager, componentManager: ComponentManager, filter: Filter): IEntity;
22
+ private anyList;
23
+ private include;
24
+ private hasSearch;
25
+ private hasExclude;
26
+ private pipeline;
27
+ /**
28
+ * 有这些组件中的任何一个组件
29
+ * @param Comps 组件类型
30
+ * @returns this
31
+ */
32
+ any(...Comps: ITypeofComponent[]): this;
33
+ /**
34
+ * 必须包含所有这些组件
35
+ * 让数量最少的组件作为第一个参数,会获得更好的性能
36
+ * @param Comps 组件类型
37
+ * @returns this
38
+ */
39
+ all(...Comps: ITypeofComponent[]): this;
40
+ /**
41
+ * 仅仅只有这些组件
42
+ * 让数量最少的组件作为第一个参数,会获得更好的性能
43
+ * @param Comps 组件类型
44
+ * @returns this
45
+ */
46
+ only(...Comps: ITypeofComponent[]): this;
47
+ /**
48
+ * 不能包含其中的任何一个组件
49
+ * @param Comps 组件类型
50
+ * @returns this
51
+ */
52
+ exclude(...Comps: ITypeofComponent[]): this;
53
+ }
54
+ /**
55
+ * 过滤条件
56
+ */
57
+ export declare const filter: IFilter;
@@ -0,0 +1,251 @@
1
+ import { EcsBase, IComponent, IComponentName, IEntity, IEntityUUID, IFlag, ISystem, ITypeofSystem } from './EcsObject';
2
+ import { CustomArray } from './EcsUtils';
3
+ /**
4
+ * 根据名获取类,用于通过组件名字获取组件类
5
+ */
6
+ export declare function getClassByName(name: IComponentName): typeof EcsBase;
7
+ /**
8
+ * 类装饰器(组件与单例组件必须使用ecsclass)
9
+ */
10
+ export declare function ecsclass(className: string): (ctor: any) => any;
11
+ /**
12
+ * flag位管理器
13
+ */
14
+ declare class FlagManager {
15
+ private index;
16
+ private cache;
17
+ private cacheAll;
18
+ /**
19
+ * 在source中添加flag
20
+ * @param source
21
+ * @param flag
22
+ */
23
+ addFlag(source: IFlag, flag: IFlag): void;
24
+ /**
25
+ * 在source中移除flag
26
+ * @param source
27
+ * @param flag
28
+ */
29
+ removeFlag(source: IFlag, flag: IFlag): void;
30
+ /**
31
+ * 检查是否完全包含
32
+ * @param source 源
33
+ * @param sub 子集
34
+ * @returns 是否完全包含子集
35
+ */
36
+ checkFlagAll(source: IFlag, sub: IFlag): boolean;
37
+ /**
38
+ * 只包含其中一个即可
39
+ * @param source 源
40
+ * @param sub 子集
41
+ * @returns 是否包含其中一个
42
+ */
43
+ checkFlagAny(source: IFlag, sub: IFlag): boolean;
44
+ /**
45
+ * 会融合父类的flag位
46
+ * @param name 组件类型名
47
+ * @returns 组件类型的flag位数组
48
+ */
49
+ getAllByName(name: string): IFlag;
50
+ /**
51
+ * 会融合父类的flag位
52
+ * @param names 组件类型名数组
53
+ * @param out 输出数组,用于存储融合后的flag位
54
+ * @returns 输出数组
55
+ */
56
+ getAllByNames(names: string[], out: number[]): IFlag;
57
+ /**
58
+ * 只计算自身的flag位
59
+ * @param name 组件类型名
60
+ * @returns 组件类型的flag位数组
61
+ */
62
+ getByName(name: string): IFlag;
63
+ /**
64
+ * 只计算自身的flag位
65
+ * @param names 组件类型名数组
66
+ * @returns 组件类型的flag位数组
67
+ */
68
+ getByNames(names: string[]): IFlag;
69
+ /**
70
+ * 获取flag位数量
71
+ * @returns flag位数量
72
+ */
73
+ get bits(): number;
74
+ }
75
+ export declare const flagManager: FlagManager;
76
+ /**
77
+ * 类管理器
78
+ */
79
+ declare class ClassManager {
80
+ /** 组件类数量 */
81
+ private comClassCount;
82
+ /** 类名到父类名的映射 */
83
+ private nameToSuperName;
84
+ /** 类名到类的映射 */
85
+ private nameToClass;
86
+ /**
87
+ * 获取父类
88
+ * @param type 类
89
+ * @returns 父类类型
90
+ */
91
+ private getSuper;
92
+ /**
93
+ * 添加一个类
94
+ * @param ctor 类构造函数
95
+ * @param className 类名
96
+ */
97
+ add(ctor: typeof EcsBase, className: string): void;
98
+ /**
99
+ * 遍历所有父类名,包括当前类
100
+ * @param subName 子类名
101
+ * @param callback 处理函数,用于对每个父类名进行操作
102
+ */
103
+ eachSuperName(subName: string, callback: (superName: string) => any): void;
104
+ /**
105
+ * 通过类名判断一个是否是另一个的子类
106
+ * @param subName 子类名
107
+ * @param superName 父类名
108
+ * @returns 是否是子类
109
+ */
110
+ isChildByName(subName: string, superName: string): boolean;
111
+ /**
112
+ * 通过类名获取一个类
113
+ * @param name 类名
114
+ * @returns 类
115
+ */
116
+ getClassByName(name: string): typeof EcsBase;
117
+ /**
118
+ * 获取父类名字
119
+ * @param name 类名
120
+ * @returns 父类名
121
+ */
122
+ getSuperName(name: string): string;
123
+ /**
124
+ * 组件种类数量
125
+ */
126
+ get comSize(): number;
127
+ }
128
+ /**类管理器 */
129
+ export declare const classManager: ClassManager;
130
+ /**
131
+ * 组件管理器
132
+ */
133
+ export declare class ComponentManager {
134
+ /** 组件名到组件列表的映射 */
135
+ private components;
136
+ /**
137
+ * 获取或创建组件列表
138
+ * @param name 组件名
139
+ * @returns 组件列表
140
+ */
141
+ private getOrCreateComps;
142
+ /**
143
+ * 添加一个组件名对应的实体
144
+ * @param comName 组件名
145
+ * @param comp 组件
146
+ */
147
+ addComponent(comName: IComponentName, comp: IComponent): void;
148
+ /**
149
+ * 移除一个组件名对应的实体
150
+ * @param comName 组件名
151
+ * @param comp 组件
152
+ */
153
+ removeComponent(comName: IComponentName, comp: IComponent): void;
154
+ /**
155
+ * 根据组件名获取实体列表,可能不存在
156
+ * @param comName 组件名
157
+ * @returns 组件列表
158
+ */
159
+ getComponents(comName: IComponentName): CustomArray<IComponent<IEntity>>;
160
+ /**
161
+ * 清空所有组件
162
+ */
163
+ clear(): void;
164
+ /**
165
+ * @param callback 处理函数,用于对每个组件进行操作
166
+ * @returns 输出数组
167
+ */
168
+ eachUnique(callback: (component: IComponent) => void): void;
169
+ }
170
+ /**
171
+ * 实体管理器
172
+ */
173
+ export declare class EntityManager {
174
+ /** 实体UUID到实体的映射 */
175
+ private entities;
176
+ /**
177
+ * 检查实体是否存在
178
+ * @param uuid 实体UUID
179
+ * @returns 是否存在
180
+ */
181
+ has(uuid: IEntityUUID): IEntity;
182
+ /**
183
+ * 添加一个实体
184
+ * @param entity 实体
185
+ */
186
+ add(entity: IEntity): void;
187
+ /**
188
+ * 移除一个实体
189
+ * @param entity 实体
190
+ * @returns 是否成功移除
191
+ */
192
+ remove(entity: IEntity): boolean;
193
+ /**
194
+ * 根据UUID获取一个实体
195
+ * @param uuid 实体UUID
196
+ * @returns 实体
197
+ */
198
+ get(uuid: IEntityUUID): IEntity;
199
+ /**
200
+ * 获取所有实体
201
+ * @param out 输出数组,用于存储所有实体
202
+ * @returns 输出数组
203
+ */
204
+ getAll(out: IEntity[]): IEntity[];
205
+ /**
206
+ * 遍历所有实体
207
+ * @param callback 处理函数,用于对每个实体进行操作
208
+ */
209
+ each(callback: (value: IEntity) => void): void;
210
+ /**
211
+ * 清空所有实体
212
+ */
213
+ clear(): void;
214
+ }
215
+ /**
216
+ * 系统管理器
217
+ */
218
+ export declare class SystemManager {
219
+ private systems;
220
+ /**
221
+ * 添加一个系统
222
+ * @param system 系统
223
+ */
224
+ add(system: ISystem): void;
225
+ /**
226
+ * 根据系统名获取一个系统
227
+ * @param System 系统类型
228
+ * @returns 系统
229
+ */
230
+ get(System: ITypeofSystem): import("./EcsObject").EcsBaseSystem;
231
+ /**
232
+ * 移除一个系统
233
+ * @param System 系统类型
234
+ * @returns 是否成功移除
235
+ */
236
+ remove(System: ITypeofSystem): import("./EcsObject").EcsBaseSystem;
237
+ /**
238
+ * 清空所有系统
239
+ */
240
+ clear(): void;
241
+ /**
242
+ * 遍历所有系统
243
+ * @param callback 处理函数,用于对每个系统进行操作
244
+ */
245
+ each(callback: (value: ISystem) => void): void;
246
+ /**
247
+ * 系统数量
248
+ */
249
+ get size(): number;
250
+ }
251
+ export {};