@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,141 @@
1
+ import { Vec2 } from 'cc';
2
+ import { EcsComponent } from '../../ecs/EcsComponent';
3
+ import { IEntity } from '../../lib/EcsObject';
4
+ import { NodeComponent } from './NodeComponent';
5
+ interface IOptions {
6
+ /**
7
+ * 允许旋转
8
+ * - 当rotate为true时,angle属性才会同步到NodeComponent
9
+ * @description 默认值: false
10
+ */
11
+ rotate: boolean;
12
+ /**
13
+ * 最小速度
14
+ * @description 单位: 像素/秒
15
+ * @description 默认值: -Infinity
16
+ * @description 取值范围: (-oo, +oo)
17
+ */
18
+ minSpeed: number;
19
+ /**
20
+ * 最大速度
21
+ * @description 单位: 像素/秒
22
+ * @description 默认值: Infinity
23
+ * @description 取值范围: (-oo, +oo)
24
+ */
25
+ maxSpeed: number;
26
+ /**
27
+ * 加速度
28
+ * @description 单位: 像素/秒
29
+ * @description 默认值: 0
30
+ * @description 取值范围: (-oo, +oo)
31
+ */
32
+ acceleratedVelocity: number;
33
+ /**
34
+ * 角速度(0表示无穷大)
35
+ * @description 单位: 度/秒
36
+ * @description 默认值: 0
37
+ * @description 取值范围: [0, +oo)
38
+ */
39
+ angleVelocity: number;
40
+ }
41
+ export interface IMoveComponent {
42
+ /**
43
+ * 选项参数
44
+ */
45
+ options: IOptions;
46
+ /**
47
+ * 最终的目标
48
+ * - taget与toward二选一, 且必须设置一个
49
+ * @description 默认值: null
50
+ */
51
+ target: NodeComponent;
52
+ /**
53
+ * 最终的角度
54
+ * - taget与toward二选一, 且必须设置一个
55
+ * @description 单位: 度
56
+ * @description 默认值: 0
57
+ * @description 取值范围: (-180, 180]
58
+ */
59
+ toward: number;
60
+ /**
61
+ * 当前速度
62
+ * @description 单位: 像素/秒
63
+ * @description 默认值: 0
64
+ * @description 取值范围: (-oo, +oo)
65
+ */
66
+ speed: number;
67
+ /**
68
+ * 当前角度
69
+ * @description 单位: 度
70
+ * @description 默认值: 0
71
+ * @description 取值范围: (-180, 180]
72
+ */
73
+ angle: number;
74
+ /**
75
+ * 总移动距离
76
+ * @description 单位: 像素
77
+ * @description 默认值: 0
78
+ * @description 取值范围: [0, +oo)
79
+ */
80
+ distance: number;
81
+ }
82
+ /**
83
+ * 移动方向(只给出了常用的方向)
84
+ * @description 单位: 度
85
+ * @description 取值范围: (-180, 180]
86
+ */
87
+ export declare enum MoveTowardType {
88
+ Right = 0,
89
+ RightUp = 45,
90
+ Up = 90,
91
+ LeftUp = 135,
92
+ Left = 180,
93
+ LeftDown = -135,
94
+ Down = -90,
95
+ RightDown = -45
96
+ }
97
+ export declare class MoveComponent<T extends IEntity = IEntity> extends EcsComponent<T> implements IMoveComponent {
98
+ static allowRecycling: boolean;
99
+ protected onRemove(): void;
100
+ reset(): void;
101
+ private _options;
102
+ get options(): IOptions;
103
+ set options(value: IOptions);
104
+ private _distance;
105
+ get distance(): number;
106
+ private set distance(value);
107
+ private _targetUUID;
108
+ private _target;
109
+ get target(): NodeComponent;
110
+ set target(value: NodeComponent);
111
+ private _toward;
112
+ get toward(): number;
113
+ set toward(value: number);
114
+ private _angle;
115
+ get angle(): number;
116
+ set angle(value: number);
117
+ private _speed;
118
+ get speed(): number;
119
+ set speed(value: number);
120
+ /**
121
+ * 获取self朝向other的角度
122
+ */
123
+ static getTowardAngle(self: NodeComponent, other: NodeComponent): number;
124
+ /**
125
+ * 修正到(-180, 180]
126
+ */
127
+ static getAngleFromNeg180to180(angle: number): number;
128
+ /**
129
+ * 修正到[0, 360)
130
+ */
131
+ static getAngleFrom0To360(angle: number): number;
132
+ /**
133
+ * 修正到(-360, 0]
134
+ */
135
+ static getAngleFromNeg360To0(angle: number): number;
136
+ /**
137
+ * 根据速度二维分量获取toward值
138
+ */
139
+ static getTowardByVelocity(velocity: Vec2): number;
140
+ }
141
+ export {};
@@ -0,0 +1,98 @@
1
+ import { Quat, Rect, Size, Vec2, Vec3 } from 'cc';
2
+ import { EcsComponent } from '../../ecs/EcsComponent';
3
+ import { IEntity } from '../../lib/EcsObject';
4
+ interface ILikeSize {
5
+ readonly width: number;
6
+ readonly height: number;
7
+ }
8
+ interface ILikeV2 {
9
+ readonly x: number;
10
+ readonly y: number;
11
+ }
12
+ interface ILikeV3 {
13
+ readonly x: number;
14
+ readonly y: number;
15
+ readonly z: number;
16
+ }
17
+ export declare class NodeComponent<T extends IEntity = IEntity> extends EcsComponent<T> {
18
+ static allowRecycling: boolean;
19
+ protected onRemove(): void;
20
+ reset(): void;
21
+ /**是否需要更新BoundingBox */
22
+ protected isBoundingBoxDirty: boolean;
23
+ protected $position: Vec3;
24
+ /**坐标 */
25
+ get position(): Readonly<ILikeV3>;
26
+ /**x坐标 */
27
+ get x(): number;
28
+ set x(value: number);
29
+ /**y坐标 */
30
+ get y(): number;
31
+ set y(value: number);
32
+ /**z坐标 */
33
+ get z(): number;
34
+ set z(value: number);
35
+ protected $scale: Vec3;
36
+ /**缩放 */
37
+ get scale(): Readonly<ILikeV3>;
38
+ /**缩放x */
39
+ get scaleX(): number;
40
+ set scaleX(value: number);
41
+ /**缩放y */
42
+ get scaleY(): number;
43
+ set scaleY(value: number);
44
+ /**缩放z */
45
+ get scaleZ(): number;
46
+ set scaleZ(value: number);
47
+ protected $anchorPoint: Vec2;
48
+ /**锚点 */
49
+ get anchorPoint(): Readonly<ILikeV2>;
50
+ /**锚点x */
51
+ get anchorX(): number;
52
+ set anchorX(value: number);
53
+ /**锚点y */
54
+ get anchorY(): number;
55
+ set anchorY(value: number);
56
+ protected $contentSize: Size;
57
+ /**尺寸 */
58
+ get contentSize(): Readonly<ILikeSize>;
59
+ /**宽 */
60
+ get width(): number;
61
+ set width(value: number);
62
+ /**高 */
63
+ get height(): number;
64
+ set height(value: number);
65
+ protected $lrot: Quat;
66
+ /**本地坐标系下的旋转,用四元数表示 */
67
+ get rotation(): Readonly<Quat>;
68
+ set rotation(val: Readonly<Quat>);
69
+ protected $euler: Vec3;
70
+ /**本地坐标系下的旋转,用欧拉角表示 */
71
+ get eulerAngles(): Readonly<Vec3>;
72
+ set eulerAngles(val: Readonly<Vec3>);
73
+ /**本地坐标系下的旋转,用欧拉角表示,但是限定在 z 轴上 */
74
+ get angle(): number;
75
+ set angle(value: number);
76
+ private _boundingBox;
77
+ private _boundingBoxOut;
78
+ /**轴对称包围盒 */
79
+ get boundingBox(): Rect;
80
+ protected _updateBoundingBox(): void;
81
+ /**最小x坐标 */
82
+ get minX(): number;
83
+ /**最小y坐标 */
84
+ get minY(): number;
85
+ /**最大x坐标 */
86
+ get maxX(): number;
87
+ /**最大y坐标 */
88
+ get maxY(): number;
89
+ setPosition(x: number, y: number, z?: number): this;
90
+ addPosition(x: number, y: number, z?: number): this;
91
+ setScale(x: number, y: number, z?: number): this;
92
+ addScale(x: number, y: number, z?: number): this;
93
+ setAngle(angle: number): this;
94
+ addAngle(angle: number): this;
95
+ setContentSize(width: number, height: number): this;
96
+ setAnchorPoints(x: number, y: number): this;
97
+ }
98
+ export {};
@@ -0,0 +1,17 @@
1
+ import { EcsSystem } from '../../ecs/EcsSystem';
2
+ /**
3
+ * 负责驱动move组件
4
+ */
5
+ export declare class MoveSystem extends EcsSystem {
6
+ private filter;
7
+ protected execute(dt?: number): void;
8
+ /**
9
+ * 处理
10
+ * @param move
11
+ * @param entity
12
+ * @param dt
13
+ */
14
+ private handle;
15
+ private run;
16
+ private rotate;
17
+ }
@@ -0,0 +1,89 @@
1
+ import { EcsBaseComponent, IComponent, IEntity } from '../lib/EcsObject';
2
+ import type { EcsDirtyMask, IEcsComponentDirtySink } from './EcsDirty';
3
+ export declare class EcsComponent<E extends IEntity = IEntity> extends EcsBaseComponent implements IComponent {
4
+ static readonly Fields: Record<string, any>;
5
+ /**内部函数 */
6
+ static updateEnable(comp: EcsComponent): void;
7
+ /** 内部函数:ECS/observed runtime 用它把 dirty sink 绑定到组件实例。 */
8
+ static bindDirtySink(comp: EcsComponent, sink: IEcsComponentDirtySink | null): void;
9
+ /**内部函数 */
10
+ static beforeRemove(comp: EcsComponent): void;
11
+ /**内部函数 */
12
+ static onAdd(comp: EcsComponent, entity: IEntity): void;
13
+ /**内部函数 */
14
+ static onRemove(comp: EcsComponent): void;
15
+ /**正在初始化中 */
16
+ private _initing;
17
+ /**正在移除中 */
18
+ private _removing;
19
+ /** 当前组件累积的 dirty bit。未安装 observed 时也会维护这个本地状态。 */
20
+ private _dirtyMask;
21
+ /** 每次 dirtyMask 从“未包含某 bit”变为“包含某 bit”时递增,方便调试或增量同步判断。 */
22
+ private _dirtyVersion;
23
+ /** 可选扩展 sink。只有 observed runtime install 后才会非空。 */
24
+ private _dirtySink;
25
+ /**是否有效 */
26
+ private _isValid;
27
+ get isValid(): boolean;
28
+ private set isValid(value);
29
+ get isStrictValid(): boolean;
30
+ /**是否生效 */
31
+ private _enabled;
32
+ get enabled(): boolean;
33
+ set enabled(value: boolean);
34
+ /**当前组件所在的实体 */
35
+ private _entity;
36
+ get entity(): E;
37
+ private set entity(value);
38
+ /**表示该组件是否被启用并且所在的实体也处于启用状态(为false代表不会被查询到) */
39
+ get enabledInHierarchy(): boolean;
40
+ private __enabled;
41
+ private updateEnable;
42
+ get dirty(): boolean;
43
+ /**
44
+ * 兼容旧式 boolean dirty 用法。
45
+ * 设置 true 等价于 markDirty(1),设置 false 会清掉全部 dirty bit。
46
+ */
47
+ set dirty(value: boolean);
48
+ get dirtyMask(): EcsDirtyMask;
49
+ get dirtyVersion(): number;
50
+ /** 判断当前组件是否包含指定 dirty bit。 */
51
+ hasDirty(mask: EcsDirtyMask): boolean;
52
+ /**
53
+ * 标记组件 dirty。
54
+ *
55
+ * 业务组件的写屏障应该调用它,例如 position.setXYRaw 后标记 PositionDirtyBits.Spatial。
56
+ * 如果 observed runtime 已安装,会同步入队;未安装时只更新本地 dirtyMask/version。
57
+ */
58
+ markDirty(mask?: EcsDirtyMask): void;
59
+ /**
60
+ * 清理组件 dirty。
61
+ * drain 默认会调用它清理 matched bit;业务也可以在重置组件状态时主动调用。
62
+ */
63
+ clearDirty(mask?: EcsDirtyMask): void;
64
+ /**
65
+ * 静默清理本地 dirtyMask,不通知 sink。
66
+ * 只用于组件移除/回收这类生命周期收尾,普通业务不要用它代替 clearDirty。
67
+ */
68
+ clearDirtySilent(): void;
69
+ /**
70
+ * 组件被添加(内部调用)
71
+ */
72
+ private innerAdd;
73
+ /**
74
+ * 组件被移除前(内部调用)
75
+ */
76
+ private innerBeforeRemove;
77
+ /**
78
+ * 组件被移除(内部调用)
79
+ */
80
+ private innerRemove;
81
+ protected onAdd(): void;
82
+ protected onEnable(): void;
83
+ protected onDisable(): void;
84
+ protected onRemove(): void;
85
+ destroy(): boolean;
86
+ protected log(...args: any[]): void;
87
+ protected warn(...args: any[]): void;
88
+ protected error(...args: any[]): void;
89
+ }