Skip to content

Custom state#33

Merged
BillyDM merged 10 commits into
mainfrom
custom_state
Mar 15, 2025
Merged

Custom state#33
BillyDM merged 10 commits into
mainfrom
custom_state

Conversation

@BillyDM

@BillyDM BillyDM commented Mar 10, 2025

Copy link
Copy Markdown
Owner

No description provided.

@CorvusPrudens CorvusPrudens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I'd make a couple comments on the API, but they're just some small suggestions.

I've integrated this PR in bevy_seedling. Overall, I'm maybe the slightest touch worried that it's a little cumbersome to get the state, but I'm very happy that this encourages nodes to be POD. That takes the APIs I've written for the ECS from mostly correct to necessarily correct.

There are certainly ways to make sharing a node's state easy with this API if someone needs that, so I'd be content if it were merged as-is.

Comment thread crates/firewheel-nodes/src/stream/reader.rs
Comment thread crates/firewheel-nodes/src/stream/writer.rs
channel_config: ChannelConfig,
uses_events: bool,
call_update_method: bool,
custom_state: Option<Box<dyn Any>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super nitpicky, so take it for what it's worth, but could we possibly separate out the state from the info struct?

The reason I ask is that technically, a user could provide the state in both AudioNode::info and AudioNode::processor, although it seems like it's supposed to be constructed in the latter (correct me if I'm wrong).

@BillyDM BillyDM Mar 14, 2025

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same Option<Box<dyn Any>> object that is created in the AudioNodeInfo struct is what is passed to AudioNode::processor and AudioNode::update. The node is free to mutate these at any point, but generally nodes should construct it in AudioNodeInfo so that the state is immediately available to the user in FirewheelCtx::node_state.

Comment thread crates/firewheel-core/src/node.rs Outdated
Comment thread crates/firewheel-core/src/node.rs Outdated
@CorvusPrudens

Copy link
Copy Markdown
Contributor

Looks good to me -- my examples work, all tests pass, and I like the constructor argument consolidation.

@BillyDM BillyDM merged commit 8b3f078 into main Mar 15, 2025
@BillyDM BillyDM deleted the custom_state branch March 15, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants