- 新增 script/playable_soak.sh:先做 soak 配置/资源校验,无 --allow-gameplay 只校验不启动客户端;N(>=10) 次独立正常退出运行 + 墙钟 soak,失败即停止后续 运行并记 BLOCKED;写本批次 release-manifest.json 后聚合 - run_client_gate.sh:确认的故障代理对所有 suite 启动(共享场景的退出运行也经代理); soak 超时下限只约束 soak 客户端(validate_soak 增加 soak_client 参数) - 新增本地 127.0.0.1 故障代理、RSS 采样/内存判定、窗口/指标/流程模块及其测试 - forest_mob_render_test 输出 PASS/FAIL 标记,供 rendering_batch_test.sh 识别 - 新增 docs/FIRST-MAC-PLAYABLE-STATUS.md:如实记录 PASS/BLOCKED、已知问题与环境需求 - .gitignore 排除本地场景配置、凭据文件与运行输出 离线回归:rendering_batch_test.sh failures=0,playable_gate_test.sh PASS, node 夹具测试 PASS。未联网运行,未重建候选包。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ft3kXpNdLbKEfg5uDLfqVF
147 lines
5.0 KiB
GDScript
147 lines
5.0 KiB
GDScript
# EffectRegistry (P5) —— 按名字 / 路径找 `.mse`,缓存解析结果,生成 EffectPlayer。
|
|
#
|
|
# var fxr := preload("res://fx/effect_registry.gd").new()
|
|
# fxr.setup(assets_root)
|
|
# fxr.spawn("geompung_3_sword", weapon_bone_node) # 挂到某节点下播一次性
|
|
# var pv := fxr.spawn_at("hit_spark", world, global_pos)
|
|
extends RefCounted
|
|
|
|
## Lifecycle boundaries of every effect this registry creates. lifetime_ms is the
|
|
## MSE-defined length (-1 = looping, lives as long as its owner). fx_finished is
|
|
## emitted when the node actually leaves the tree; reason "cleanup" means its own
|
|
## playback clock freed it, "removed" means the owner/scene removed it earlier.
|
|
signal fx_spawned(effect: String, fx_id: int, lifetime_ms: int)
|
|
signal fx_finished(effect: String, fx_id: int, lifetime_ms: int, elapsed_ms: int, reason: String)
|
|
|
|
const Mse = preload("res://fx/mse.gd")
|
|
const EffectPlayer = preload("res://fx/effect_player.gd")
|
|
|
|
var assets_root := ""
|
|
var _path_cache := {} # name -> abs .mse path ("" = not found)
|
|
var _spec_cache := {} # abs path -> parsed spec
|
|
# Process-wide so ids stay unique when GameScene rebuilds its registry.
|
|
static var _next_fx_id := 0
|
|
|
|
func setup(assets: String) -> void:
|
|
assets_root = assets
|
|
|
|
# name 可为: 裸名 "xxx"(扫 **/effect/ 下 xxx.mse)· 相对 "effect/xxx.mse" · "d:/ymir work/.../xxx.mse"
|
|
func resolve(name: String) -> String:
|
|
if _path_cache.has(name):
|
|
return _path_cache[name]
|
|
var p := _resolve_uncached(name)
|
|
_path_cache[name] = p
|
|
return p
|
|
|
|
func _resolve_uncached(name: String) -> String:
|
|
if assets_root == "":
|
|
return ""
|
|
var rel := name.replace("\\", "/")
|
|
if rel.length() >= 2 and rel[1] == ":":
|
|
rel = rel.substr(2)
|
|
rel = rel.lstrip("/")
|
|
if not rel.ends_with(".mse"):
|
|
rel += ".mse"
|
|
# 直接 / 散包相对
|
|
for cand in [assets_root.path_join(rel)]:
|
|
if FileAccess.file_exists(cand):
|
|
return cand
|
|
var da := DirAccess.open(assets_root)
|
|
if da:
|
|
for sub in da.get_directories():
|
|
var c := assets_root.path_join(sub).path_join(rel)
|
|
if FileAccess.file_exists(c):
|
|
return c
|
|
# 裸名:按 basename 递归找(限定 effect 目录,限量)
|
|
if not name.contains("/"):
|
|
var bn := rel.get_file()
|
|
var hit := _scan_for(assets_root, bn, 7)
|
|
if hit != "":
|
|
return hit
|
|
return ""
|
|
|
|
func _scan_for(dir: String, basename: String, depth: int) -> String:
|
|
if depth < 0:
|
|
return ""
|
|
var da := DirAccess.open(dir)
|
|
if da == null:
|
|
return ""
|
|
for f in da.get_files():
|
|
if f == basename:
|
|
return dir.path_join(f)
|
|
for sub in da.get_directories():
|
|
if sub.begins_with("."):
|
|
continue
|
|
var r := _scan_for(dir.path_join(sub), basename, depth - 1)
|
|
if r != "":
|
|
return r
|
|
return ""
|
|
|
|
func spec_for(name: String) -> Dictionary:
|
|
var p := resolve(name)
|
|
if p == "":
|
|
return {}
|
|
if _spec_cache.has(p):
|
|
return _spec_cache[p]
|
|
var s := Mse.new().parse_file(p)
|
|
_spec_cache[p] = s
|
|
return s
|
|
|
|
# 挂到 parent 下(跟随 parent 变换),播一次性
|
|
func spawn(name: String, parent: Node3D, one_shot := true) -> Node3D:
|
|
var s := spec_for(name)
|
|
if s.is_empty() or parent == null:
|
|
return null
|
|
var fx: Node3D = EffectPlayer.new()
|
|
fx.name = "fx_" + name.get_file().get_basename()
|
|
fx.one_shot = one_shot
|
|
fx.build(s, assets_root)
|
|
parent.add_child(fx)
|
|
fx.play(one_shot)
|
|
_track(fx, name)
|
|
return fx
|
|
|
|
func _track(fx: Node3D, name: String) -> void:
|
|
_next_fx_id += 1
|
|
var fx_id := _next_fx_id
|
|
var lifetime_ms: int = fx.defined_lifetime_ms
|
|
fx.tree_exiting.connect(_on_fx_exiting.bind(fx, name, fx_id, lifetime_ms, Time.get_ticks_msec()),
|
|
CONNECT_ONE_SHOT)
|
|
fx_spawned.emit(name, fx_id, lifetime_ms)
|
|
|
|
func _on_fx_exiting(fx: Node3D, name: String, fx_id: int, lifetime_ms: int, spawned_ms: int) -> void:
|
|
var reason := "removed"
|
|
if is_instance_valid(fx) and not String(fx.finish_reason).is_empty():
|
|
reason = fx.finish_reason
|
|
fx_finished.emit(name, fx_id, lifetime_ms, Time.get_ticks_msec() - spawned_ms, reason)
|
|
|
|
# 在世界某点播一次性
|
|
func spawn_at(name: String, world_parent: Node3D, global_pos: Vector3, one_shot := true) -> Node3D:
|
|
var fx := spawn(name, world_parent, one_shot)
|
|
if fx:
|
|
fx.global_position = global_pos
|
|
return fx
|
|
|
|
func spawn_motion(event: Dictionary, view: Node3D, world_parent: Node3D) -> Node3D:
|
|
var effect := spawn(String(event.get("effect", "")), world_parent, true)
|
|
if effect == null:
|
|
return null
|
|
var anchor := preload("res://fx/motion_effect_anchor.gd").new()
|
|
effect.add_child(anchor)
|
|
if not anchor.configure(view, event):
|
|
effect.free()
|
|
return null
|
|
return effect
|
|
|
|
func spawn_target(event: Dictionary, target: Node3D, world_parent: Node3D) -> Node3D:
|
|
if not is_instance_valid(target) or bool(event.get("fishing_effect", false)):
|
|
return null # Fishing requires its separate water landing position.
|
|
var effect := spawn(String(event.get("effect", "")), world_parent, true)
|
|
if effect == null: return null
|
|
var anchor := preload("res://fx/target_effect_anchor.gd").new()
|
|
effect.add_child(anchor)
|
|
if not anchor.configure(target, event.get("pos", Vector3.ZERO), bool(event.get("following", false))):
|
|
effect.free()
|
|
return null
|
|
return effect
|