|
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
|
The asset import pipeline, like Unity's: finds assets, gives them GUIDs and compiles them into the cache. More...
#include <C:/Users/kirby/Documents/Github/deki/deki-editor/deki-editor/include/deki-editor/AssetPipeline.h>
Public Types | |
| enum class | SyncHandlerPolicy { OnSourceChange , Always } |
| When a sync handler runs during ProcessAsset. More... | |
| using | AssetSyncHandler |
| Called by ProcessAsset for a registered extension, with the asset's absolute path, its GUID and the absolute project root. | |
| using | CacheVariantProvider |
| Lists the derived cache files of a source asset. | |
Public Member Functions | |
| AssetPipeline () | |
| ~AssetPipeline () | |
| void | RegisterSyncHandler (const std::string &extension, AssetSyncHandler handler, SyncHandlerPolicy policy=SyncHandlerPolicy::OnSourceChange) |
| Registers a sync handler for an extension (with dot, e.g. | |
| void | RegisterCacheHandler (const std::string &extension, AssetCacheHandler handler) |
| Registers the cache handler for an extension (with dot, e.g. | |
| void | RegisterExportEncoder (const std::string &extension, AssetExportEncoder encoder) |
| Registers the encoder that writes this extension's assets for a target. | |
| const AssetExportEncoder * | FindExportEncoder (const std::string &extension) const |
| The encoder for an extension (lowercase, with dot), or null. | |
| void | SetEditorTarget (const AssetExportTarget &target) |
| Sets the target the editor's own cache is stored for: the project's active platform, set when a project opens and when the active platform changes. | |
| bool | IsRunning () const |
| const AssetExportTarget & | GetEditorTarget () const |
| void | SetDefaultCacheHandler (AssetCacheHandler handler) |
| The handler used for extensions that have none registered. | |
| void | RegisterCacheVariantProvider (const std::string &extension, CacheVariantProvider provider) |
| Registers a cache-variant provider for an extension. | |
| std::string | MakeProjectRelative (const std::string &absolutePath) const |
| An absolute path made project-relative, with forward slashes. | |
| void | Start (const std::string &assetsPath, const std::string &projectPath) |
| Starts the pipeline on the absolute assets folder and project root. | |
| void | Stop () |
| void | ImportAllAssets () |
| Imports every asset. Called when a project loads. | |
| void | Tick () |
| Takes pending file-watcher events and reprocesses the assets they name. | |
| const AssetInfo * | GetAssetInfo (const std::string &relativePath) const |
| Asset info by project-relative path, e.g. "assets/textures/player.png". | |
| const AssetInfo * | GetAssetInfoByGuid (const std::string &guid) const |
| bool | IsBdfFont (const std::string &sourceGuid) const |
| True when the font asset with this GUID is a BDF font, which has one baked form whatever the text's size (see BakedFontGuid). | |
| void | RefreshAsset (const std::string &relativePath) |
| Reimports one asset and rebuilds its cache. | |
| int | RecompileStaleScenes () |
| Recompiles every scene whose cache does not match the component types registered now (see MakeCacheStamp), or that has none: one that could not compile before its packages were built or loaded, or compiled before a component gained or lost a property. | |
| void | RemoveAsset (const std::string &relativePath) |
| Removes an asset from the index and the GuidCache. | |
| std::string | GetAbsolutePath (const std::string &relativePath) const |
| const std::string & | GetProjectPath () const |
| const std::string & | GetAssetsPath () const |
| const std::unordered_map< std::string, AssetInfo > & | GetAllAssets () const |
| Every discovered asset, keyed by project-relative path. | |
| std::string | GetOrCreateAssetGuid (const std::string &relativePath) |
| The asset's GUID, creating its .data sidecar if needed. | |
| int | CleanCache () |
| Removes orphaned cache files. Returns how many were removed. | |
| void | UpdateAssetTable () |
| Rewrites cache/asset_table.bin, the one table that resolves assets for play mode and ExportToStorage. | |
| void | ValidateCache () |
| Removes cache files that match no known asset. Called on project load. | |
| const std::vector< SubAssetInfo > * | GetSubAssets (const std::string &parentGuid) const |
| The sub-assets of a parent asset, or nullptr when it has none. | |
| const SubAssetInfo * | GetSubAsset (const std::string &guid) const |
| The sub-asset with this GUID, or nullptr. | |
| void | RegisterSubAssets (const std::string &parentGuid, const std::vector< SubAssetInfo > &subAssets) |
| Sets the sub-assets of a parent asset, for any asset type. | |
| bool | CompileSceneFile (const std::string &scenePath, const std::string &binaryPath) |
| bool | CompileAssetFile (const std::string &assetPath, const std::string &cachePath) |
| std::string | MakeCacheStamp (const std::string &absolutePath) const |
| What a cache built from this source now would be built from: the size and modification time of the source and its .data file, and the cache format version; for a scene, also the registered component types and their properties. | |
Static Public Member Functions | |
| static AssetPipeline * | Instance () |
| The running pipeline, or nullptr if none has started. | |
| static void | OnStarted (std::function< void(AssetPipeline *)> callback) |
| Calls callback when a pipeline starts, or right away if one is running. | |
| static void | OnImportComplete (std::function< void(AssetPipeline *)> callback) |
| Calls callback after ImportAllAssets() finishes. | |
| static void | ClearOnStartedCallbacks () |
| Clears all OnStarted callbacks and sync handlers. | |
| static std::string | GetAssetTypeFromExtension (const std::string &ext) |
| The type name for an extension with dot (".scene" gives "Scene", ".png" gives "Sprite"), or "" when unknown. | |
Public Attributes | |
| std::function< void(const std::string &)> | onAssetDiscovered |
| std::function< void(const std::string &)> | onAssetChanged |
| std::function< void(const std::string &relativePath, const std::string &guid)> | onAssetDeleted |
| std::function< void(const std::string &)> | onAssetCreated |
| std::function< void()> | onImportAllFinished |
Static Public Attributes | |
| static AssetPipeline * | s_Instance |
| static std::vector< std::function< void(AssetPipeline *)> > | s_OnStartedCallbacks |
| static std::vector< std::function< void(AssetPipeline *)> > | s_OnImportCompleteCallbacks |
The asset import pipeline, like Unity's: finds assets, gives them GUIDs and compiles them into the cache.
Called by ProcessAsset for a registered extension, with the asset's absolute path, its GUID and the absolute project root.
Lists the derived cache files of a source asset.
Some asset types make extra cache files (font baking writes one variant per size plus its atlases); the owning package names their GUIDs here so the orphan sweep keeps them.
Insert every derived GUID into outValidGuids. The pipeline already keeps the source asset's own GUID.
|
strong |
| DekiEditor::AssetPipeline::AssetPipeline | ( | ) |
| DekiEditor::AssetPipeline::~AssetPipeline | ( | ) |
|
static |
The running pipeline, or nullptr if none has started.
|
static |
Calls callback when a pipeline starts, or right away if one is running.
Packages use it to register their handlers at load.
|
static |
Calls callback after ImportAllAssets() finishes.
Use it for sub-assets that depend on cache state, such as baked font variants.
|
static |
Clears all OnStarted callbacks and sync handlers.
Must be called before unloading the package DLLs that registered them; after a reload the packages register again through DekiPluginRegisterComponents.
| void DekiEditor::AssetPipeline::RegisterSyncHandler | ( | const std::string & | extension, |
| AssetSyncHandler | handler, | ||
| SyncHandlerPolicy | policy = SyncHandlerPolicy::OnSourceChange ) |
Registers a sync handler for an extension (with dot, e.g.
".ttf"). It runs after an asset is processed by ImportAllAssets() or by Tick(), as policy allows. The default, OnSourceChange, keeps warm reopens fast.
| void DekiEditor::AssetPipeline::RegisterCacheHandler | ( | const std::string & | extension, |
| AssetCacheHandler | handler ) |
Registers the cache handler for an extension (with dot, e.g.
".png"). ProcessAsset calls it to write the cache files. Registering an extension that has a built-in handler replaces it.
| void DekiEditor::AssetPipeline::RegisterExportEncoder | ( | const std::string & | extension, |
| AssetExportEncoder | encoder ) |
Registers the encoder that writes this extension's assets for a target.
Cleared with the cache handlers when a package unloads.
| const AssetExportEncoder * DekiEditor::AssetPipeline::FindExportEncoder | ( | const std::string & | extension | ) | const |
The encoder for an extension (lowercase, with dot), or null.
|
inline |
Sets the target the editor's own cache is stored for: the project's active platform, set when a project opens and when the active platform changes.
Changing it re-imports what depends on it.
|
inline |
|
inline |
| void DekiEditor::AssetPipeline::SetDefaultCacheHandler | ( | AssetCacheHandler | handler | ) |
The handler used for extensions that have none registered.
| void DekiEditor::AssetPipeline::RegisterCacheVariantProvider | ( | const std::string & | extension, |
| CacheVariantProvider | provider ) |
Registers a cache-variant provider for an extension.
Consulted during cache cleanup and validation so derived files are not deleted as orphans.
| std::string DekiEditor::AssetPipeline::MakeProjectRelative | ( | const std::string & | absolutePath | ) | const |
An absolute path made project-relative, with forward slashes.
| void DekiEditor::AssetPipeline::Start | ( | const std::string & | assetsPath, |
| const std::string & | projectPath ) |
Starts the pipeline on the absolute assets folder and project root.
| void DekiEditor::AssetPipeline::Stop | ( | ) |
| void DekiEditor::AssetPipeline::ImportAllAssets | ( | ) |
Imports every asset. Called when a project loads.
| void DekiEditor::AssetPipeline::Tick | ( | ) |
Takes pending file-watcher events and reprocesses the assets they name.
Call once per frame from the editor main loop. Runs ProcessAsset and fires onAssetDiscovered / onAssetChanged / onAssetDeleted on the main thread, because subscribers touch GPU resources.
| const AssetInfo * DekiEditor::AssetPipeline::GetAssetInfo | ( | const std::string & | relativePath | ) | const |
Asset info by project-relative path, e.g. "assets/textures/player.png".
| const AssetInfo * DekiEditor::AssetPipeline::GetAssetInfoByGuid | ( | const std::string & | guid | ) | const |
| bool DekiEditor::AssetPipeline::IsBdfFont | ( | const std::string & | sourceGuid | ) | const |
True when the font asset with this GUID is a BDF font, which has one baked form whatever the text's size (see BakedFontGuid).
|
static |
The type name for an extension with dot (".scene" gives "Scene", ".png" gives "Sprite"), or "" when unknown.
| void DekiEditor::AssetPipeline::RefreshAsset | ( | const std::string & | relativePath | ) |
Reimports one asset and rebuilds its cache.
| int DekiEditor::AssetPipeline::RecompileStaleScenes | ( | ) |
Recompiles every scene whose cache does not match the component types registered now (see MakeCacheStamp), or that has none: one that could not compile before its packages were built or loaded, or compiled before a component gained or lost a property.
Returns how many it tried. Play mode calls it before it starts.
| void DekiEditor::AssetPipeline::RemoveAsset | ( | const std::string & | relativePath | ) |
Removes an asset from the index and the GuidCache.
When an asset moves or is renamed, call this with the old path before RefreshAsset.
| std::string DekiEditor::AssetPipeline::GetAbsolutePath | ( | const std::string & | relativePath | ) | const |
|
inline |
|
inline |
|
inline |
Every discovered asset, keyed by project-relative path.
| std::string DekiEditor::AssetPipeline::GetOrCreateAssetGuid | ( | const std::string & | relativePath | ) |
The asset's GUID, creating its .data sidecar if needed.
| int DekiEditor::AssetPipeline::CleanCache | ( | ) |
Removes orphaned cache files. Returns how many were removed.
| void DekiEditor::AssetPipeline::UpdateAssetTable | ( | ) |
Rewrites cache/asset_table.bin, the one table that resolves assets for play mode and ExportToStorage.
Called after ProcessAsset() and after asset deletions.
| void DekiEditor::AssetPipeline::ValidateCache | ( | ) |
Removes cache files that match no known asset. Called on project load.
| const std::vector< SubAssetInfo > * DekiEditor::AssetPipeline::GetSubAssets | ( | const std::string & | parentGuid | ) | const |
The sub-assets of a parent asset, or nullptr when it has none.
| const SubAssetInfo * DekiEditor::AssetPipeline::GetSubAsset | ( | const std::string & | guid | ) | const |
The sub-asset with this GUID, or nullptr.
| void DekiEditor::AssetPipeline::RegisterSubAssets | ( | const std::string & | parentGuid, |
| const std::vector< SubAssetInfo > & | subAssets ) |
Sets the sub-assets of a parent asset, for any asset type.
| bool DekiEditor::AssetPipeline::CompileSceneFile | ( | const std::string & | scenePath, |
| const std::string & | binaryPath ) |
| bool DekiEditor::AssetPipeline::CompileAssetFile | ( | const std::string & | assetPath, |
| const std::string & | cachePath ) |
| std::string DekiEditor::AssetPipeline::MakeCacheStamp | ( | const std::string & | absolutePath | ) | const |
What a cache built from this source now would be built from: the size and modification time of the source and its .data file, and the cache format version; for a scene, also the registered component types and their properties.
Compared for equality (not "is the source newer"), so a file restored from a backup or unzip with an older time, or a cache format change, still counts as changed. Also used for the per-target export cache.
| std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetDiscovered |
| std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetChanged |
| std::function<void(const std::string& relativePath, const std::string& guid)> DekiEditor::AssetPipeline::onAssetDeleted |
| std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetCreated |
| std::function<void()> DekiEditor::AssetPipeline::onImportAllFinished |
|
static |
|
static |
|
static |