Feat/client audio via zenoh frame#307
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements a server-driven audio cue system, allowing the Elixir backend to trigger sound effects on the Rust client by including relative asset paths in Zenoh render frames. Key changes include new callbacks in the Elixir Content behavior, state management for pending audio cues in BulletHell3D, and updates to the Rust AssetLoader and NetworkRenderBridge to safely load and play these cues. Review feedback identifies a potential performance bottleneck due to synchronous file I/O within the audio thread's main loop and suggests an optimization in the frame reuse logic to avoid redundant cloning and clearing of audio data.
| } | ||
| AudioCommand::PlaySeFromRelativePath(ref path) => { | ||
| if let Some(audio) = &audio { | ||
| if let Some(bytes) = loader.load_bytes_relative_path(path) { |
| Ok(guard) => { | ||
| if let Some(frame) = guard.as_ref() { | ||
| return frame.clone(); | ||
| let mut f = frame.clone(); | ||
| f.audio_cues.clear(); | ||
| return f; | ||
| } |
There was a problem hiding this comment.
フレームの再利用パスにおいて、毎回 clone() した後に clear() を行っていますが、これでは再利用のたびに不要なクローンとクリアが繰り返されます。元の last_frame 自体を一度 clear() すれば、それ以降の再利用では無駄な処理を省けます。guard.as_mut() を使用してソース側の audio_cues をクリアするように変更することで、パフォーマンスを向上させることができます。
Ok(mut guard) => {
if let Some(frame) = guard.as_mut() {
frame.audio_cues.clear();
return frame.clone();
}
}
protoをrender_frameから分離。音キューはContentの任意コールバックで組み立て、描画コンポーネントはencodeのみ担当。