补ECS注释

This commit is contained in:
donggang
2024-06-06 13:32:31 +08:00
parent 9590227756
commit b0e156c1be
4 changed files with 16 additions and 7 deletions

View File

@@ -4,6 +4,11 @@ import { ECSMatcher } from "./ECSMatcher";
import { CompCtor, CompType, ECSModel, EntityCtor } from "./ECSModel";
import { ECSComblockSystem, ECSRootSystem, ECSSystem } from "./ECSSystem";
/**
* ECSEntity对象在destroy后会回收到ECSModel.entityPool实体对象池中
* ECSComp对象从ECSEntity.remove后数据组件会回收到ECSModel.compPools组件对象池中
*/
/** Entity-Component-System实体-组件-系统)框架 */
export module ecs {
/** 实体 - 一个概念上的定义,指的是游戏世界中的一个独特物体,是一系列组件的集合 */
@@ -138,7 +143,7 @@ export module ecs {
ctor.tid = ECSModel.compTid++;
ctor.compName = name;
if (canNew) {
ECSModel.compCtors.push(ctor);
ECSModel.compCtors.push(ctor); // 注册不同类型的组件
ECSModel.compPools.set(ctor.tid, []);
}
else {

View File

@@ -241,15 +241,19 @@ export class ECSEntity {
comp.ent = null;
if (isRecycle) {
comp.reset();
// 回收组件到指定缓存池中
if (comp.canRecycle) {
ECSModel.compPools.get(componentTypeId)!.push(comp);
const compPoolsType = ECSModel.compPools.get(componentTypeId)!;
compPoolsType.push(comp);
}
}
else {
this.compTid2Obj.set(componentTypeId, comp);
this.compTid2Obj.set(componentTypeId, comp); // 用于缓存显示对象组件
}
}
// 删除实体上的组件逻辑
if (hasComp) {
//@ts-ignore
this[compName] = null;

View File

@@ -42,7 +42,7 @@ export class ECSModel {
static compTid = 0;
/** 组件缓存池 */
static compPools: Map<number, ecs.IComp[]> = new Map();
/** 组件构造函数 */
/** 组件构造函数用于ecs.register注册时记录不同类型的组件 */
static compCtors: (CompCtor<any> | number)[] = [];
/**
* 每个组件的添加和删除的动作都要派送到“关心”它们的group上。goup对当前拥有或者之前删除前拥有该组件的实体进行组件规则判断。判断该实体是否满足group

View File

@@ -62,10 +62,10 @@ export class ModuleUtil {
* @param ent 模块实体
* @param ctor 界面逻辑组件
* @param uiId 界面资源编号
* @param isDestroy 是否释放界面缓存
* @param isDestroy 是否释放界面缓存(默认为释放界面缓存)
*/
public static removeViewUi(ent: ecs.Entity, ctor: CompType<ecs.IComp>, uiId: number, isDestroy?: boolean) {
ent.remove(ctor);
public static removeViewUi(ent: ecs.Entity, ctor: CompType<ecs.IComp>, uiId: number, isDestroy: boolean = true) {
ent.remove(ctor, isDestroy);
oops.gui.remove(uiId, isDestroy);
}