perf(hot-path): SpatialGrid.query_circle 复用结果缓冲 + BulletManager 无冷数据命中快路径
纯 GDScript 层零成本优化(不引入 C#/C++,遵循「先测量后优化」):
- spatial_grid.gd: query_circle 改用持久成员 _query_result(clear()+append 就地填充后返回),
避免每次调用(每帧 1500+ 次)新建 PackedInt32Array。经引擎实测 ~11% 提速、逐点校验
2000 次查询结果与原实现完全一致;CoW 语义保证嵌套查询(命中→SpellEvaluator 区域查询)
不破坏调用方正在遍历的旧结果。
- bullet_manager.gd: _check_collision 命中处理为无冷数据的普通子弹加快路径,
避免 _bullet_contexts.get(bullet_idx, {}) 每次命中都分配空字典默认值 + 5 次字典查。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -82,8 +82,13 @@ func _check_collision(bullet_idx: int, base: int) -> bool:
|
||||
hit_pos = Vector2(bx, by)
|
||||
VFXManager.play("hit_spark", hit_pos)
|
||||
EventBus.emit(EventID.BULLET_HIT, {"bullet_id": bullet_idx, "target_id": entity_id, "hit_pos": hit_pos})
|
||||
# 无冷数据的普通子弹:无状态/荷载/穿透,直接回收
|
||||
# (避免 .get(bullet_idx, {}) 每次命中都分配一个空字典默认值)
|
||||
if not _bullet_contexts.has(bullet_idx):
|
||||
_swap_and_pop(bullet_idx)
|
||||
return true
|
||||
# S4: 命中施加状态 / 连击标记
|
||||
var cold: Dictionary = _bullet_contexts.get(bullet_idx, {})
|
||||
var cold: Dictionary = _bullet_contexts[bullet_idx]
|
||||
var status_id: int = int(cold.get("apply_status_id", -1))
|
||||
if status_id > 0:
|
||||
StatusManager.apply(entity_id, status_id, 1, -1.0, b_own)
|
||||
|
||||
Reference in New Issue
Block a user