use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};1use serde::{Deserialize, Serialize};23bitflags::bitflags! {4/// Defines where the asset will be used.5///6/// If an asset is set to the `RENDER_WORLD` but not the `MAIN_WORLD`, the asset will be7/// unloaded from the asset server once it's been extracted and prepared in the render world.8///9/// Unloading the asset saves on memory, as for most cases it is no longer necessary to keep10/// it in RAM once it's been uploaded to the GPU's VRAM. However, this means you can no longer11/// access the asset from the CPU (via the `Assets<T>` resource) once unloaded (without re-loading it).12///13/// If you never need access to the asset from the CPU past the first frame it's loaded on,14/// or only need very infrequent access, then set this to `RENDER_WORLD`. Otherwise, set this to15/// `RENDER_WORLD | MAIN_WORLD`.16///17/// If you have an asset that doesn't actually need to end up in the render world, like an Image18/// that will be decoded into another Image asset, use `MAIN_WORLD` only.19///20/// ## Platform-specific21///22/// On Wasm, it is not possible for now to free reserved memory. To control memory usage, load assets23/// in sequence and unload one before loading the next. See this24/// [discussion about memory management](https://github.com/WebAssembly/design/issues/1397) for more25/// details.26#[repr(transparent)]27#[derive(Serialize, Deserialize, Hash, Clone, Copy, PartialEq, Eq, Debug, Reflect)]28#[reflect(opaque)]29#[reflect(Serialize, Deserialize, Hash, Clone, PartialEq, Debug)]30pub struct RenderAssetUsages: u8 {31/// The bit flag for the main world.32const MAIN_WORLD = 1 << 0;33/// The bit flag for the render world.34const RENDER_WORLD = 1 << 1;35}36}3738impl Default for RenderAssetUsages {39/// Returns the default render asset usage flags:40/// `RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD`41///42/// This default configuration ensures the asset persists in the main world, even after being prepared for rendering.43///44/// If your asset does not change, consider using `RenderAssetUsages::RENDER_WORLD` exclusively. This will cause45/// the asset to be unloaded from the main world once it has been prepared for rendering. If the asset does not need46/// to reach the render world at all, use `RenderAssetUsages::MAIN_WORLD` exclusively.47fn default() -> Self {48RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD49}50}515253