wiki更新
This commit is contained in:
@@ -2,16 +2,22 @@
|
||||
|
||||
<cite>
|
||||
**本文档引用文件**
|
||||
- [Mission.ts](file://assets/script/game/common/config/Mission.ts)
|
||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts)
|
||||
- [VictoryComp.ts](file://assets/script/game/map/VictoryComp.ts)
|
||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts)
|
||||
- [GameUIConfig.ts](file://assets/script/game/common/config/GameUIConfig.ts)
|
||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts)
|
||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts)
|
||||
- [Design.md](file://assets/script/Design.md)
|
||||
- [Mission.ts](file://assets/script/game/common/config/Mission.ts) - *奖励常量配置*
|
||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts) - *奖励数据管理与实体销毁逻辑*
|
||||
- [VictoryComp.ts](file://assets/script/game/map/VictoryComp.ts) - *奖励界面展示*
|
||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts) - *事件定义*
|
||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts) - *怪物生成与事件处理*
|
||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts) - *肉鸽关卡配置*
|
||||
- [Design.md](file://assets/script/Design.md) - *系统设计概述*
|
||||
</cite>
|
||||
|
||||
## 更新摘要
|
||||
**变更内容**
|
||||
- 更新了`MissionComp`中实体销毁逻辑,修复空引用问题
|
||||
- 修正奖励发放流程中组件清理的实现方式
|
||||
- 更新相关章节以反映最新的代码实现
|
||||
- 增强源码追踪信息,标注关键修改点
|
||||
|
||||
## 目录
|
||||
1. [奖励系统概述](#奖励系统概述)
|
||||
2. [三选一奖励机制](#三选一奖励机制)
|
||||
@@ -232,6 +238,31 @@ VictoryComp --> GameEvent : "触发"
|
||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts#L43)
|
||||
- [GameUIConfig.ts](file://assets/script/game/common/config/GameUIConfig.ts#L30)
|
||||
|
||||
### 实体销毁逻辑优化
|
||||
|
||||
根据最新代码变更,`MissionComp`中的`cleanComponents`方法已优化,修复了实体销毁时可能出现的空引用问题。新的实现直接销毁实体,让ECS系统自动处理组件清理,避免在组件`reset`方法中访问已被销毁的实体引用。
|
||||
|
||||
```typescript
|
||||
private cleanComponents() {
|
||||
// 优化销毁顺序:直接销毁实体,让ECS系统自动处理组件清理
|
||||
// 这样可以避免在组件reset方法中访问已经被销毁的实体引用
|
||||
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
ecs.query(ecs.allOf(AtkConCom)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
ecs.query(ecs.allOf(SkillViewCom)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
此变更确保了在战斗结束后的清理过程中,不会因组件访问已被销毁的实体而导致运行时错误,提高了系统的稳定性。
|
||||
|
||||
**Section sources**
|
||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts#L137-L149) - *修复实体销毁空引用问题*
|
||||
|
||||
## 扩展新奖励类型
|
||||
|
||||
### 配置修改步骤
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
**本文档引用的文件**
|
||||
- [Mission.ts](file://assets/script/game/common/config/Mission.ts)
|
||||
- [Tasks.ts](file://assets/script/game/common/config/Tasks.ts)
|
||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts)
|
||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts) - *最近提交中已更新*
|
||||
- [MissionHeroComp.ts](file://assets/script/game/map/MissionHeroComp.ts)
|
||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts)
|
||||
- [MissionHomeComp.ts](file://assets/script/game/map/MissionHomeComp.ts)
|
||||
@@ -17,6 +17,13 @@
|
||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts)
|
||||
</cite>
|
||||
|
||||
## 更新摘要
|
||||
**已做更改**
|
||||
- 更新了“核心组件分析”中关于MissionComp的实体销毁逻辑说明
|
||||
- 修正了“性能优化考虑”中关于组件清理的描述
|
||||
- 移除了过时的故障排除建议,增加了针对空引用问题的解决方案
|
||||
- 所有文件引用和标题均已转换为中文
|
||||
|
||||
## 目录
|
||||
1. [简介](#简介)
|
||||
2. [系统架构概览](#系统架构概览)
|
||||
@@ -524,6 +531,31 @@ do_reward() {
|
||||
2. **随机数优化**:使用高效的随机数生成算法
|
||||
3. **数据结构优化**:使用合适的数据结构提高查找效率
|
||||
|
||||
### 实体销毁优化
|
||||
|
||||
根据最近的代码提交,MissionComp中的实体销毁逻辑已优化:
|
||||
|
||||
```typescript
|
||||
private cleanComponents() {
|
||||
// 优化销毁顺序:直接销毁实体,让ECS系统自动处理组件清理
|
||||
// 这样可以避免在组件reset方法中访问已经被销毁的实体引用
|
||||
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
ecs.query(ecs.allOf(AtkConCom)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
ecs.query(ecs.allOf(SkillViewCom)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
此更改修复了实体销毁时可能出现的空引用问题,确保在清理过程中不会访问已被销毁的实体。
|
||||
|
||||
**节来源**
|
||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts#L137-L149) - *最近提交中已更新*
|
||||
|
||||
## 故障排除指南
|
||||
|
||||
### 常见问题及解决方案
|
||||
@@ -580,35 +612,36 @@ validateRewardWeights() {
|
||||
}
|
||||
```
|
||||
|
||||
#### 性能问题
|
||||
#### 实体销毁空引用问题
|
||||
|
||||
**症状**:奖励生成过程卡顿
|
||||
**症状**:在组件清理过程中出现空引用错误
|
||||
|
||||
**原因分析**:
|
||||
1. 奖励算法复杂度过高
|
||||
2. 数据库查询频繁
|
||||
3. UI渲染过于复杂
|
||||
1. 组件清理顺序不当
|
||||
2. 在reset方法中访问已被销毁的实体
|
||||
|
||||
**解决方案**:
|
||||
```typescript
|
||||
// 优化奖励生成算法
|
||||
async generateRewardsOptimized() {
|
||||
// 使用Web Worker异步处理
|
||||
const worker = new Worker('reward_worker.js');
|
||||
|
||||
worker.postMessage({
|
||||
monsters: this.monsters,
|
||||
heroes: this.heroes,
|
||||
difficulty: this.difficulty
|
||||
// 优化后的实体销毁方法
|
||||
private cleanComponents() {
|
||||
// 直接销毁实体,让ECS系统自动处理组件清理
|
||||
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
ecs.query(ecs.allOf(AtkConCom)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
ecs.query(ecs.allOf(SkillViewCom)).forEach(entity => {
|
||||
entity.destroy();
|
||||
});
|
||||
|
||||
worker.onmessage = (e) => {
|
||||
this.rewards = e.data;
|
||||
this.displayRewards();
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
此解决方案通过直接销毁实体而非逐个清理组件,避免了在组件reset方法中访问已被销毁实体的问题。
|
||||
|
||||
**节来源**
|
||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts#L137-L149) - *最近提交中已更新*
|
||||
|
||||
## 总结
|
||||
|
||||
奖励系统是本游戏的核心机制,通过精心设计的三选一奖励选择模式,为玩家提供了丰富的策略选择空间。系统采用模块化架构,各组件职责明确,通过事件驱动的方式实现松耦合设计。
|
||||
|
||||
Reference in New Issue
Block a user