-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystem.ecs.js
More file actions
executable file
·160 lines (128 loc) · 3.3 KB
/
Copy pathSystem.ecs.js
File metadata and controls
executable file
·160 lines (128 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// 系统基类
export function createSystemClass(ecs) {
return class BaseSystem {
constructor(world) {
// ecs
this._ecs = ecs;
// world
this._world = world;
// 运行状态
this._started = false;
// 锁定状态
this._locked = false;
// 激活状态
this._enabled = true;
}
/*
* 获取运行状态
* @return (boolean) isStarted 运行状态
*/
get started() {
return this._started;
}
/*
* 设置运行状态
* @param (boolean) val 是否激活
*/
set started(val) {
if (!val) {
return;
}
if (this._started === val) {
return;
}
this._started = val;
if (this._started) {
this.onStart();
}
}
/*
* 获取激活状态
* @return (boolean) isEnabled 激活状态
*/
get enabled() {
return this._enabled;
}
/*
* 设置激活状态
* @param (boolean) val 是否激活
*/
set enabled(val) {
if (this._locked) {
console.warn('Cannot change the enabled value when the system is updating.');
return;
}
if (this._enabled === val) {
return;
}
this._enabled = val;
if (this._enabled) {
this.onEnable();
} else {
this.onDisable();
}
}
// 系统内部初始化
initialize() {
this.onLoad();
this.onEnable();
}
// 系统内部卸载
uninitialize() {
this._ecs = null;
this.onDestroy();
}
/*
* 系统内部更新
* @param (number) dt 帧间隔时间
*/
update(dt) {
if (!this._started || !this._enabled) {
return;
}
this._locked = true;
this.onUpdate(dt);
this._locked = false;
}
/*
* 系统内部更新
* @param (number) dt 帧间隔时间
*/
lateUpdate(dt) {
if (!this._started || !this._enabled) {
return;
}
this._locked = true;
this.onLateUpdate(dt);
this._locked = false;
}
/*
* 系统内部收到消息时调用
* @param (object) data 数据
*/
receive(data) {
this.onReceive(data);
}
// 系统初始化时调用
onLoad() {}
// 系统开始运行时调用
onStart() {}
/*
* 系统更新时调用
* @param (number) dt 帧间隔时间
*/
onUpdate(dt) {}
onLateUpdate(dt) {}
// 系统被激活时调用
onEnable() {}
// 系统被禁用时调用
onDisable() {}
// 系统被注销时调用
onDestroy() {}
/*
* 系统收到消息时调用
* @param (object) data 数据
*/
onReceive(data) {}
}
};