Unravel Engine C++ Reference
Loading...
Searching...
No Matches
thumbnail_invalidation.cpp
Go to the documentation of this file.
2
3#include "thumbnail_manager.h"
4
7#include <engine/ecs/prefab.h>
8
9#include <deque>
10#include <unordered_set>
11
12namespace unravel::asset_deps
13{
14
15namespace
16{
17
18//------------------------------------------------------------------------------
19// BFS over the dependency graph starting from `root`, regenerating the
20// thumbnail of every loaded transitive dependent. `root` itself is NOT
21// touched here — the caller decides whether to regen or remove it.
22//
23// `visited` must already contain `root` (so we don't re-visit it via a cycle)
24// and is populated with every UUID we touch — useful to the caller for the
25// prefab mass-invalidation pass.
26//------------------------------------------------------------------------------
27void walk_and_regen_dependents(asset_manager& am,
28 thumbnail_manager& tm,
29 const hpp::uuid& root,
30 std::unordered_set<hpp::uuid>& visited)
31{
32 std::deque<hpp::uuid> queue;
33 queue.push_back(root);
34
35 while(!queue.empty())
36 {
37 const auto current = queue.front();
38 queue.pop_front();
39
40 for(const auto& dep : find_loaded_dependents(am, current))
41 {
42 if(visited.insert(dep).second)
43 {
44 tm.regenerate_thumbnail(dep);
45 queue.push_back(dep);
46 }
47 }
48 }
49}
50
51//------------------------------------------------------------------------------
52// Conservative prefab fallback: mark every loaded prefab thumbnail we haven't
53// already touched. Used by both cascade entry points when the triggering
54// asset type can affect prefab visuals.
55//------------------------------------------------------------------------------
56void mass_invalidate_prefab_thumbnails(asset_manager& am,
57 thumbnail_manager& tm,
58 const std::unordered_set<hpp::uuid>& visited)
59{
60 am.for_each_asset<prefab>(
61 [&](const auto& kvp) -> void
62 {
63 const auto& handle = kvp.second;
64 const auto& uid = handle.uid();
65 if(uid.is_nil() || visited.count(uid) != 0)
66 {
67 return;
68 }
69 tm.regenerate_thumbnail(uid);
70 });
71}
72
73} // namespace
74
77 const hpp::uuid& changed,
78 bool mass_invalidate_prefabs)
79{
80 if(changed.is_nil())
81 {
82 return;
83 }
84
85 std::unordered_set<hpp::uuid> visited;
86 visited.insert(changed);
87 tm.regenerate_thumbnail(changed);
88
89 walk_and_regen_dependents(am, tm, changed, visited);
90
91 if(mass_invalidate_prefabs)
92 {
93 mass_invalidate_prefab_thumbnails(am, tm, visited);
94 }
95}
96
97// Note: `removed_uids` and `dependent_uids` are intentionally distinct sets:
98// the former gets thumbnails dropped, the latter regenerated.
99// NOLINTBEGIN(bugprone-easily-swappable-parameters)
102 const std::set<hpp::uuid>& removed_uids,
103 const std::set<hpp::uuid>& dependent_uids,
104 bool mass_invalidate_prefabs)
105// NOLINTEND(bugprone-easily-swappable-parameters)
106{
107 std::unordered_set<hpp::uuid> visited;
108
109 // Removed assets: drop their thumbnails entirely. They no longer exist, so
110 // a regen would be a wasted render against a missing asset.
111 for(const auto& uid : removed_uids)
112 {
113 if(uid.is_nil())
114 {
115 continue;
116 }
117 tm.remove_thumbnail(uid);
118 visited.insert(uid);
119 }
120
121 // Dependents are still loaded — refresh their thumbnails so the missing
122 // dependency is reflected (e.g. a material whose normal map was deleted
123 // will now render with an empty slot).
124 for(const auto& uid : dependent_uids)
125 {
126 if(uid.is_nil() || !visited.insert(uid).second)
127 {
128 continue;
129 }
130 tm.regenerate_thumbnail(uid);
131 }
132
133 if(mass_invalidate_prefabs)
134 {
135 mass_invalidate_prefab_thumbnails(am, tm, visited);
136 }
137}
138
139} // namespace unravel::asset_deps
Manages assets, including loading, unloading, and storage.
auto queue(seq_action action, const seq_scope_policy &scope_policy, hpp::source_location location) -> seq_id_t
Queues a new action.
Definition seq.cpp:14
void cascade_thumbnail_remove(asset_manager &am, thumbnail_manager &tm, const std::set< hpp::uuid > &removed_uids, const std::set< hpp::uuid > &dependent_uids, bool mass_invalidate_prefabs)
void cascade_thumbnail_regen(asset_manager &am, thumbnail_manager &tm, const hpp::uuid &changed, bool mass_invalidate_prefabs)
auto find_loaded_dependents(asset_manager &am, const hpp::uuid &uid) -> std::vector< hpp::uuid >
void remove_thumbnail(const hpp::uuid &uid)
void regenerate_thumbnail(const hpp::uuid &uid)
gfx::uniform_handle handle
Definition uniform.cpp:9