update 2.1.30

This commit is contained in:
YHH
2025-08-11 09:31:44 +08:00
parent edc60fc3d8
commit 5bce08683a
14 changed files with 111 additions and 99 deletions

View File

@@ -157,7 +157,7 @@ console.log('查询统计:', queryStats);
### 1. 高效查询
```typescript
// 好的做法:缓存查询结果
// 好的做法:缓存查询结果
class CombatSystem extends EntitySystem {
private cachedEnemies: Entity[] = [];
private lastUpdateFrame = 0;
@@ -184,7 +184,7 @@ class CombatSystem extends EntitySystem {
### 2. 批量操作
```typescript
// 好的做法:批量创建和配置
// 好的做法:批量创建和配置
function createBulletWave(count: number): Entity[] {
// 使用Scene的批量创建
const bullets = scene.createEntities(count, "Bullet");
@@ -208,7 +208,7 @@ function createBulletWave(count: number): Entity[] {
### 3. 内存管理
```typescript
// 好的做法:及时清理无用实体
// 好的做法:及时清理无用实体
class CleanupSystem extends EntitySystem {
protected process(entities: Entity[]): void {
// 清理超出边界的子弹
@@ -241,7 +241,7 @@ class CleanupSystem extends EntitySystem {
### 4. 查询优化
```typescript
// 好的做法:使用合适的查询方法
// 好的做法:使用合适的查询方法
class GameSystem extends EntitySystem {
findTargetsInRange(attacker: Entity, range: number): Entity[] {
const attackerPos = attacker.getComponent(PositionComponent);