Skip to content

Commit 1c9276b

Browse files
committed
新增DelayedIteratingSystem/IntervalSystem/IntervalIteratingSystem
1 parent 4f7cfb0 commit 1c9276b

File tree

12 files changed

+733
-137
lines changed

12 files changed

+733
-137
lines changed

engine_support/egret/lib/framework.d.ts

Lines changed: 134 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ declare module es {
351351
* 每帧进行调用进行更新组件
352352
*/
353353
update(): void;
354+
/**
355+
* 创建组件的新实例。返回实例组件
356+
* @param componentType
357+
*/
358+
createComponent<T extends Component>(componentType: new () => T): T;
354359
/**
355360
* 将组件添加到组件列表中。返回组件。
356361
* @param component
@@ -857,15 +862,6 @@ declare module es {
857862
toString(): string;
858863
}
859864
}
860-
declare module es {
861-
class ComponentPool<T extends PooledComponent> {
862-
private _cache;
863-
private _type;
864-
constructor(typeClass: any);
865-
obtain(): T;
866-
free(component: T): void;
867-
}
868-
}
869865
declare module es {
870866
/**
871867
* 接口,当添加到一个Component时,只要Component和实体被启用,它就会在每个框架中调用更新方法。
@@ -883,12 +879,6 @@ declare module es {
883879
}
884880
var isIUpdatable: (props: any) => props is IUpdatable;
885881
}
886-
declare module es {
887-
/** 回收实例的组件类型。 */
888-
abstract class PooledComponent extends Component {
889-
abstract reset(): any;
890-
}
891-
}
892882
declare module es {
893883
class SceneComponent implements IComparer<SceneComponent> {
894884
/**
@@ -1272,6 +1262,9 @@ declare module es {
12721262
private _entities;
12731263
constructor(matcher?: Matcher);
12741264
private _scene;
1265+
/**
1266+
* 这个系统所属的场景
1267+
*/
12751268
scene: Scene;
12761269
private _matcher;
12771270
readonly matcher: Matcher;
@@ -1283,10 +1276,96 @@ declare module es {
12831276
onRemoved(entity: Entity): void;
12841277
update(): void;
12851278
lateUpdate(): void;
1279+
/**
1280+
* 在系统处理开始前调用
1281+
* 在下一个系统开始处理或新的处理回合开始之前(以先到者为准),使用此方法创建的任何实体都不会激活
1282+
*/
12861283
protected begin(): void;
12871284
protected process(entities: Entity[]): void;
12881285
protected lateProcess(entities: Entity[]): void;
1286+
/**
1287+
* 系统处理完毕后调用
1288+
*/
12891289
protected end(): void;
1290+
/**
1291+
* 系统是否需要处理
1292+
*
1293+
* 在启用系统时有用,但仅偶尔需要处理
1294+
* 这只影响处理,不影响事件或订阅列表
1295+
* @returns 如果系统应该处理,则为true,如果不处理则为false。
1296+
*/
1297+
protected checkProcessing(): boolean;
1298+
}
1299+
}
1300+
declare module es {
1301+
/**
1302+
* 追踪每个实体的冷却时间,当实体的计时器耗尽时进行处理
1303+
*
1304+
* 一个示例系统将是ExpirationSystem,该系统将在特定生存期后删除实体。
1305+
* 你不必运行会为每个实体递减timeLeft值的系统
1306+
* 而只需使用此系统在寿命最短的实体时在将来执行
1307+
* 然后重置系统在未来的某一个最短命实体的时间运行
1308+
*
1309+
* 另一个例子是一个动画系统
1310+
* 你知道什么时候你必须对某个实体进行动画制作,比如300毫秒内。
1311+
* 所以你可以设置系统以300毫秒为单位运行来执行动画
1312+
*
1313+
* 这将在某些情况下节省CPU周期
1314+
*/
1315+
abstract class DelayedIteratingSystem extends EntitySystem {
1316+
/**
1317+
* 一个实体应被处理的时间
1318+
*/
1319+
private delay;
1320+
/**
1321+
* 如果系统正在运行,并倒计时延迟
1322+
*/
1323+
private running;
1324+
/**
1325+
* 倒计时
1326+
*/
1327+
private acc;
1328+
constructor(matcher: Matcher);
1329+
protected process(entities: Entity[]): void;
1330+
protected checkProcessing(): boolean;
1331+
/**
1332+
* 只有当提供的延迟比系统当前计划执行的时间短时,才会重新启动系统。
1333+
* 如果系统已经停止(不运行),那么提供的延迟将被用来重新启动系统,无论其值如何
1334+
* 如果系统已经在倒计时,并且提供的延迟大于剩余时间,系统将忽略它。
1335+
* 如果提供的延迟时间短于剩余时间,系统将重新启动,以提供的延迟时间运行。
1336+
* @param offeredDelay
1337+
*/
1338+
offerDelay(offeredDelay: number): void;
1339+
/**
1340+
* 处理本系统感兴趣的实体
1341+
* 从实体定义的延迟中抽象出accumulativeDelta
1342+
* @param entity
1343+
* @param accumulatedDelta 本系统最后一次执行后的delta时间
1344+
*/
1345+
protected abstract processDelta(entity: Entity, accumulatedDelta: number): any;
1346+
protected abstract processExpired(entity: Entity): any;
1347+
/**
1348+
* 返回该实体处理前的延迟时间
1349+
* @param entity
1350+
*/
1351+
protected abstract getRemainingDelay(entity: Entity): number;
1352+
/**
1353+
* 获取系统被命令处理实体后的初始延迟
1354+
*/
1355+
getInitialTimeDelay(): number;
1356+
/**
1357+
* 获取系统计划运行前的时间
1358+
* 如果系统没有运行,则返回零
1359+
*/
1360+
getRemainingTimeUntilProcessing(): number;
1361+
/**
1362+
* 检查系统是否正在倒计时处理
1363+
*/
1364+
isRunning(): boolean;
1365+
/**
1366+
* 停止系统运行,中止当前倒计时
1367+
*/
1368+
stop(): void;
12901369
}
12911370
}
12921371
declare module es {
@@ -1312,6 +1391,46 @@ declare module es {
13121391
protected lateProcess(entities: Entity[]): void;
13131392
}
13141393
}
1394+
declare module es {
1395+
/**
1396+
* 实体系统以一定的时间间隔进行处理
1397+
*/
1398+
abstract class IntervalSystem extends EntitySystem {
1399+
/**
1400+
* 累积增量以跟踪间隔
1401+
*/
1402+
protected acc: number;
1403+
/**
1404+
* 更新之间需要等待多长时间
1405+
*/
1406+
private readonly interval;
1407+
private intervalDelta;
1408+
constructor(matcher: Matcher, interval: number);
1409+
protected checkProcessing(): boolean;
1410+
/**
1411+
* 获取本系统上次处理后的实际delta值
1412+
*/
1413+
protected getIntervalDelta(): number;
1414+
}
1415+
}
1416+
declare module es {
1417+
/**
1418+
* 每x个ticks处理一个实体的子集
1419+
*
1420+
* 典型的用法是每隔一定的时间间隔重新生成弹药或生命值
1421+
* 而无需在每个游戏循环中都进行
1422+
* 而是每100毫秒一次或每秒
1423+
*/
1424+
abstract class IntervalIteratingSystem extends IntervalSystem {
1425+
constructor(matcher: Matcher, interval: number);
1426+
/**
1427+
* 处理本系统感兴趣的实体
1428+
* @param entity
1429+
*/
1430+
abstract processEntity(entity: Entity): any;
1431+
protected process(entities: Entity[]): void;
1432+
}
1433+
}
13151434
declare module es {
13161435
abstract class PassiveSystem extends EntitySystem {
13171436
onChanged(entity: Entity): void;

extensions/ecs-tween

source/bin/framework.d.ts

Lines changed: 134 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ declare module es {
351351
* 每帧进行调用进行更新组件
352352
*/
353353
update(): void;
354+
/**
355+
* 创建组件的新实例。返回实例组件
356+
* @param componentType
357+
*/
358+
createComponent<T extends Component>(componentType: new () => T): T;
354359
/**
355360
* 将组件添加到组件列表中。返回组件。
356361
* @param component
@@ -857,15 +862,6 @@ declare module es {
857862
toString(): string;
858863
}
859864
}
860-
declare module es {
861-
class ComponentPool<T extends PooledComponent> {
862-
private _cache;
863-
private _type;
864-
constructor(typeClass: any);
865-
obtain(): T;
866-
free(component: T): void;
867-
}
868-
}
869865
declare module es {
870866
/**
871867
* 接口,当添加到一个Component时,只要Component和实体被启用,它就会在每个框架中调用更新方法。
@@ -883,12 +879,6 @@ declare module es {
883879
}
884880
var isIUpdatable: (props: any) => props is IUpdatable;
885881
}
886-
declare module es {
887-
/** 回收实例的组件类型。 */
888-
abstract class PooledComponent extends Component {
889-
abstract reset(): any;
890-
}
891-
}
892882
declare module es {
893883
class SceneComponent implements IComparer<SceneComponent> {
894884
/**
@@ -1272,6 +1262,9 @@ declare module es {
12721262
private _entities;
12731263
constructor(matcher?: Matcher);
12741264
private _scene;
1265+
/**
1266+
* 这个系统所属的场景
1267+
*/
12751268
scene: Scene;
12761269
private _matcher;
12771270
readonly matcher: Matcher;
@@ -1283,10 +1276,96 @@ declare module es {
12831276
onRemoved(entity: Entity): void;
12841277
update(): void;
12851278
lateUpdate(): void;
1279+
/**
1280+
* 在系统处理开始前调用
1281+
* 在下一个系统开始处理或新的处理回合开始之前(以先到者为准),使用此方法创建的任何实体都不会激活
1282+
*/
12861283
protected begin(): void;
12871284
protected process(entities: Entity[]): void;
12881285
protected lateProcess(entities: Entity[]): void;
1286+
/**
1287+
* 系统处理完毕后调用
1288+
*/
12891289
protected end(): void;
1290+
/**
1291+
* 系统是否需要处理
1292+
*
1293+
* 在启用系统时有用,但仅偶尔需要处理
1294+
* 这只影响处理,不影响事件或订阅列表
1295+
* @returns 如果系统应该处理,则为true,如果不处理则为false。
1296+
*/
1297+
protected checkProcessing(): boolean;
1298+
}
1299+
}
1300+
declare module es {
1301+
/**
1302+
* 追踪每个实体的冷却时间,当实体的计时器耗尽时进行处理
1303+
*
1304+
* 一个示例系统将是ExpirationSystem,该系统将在特定生存期后删除实体。
1305+
* 你不必运行会为每个实体递减timeLeft值的系统
1306+
* 而只需使用此系统在寿命最短的实体时在将来执行
1307+
* 然后重置系统在未来的某一个最短命实体的时间运行
1308+
*
1309+
* 另一个例子是一个动画系统
1310+
* 你知道什么时候你必须对某个实体进行动画制作,比如300毫秒内。
1311+
* 所以你可以设置系统以300毫秒为单位运行来执行动画
1312+
*
1313+
* 这将在某些情况下节省CPU周期
1314+
*/
1315+
abstract class DelayedIteratingSystem extends EntitySystem {
1316+
/**
1317+
* 一个实体应被处理的时间
1318+
*/
1319+
private delay;
1320+
/**
1321+
* 如果系统正在运行,并倒计时延迟
1322+
*/
1323+
private running;
1324+
/**
1325+
* 倒计时
1326+
*/
1327+
private acc;
1328+
constructor(matcher: Matcher);
1329+
protected process(entities: Entity[]): void;
1330+
protected checkProcessing(): boolean;
1331+
/**
1332+
* 只有当提供的延迟比系统当前计划执行的时间短时,才会重新启动系统。
1333+
* 如果系统已经停止(不运行),那么提供的延迟将被用来重新启动系统,无论其值如何
1334+
* 如果系统已经在倒计时,并且提供的延迟大于剩余时间,系统将忽略它。
1335+
* 如果提供的延迟时间短于剩余时间,系统将重新启动,以提供的延迟时间运行。
1336+
* @param offeredDelay
1337+
*/
1338+
offerDelay(offeredDelay: number): void;
1339+
/**
1340+
* 处理本系统感兴趣的实体
1341+
* 从实体定义的延迟中抽象出accumulativeDelta
1342+
* @param entity
1343+
* @param accumulatedDelta 本系统最后一次执行后的delta时间
1344+
*/
1345+
protected abstract processDelta(entity: Entity, accumulatedDelta: number): any;
1346+
protected abstract processExpired(entity: Entity): any;
1347+
/**
1348+
* 返回该实体处理前的延迟时间
1349+
* @param entity
1350+
*/
1351+
protected abstract getRemainingDelay(entity: Entity): number;
1352+
/**
1353+
* 获取系统被命令处理实体后的初始延迟
1354+
*/
1355+
getInitialTimeDelay(): number;
1356+
/**
1357+
* 获取系统计划运行前的时间
1358+
* 如果系统没有运行,则返回零
1359+
*/
1360+
getRemainingTimeUntilProcessing(): number;
1361+
/**
1362+
* 检查系统是否正在倒计时处理
1363+
*/
1364+
isRunning(): boolean;
1365+
/**
1366+
* 停止系统运行,中止当前倒计时
1367+
*/
1368+
stop(): void;
12901369
}
12911370
}
12921371
declare module es {
@@ -1312,6 +1391,46 @@ declare module es {
13121391
protected lateProcess(entities: Entity[]): void;
13131392
}
13141393
}
1394+
declare module es {
1395+
/**
1396+
* 实体系统以一定的时间间隔进行处理
1397+
*/
1398+
abstract class IntervalSystem extends EntitySystem {
1399+
/**
1400+
* 累积增量以跟踪间隔
1401+
*/
1402+
protected acc: number;
1403+
/**
1404+
* 更新之间需要等待多长时间
1405+
*/
1406+
private readonly interval;
1407+
private intervalDelta;
1408+
constructor(matcher: Matcher, interval: number);
1409+
protected checkProcessing(): boolean;
1410+
/**
1411+
* 获取本系统上次处理后的实际delta值
1412+
*/
1413+
protected getIntervalDelta(): number;
1414+
}
1415+
}
1416+
declare module es {
1417+
/**
1418+
* 每x个ticks处理一个实体的子集
1419+
*
1420+
* 典型的用法是每隔一定的时间间隔重新生成弹药或生命值
1421+
* 而无需在每个游戏循环中都进行
1422+
* 而是每100毫秒一次或每秒
1423+
*/
1424+
abstract class IntervalIteratingSystem extends IntervalSystem {
1425+
constructor(matcher: Matcher, interval: number);
1426+
/**
1427+
* 处理本系统感兴趣的实体
1428+
* @param entity
1429+
*/
1430+
abstract processEntity(entity: Entity): any;
1431+
protected process(entities: Entity[]): void;
1432+
}
1433+
}
13151434
declare module es {
13161435
abstract class PassiveSystem extends EntitySystem {
13171436
onChanged(entity: Entity): void;

0 commit comments

Comments
 (0)