-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Allow adding and removing asset sources at runtime. #21890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
3be29fa to
5528a8c
Compare
greeble-dev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't spot any issues and tests passed. Just added some minor comments.
One thing I was left wondering about - do readers and writers still need to be passed to AssetSourceBuilder as closures that produce the value? I understand this was necessary when sources weren't shared. But is it true now that they're shared?
| pub enum DefaultAssetSource { | ||
| /// Create the default asset source given these file paths. | ||
| FromPaths { | ||
| /// The path to the unprocessed assets. | ||
| file_path: String, | ||
| /// The path to the processed assets. | ||
| /// | ||
| /// If [`None`], the default file path is used when in [`AssetMode::Processed`]. | ||
| processed_file_path: Option<String>, | ||
| }, | ||
| /// Create the default asset source from the provided builder. | ||
| /// | ||
| /// Note: The Mutex is just an implementation detail for applying the | ||
| /// plugin. | ||
| FromBuilder(Mutex<AssetSourceBuilder>), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could consider making this DefaultAssetSource::Paths/Builder and have a function DefaultAssetSource::from_paths/from_builder? Feels slightly nicer to me, but not a big deal, and using the struct directly does make it easier to plug in default values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! This is especially good for the builder path, so users don't need to deal with the Mutex.
| /// A bool indicating whether the processor has started or not. | ||
| /// | ||
| /// This is different from `state` since `state` is async, and we only assign to it once, so we | ||
| /// should ~never block on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// should ~never block on it. | |
| /// should never block on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expanded on this since it's possible to block on this.
ff10ef4 to
cbe4a10
Compare
… adding the AssetPlugin.
…ter the processor starts.
Co-authored-by: Greeble <[email protected]>
Co-authored-by: Greeble <[email protected]>
64e3aac to
b8059fa
Compare
b8059fa to
b980d56
Compare
Objective
Solution
AssetPlugininclude aDefaultAssetSourceenum to initialize the default source when adding theAssetPlugin.DefaultAssetSourceneeds to contain a Mutex, since we need to be able to use the builder, butPluginonly provides us with a shared reference in the plugin.RwLockaround the asset sources.One thing that is not addressed is the behavior after removing an asset source. This PR leaves it in a state where assets loaded from that asset source remain loaded. If you re-add the asset source, it does not reload the asset. But if the asset changes on the asset source, it should reload again. I'm kinda leaving it undefined since it's not clear what the correct behavior here should be anyway.
Testing