Skip to content
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

Refactor process_handle_drop_internal() in bevy_asset #10920

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 44 additions & 35 deletions crates/bevy_asset/src/server/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,46 +562,55 @@ impl AssetInfos {
watching_for_changes: bool,
id: UntypedAssetId,
) -> bool {
match infos.entry(id) {
Entry::Occupied(mut entry) => {
if entry.get_mut().handle_drops_to_skip > 0 {
entry.get_mut().handle_drops_to_skip -= 1;
false
} else {
let info = entry.remove();
if let Some(path) = info.path {
if watching_for_changes {
for loader_dependency in info.loader_dependencies.keys() {
if let Some(dependants) =
loader_dependants.get_mut(loader_dependency)
{
dependants.remove(&path);
}
}
if let Some(label) = path.label() {
let mut without_label = path.to_owned();
without_label.remove_label();
if let Entry::Occupied(mut entry) =
living_labeled_assets.entry(without_label)
{
entry.get_mut().remove(label);
if entry.get().is_empty() {
entry.remove();
}
};
}
}
path_to_id.remove(&path);
}
true
}
}
let mut entry = match infos.entry(id) {
Entry::Occupied(entry) => entry,
// Either the asset was already dropped, it doesn't exist, or it isn't managed by the asset server
// None of these cases should result in a removal from the Assets collection
Entry::Vacant(_) => false,
Entry::Vacant(_) => return false,
};
matiqo15 marked this conversation as resolved.
Show resolved Hide resolved

if entry.get_mut().handle_drops_to_skip > 0 {
entry.get_mut().handle_drops_to_skip -= 1;
return false;
}

let info = entry.remove();
let Some(path) = info.path else {
return true;
};

if !watching_for_changes {
path_to_id.remove(&path);
return true;
}

for loader_dependency in info.loader_dependencies.keys() {
if let Some(dependants) = loader_dependants.get_mut(loader_dependency) {
dependants.remove(&path);
}
}

let Some(label) = path.label() else {
path_to_id.remove(&path);
return true;
};

let mut without_label = path.to_owned();
without_label.remove_label();

if let Entry::Occupied(mut entry) = living_labeled_assets.entry(without_label) {
entry.get_mut().remove(label);
if entry.get().is_empty() {
entry.remove();
}
};
path_to_id.remove(&path);
true
}

// Either the asset was already dropped, it doesn't exist, or it isn't managed by the asset server
// None of these cases should result in a removal from the Assets collection

matiqo15 marked this conversation as resolved.
Show resolved Hide resolved
/// Consumes all current handle drop events. This will update information in [`AssetInfos`], but it
/// will not affect [`Assets`] storages. For normal use cases, prefer `Assets::track_assets()`
/// This should only be called if `Assets` storage isn't being used (such as in [`AssetProcessor`](crate::processor::AssetProcessor))
Expand Down