Unravel Engine C++ Reference
Loading...
Searching...
No Matches
asset_dependency_graph.h
Go to the documentation of this file.
1#pragma once
2#include <engine/engine_export.h>
3
4#include <uuid/uuid.h>
5
6#include <vector>
7
8namespace unravel
9{
10class asset_manager;
11class material;
12class mesh;
13
14namespace asset_deps
15{
16
17//------------------------------------------------------------------------------
18// Forward-dependency enumeration.
19//
20// Returns the UUIDs that the given asset directly references. Designed as a
21// set of type-overloaded free functions (rather than a class virtual or a
22// template) so that:
23//
24// 1. Each asset type stays free of "I know about the dep graph" coupling.
25// 2. The same signatures can be reused later when migrating to a persistent
26// forward-dependency list stored at compile time (e.g. on asset_meta or
27// asset_manifest). At that point we'd populate the list once during
28// compilation by calling these same functions on the fully-loaded asset.
29//
30// All functions skip nil UUIDs so the result never contains a "this slot is
31// empty" marker.
32//------------------------------------------------------------------------------
33ENGINE_EXPORT auto get_referenced_uids(const material& m) -> std::vector<hpp::uuid>;
34ENGINE_EXPORT auto get_referenced_uids(const mesh& m) -> std::vector<hpp::uuid>;
35
36//------------------------------------------------------------------------------
37// Reverse-dependency lookup over the currently-loaded asset set.
38//
39// Walks every renderable-asset container registered with `am` (materials,
40// meshes) and returns the UUIDs of those whose `get_referenced_uids`
41// contains `uid`.
42//
43// Note: `model` is intentionally absent — it isn't a top-level asset_manager
44// storage type, it lives inside model_component on prefabs/scenes. Prefab
45// thumbnails are handled separately via the mass-invalidation path in
46// `cascade_thumbnail_regen`.
47//
48// This intentionally inspects only assets that are *already in memory*
49// (`asset_handle::peek()` — no forced loads, no deferred-task submission).
50// Unloaded dependents are correctly handled by the editor's lazy thumbnail
51// regeneration: they'll re-render against the new dependency content the next
52// time their thumbnail is requested.
53//
54// Cost: O(N_loaded × N_deps_per_asset). N is bounded by what the editor
55// actually has open, so this is cheap in practice.
56//------------------------------------------------------------------------------
57ENGINE_EXPORT auto find_loaded_dependents(asset_manager& am,
58 const hpp::uuid& uid) -> std::vector<hpp::uuid>;
59
60//------------------------------------------------------------------------------
61// Same as `find_loaded_dependents` but follows the chain transitively: returns
62// every loaded asset that depends on `root` directly *or* indirectly (a mesh
63// that uses a material that uses the changed texture, etc.).
64//
65// Use this when the dependency chain is about to be torn down (e.g. before
66// `asset_manager::unload_asset`) — the moment an asset is unloaded its
67// `asset_link_t` is cleared, and any other handle that shared the same link
68// will report a nil UUID, making post-unload enumeration miss them.
69//
70// The result excludes `root` itself.
71//------------------------------------------------------------------------------
72ENGINE_EXPORT auto find_transitive_loaded_dependents(asset_manager& am,
73 const hpp::uuid& root)
74 -> std::vector<hpp::uuid>;
75
76} // namespace asset_deps
77} // namespace unravel
auto find_transitive_loaded_dependents(asset_manager &am, const hpp::uuid &root) -> std::vector< hpp::uuid >
auto find_loaded_dependents(asset_manager &am, const hpp::uuid &uid) -> std::vector< hpp::uuid >
auto get_referenced_uids(const material &m) -> std::vector< hpp::uuid >