|
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
|
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 | |
| 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. | |
| enum class | SyncHandlerPolicy { OnSourceChange , Always } |
| When a sync handler runs during ProcessAsset. More... | |
Public Member Functions | |
| AssetPipeline () | |
| ~AssetPipeline () | |
| int | CleanCache () |
| Removes orphaned cache files. Returns how many were removed. | |
| bool | CompileAssetFile (const std::string &assetPath, const std::string &cachePath) |
| bool | CompileSceneFile (const std::string &scenePath, const std::string &binaryPath) |
| const AssetDependencyReporter * | FindDependencyReporter (const std::string &extension) const |
| The dependency reporter for an extension (any case, with dot), or null. | |
| const AssetExportEncoder * | FindExportEncoder (const std::string &extension) const |
| The encoder for an extension (lowercase, with dot), or null. | |
| std::string | GetAbsolutePath (const std::string &relativePath) const |
| const std::unordered_map< std::string, AssetInfo > & | GetAllAssets () const |
| Every discovered asset, keyed by project-relative path. | |
| 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 |
| const std::string & | GetAssetsPath () const |
| const AssetExportTarget & | GetEditorTarget () const |
| std::string | GetOrCreateAssetGuid (const std::string &relativePath) |
| The asset's GUID, creating its .data sidecar if needed. | |
| const std::string & | GetProjectPath () const |
| const SubAssetInfo * | GetSubAsset (const std::string &guid) const |
| The sub-asset with this GUID, or nullptr. | |
| const std::vector< SubAssetInfo > * | GetSubAssets (const std::string &parentGuid) const |
| The sub-assets of a parent asset, or nullptr when it has none. | |
| void | ImportAllAssets () |
| Imports every asset. Called when a project loads. | |
| 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). | |
| bool | IsRunning () const |
| 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. | |
| std::string | MakeProjectRelative (const std::string &absolutePath) const |
| An absolute path made project-relative, with forward slashes. | |
| 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 | RefreshAsset (const std::string &relativePath) |
| Reimports one asset and rebuilds its cache. | |
| void | RegisterCacheHandler (const std::string &extension, AssetCacheHandler handler) |
| Registers the cache handler for an extension (with dot, e.g. | |
| void | RegisterCacheVariantProvider (const std::string &extension, CacheVariantProvider provider) |
| Registers a cache-variant provider for an extension. | |
| void | RegisterDependencyReporter (const std::string &extension, AssetDependencyReporter reporter) |
| Registers what lists the assets an extension's assets use. | |
| void | RegisterExportEncoder (const std::string &extension, AssetExportEncoder encoder) |
| Registers the encoder that writes this extension's assets for a target. | |
| void | RegisterSceneExportCheck (const std::string &name, SceneExportCheck check) |
| Registers a check of the scenes a build ships, under a name of its own. | |
| void | RegisterSourceFilesReporter (const std::string &extension, AssetSourceFilesReporter reporter) |
| Registers what an asset type is compiled from besides its own file (AssetSourceFilesReporter). | |
| void | RegisterSubAssets (const std::string &parentGuid, const std::vector< SubAssetInfo > &subAssets) |
| Sets the sub-assets of a parent asset, for any asset type. | |
| void | RegisterSyncHandler (const std::string &extension, AssetSyncHandler handler, SyncHandlerPolicy policy=SyncHandlerPolicy::OnSourceChange) |
| Registers a sync handler for an extension (with dot, e.g. | |
| void | RemoveAsset (const std::string &relativePath) |
| Removes an asset from the index and the GuidCache. | |
| void | ResyncWithDisk () |
| Compares the assets with the disk and reprocesses what differs: new files, files changed since their cache was built, files that are gone. | |
| const std::unordered_map< std::string, SceneExportCheck > & | SceneExportChecks () const |
| void | SetDefaultCacheHandler (AssetCacheHandler handler) |
| The handler used for extensions that have none registered. | |
| 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. | |
| void | Start (const std::string &assetsPath, const std::string &projectPath) |
| Starts the pipeline on the absolute assets folder and project root. | |
| void | Stop () |
| void | Tick () |
| Takes pending file-watcher events and reprocesses the assets they name. | |
| 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. | |
Static Public Member Functions | |
| 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. | |
| static AssetPipeline * | Instance () |
| The running pipeline, or nullptr if none has started. | |
| static void | OnImportComplete (std::function< void(AssetPipeline *)> callback) |
| Calls callback after ImportAllAssets() finishes. | |
| static void | OnStarted (std::function< void(AssetPipeline *)> callback) |
| Calls callback when a pipeline starts, or right away if one is running. | |
Public Attributes | |
| std::function< void(const std::string &)> | onAssetChanged |
| std::function< void(const std::string &)> | onAssetCreated |
| std::function< void(const std::string &relativePath, const std::string &guid)> | onAssetDeleted |
| std::function< void(const std::string &)> | onAssetDiscovered |
| std::function< void()> | onImportAllFinished |
Static Public Attributes | |
| static AssetPipeline * | s_Instance |
| static std::vector< std::function< void(AssetPipeline *)> > | s_OnImportCompleteCallbacks |
| static std::vector< std::function< void(AssetPipeline *)> > | s_OnStartedCallbacks |
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 | ( | ) |
| int DekiEditor::AssetPipeline::CleanCache | ( | ) |
Removes orphaned cache files. Returns how many were removed.
|
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.
| bool DekiEditor::AssetPipeline::CompileAssetFile | ( | const std::string & | assetPath, |
| const std::string & | cachePath ) |
| bool DekiEditor::AssetPipeline::CompileSceneFile | ( | const std::string & | scenePath, |
| const std::string & | binaryPath ) |
| const AssetDependencyReporter * DekiEditor::AssetPipeline::FindDependencyReporter | ( | const std::string & | extension | ) | const |
The dependency reporter for an extension (any case, with dot), or null.
| const AssetExportEncoder * DekiEditor::AssetPipeline::FindExportEncoder | ( | const std::string & | extension | ) | const |
The encoder for an extension (lowercase, with dot), or null.
| std::string DekiEditor::AssetPipeline::GetAbsolutePath | ( | const std::string & | relativePath | ) | const |
|
inline |
Every discovered asset, keyed by project-relative path.
| 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 |
|
inline |
|
static |
The type name for an extension with dot (".scene" gives "Scene", ".png" gives "Sprite"), or "" when unknown.
|
inline |
| std::string DekiEditor::AssetPipeline::GetOrCreateAssetGuid | ( | const std::string & | relativePath | ) |
The asset's GUID, creating its .data sidecar if needed.
|
inline |
| const SubAssetInfo * DekiEditor::AssetPipeline::GetSubAsset | ( | const std::string & | guid | ) | const |
The sub-asset with this GUID, or nullptr.
| 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.
| void DekiEditor::AssetPipeline::ImportAllAssets | ( | ) |
Imports every asset. Called when a project loads.
|
static |
The running pipeline, or nullptr if none has started.
| 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).
|
inline |
| 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::string DekiEditor::AssetPipeline::MakeProjectRelative | ( | const std::string & | absolutePath | ) | const |
An absolute path made project-relative, with forward slashes.
|
static |
Calls callback after ImportAllAssets() finishes.
Use it for sub-assets that depend on cache state, such as baked font variants.
|
static |
Calls callback when a pipeline starts, or right away if one is running.
Packages use it to register their handlers at load.
| 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::RefreshAsset | ( | const std::string & | relativePath | ) |
Reimports one asset and rebuilds its cache.
| 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::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.
| void DekiEditor::AssetPipeline::RegisterDependencyReporter | ( | const std::string & | extension, |
| AssetDependencyReporter | reporter ) |
Registers what lists the assets an extension's assets use.
Cleared with the cache handlers when a package unloads.
| 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.
| void DekiEditor::AssetPipeline::RegisterSceneExportCheck | ( | const std::string & | name, |
| SceneExportCheck | check ) |
Registers a check of the scenes a build ships, under a name of its own.
Cleared with the cache handlers when a package unloads.
| void DekiEditor::AssetPipeline::RegisterSourceFilesReporter | ( | const std::string & | extension, |
| AssetSourceFilesReporter | reporter ) |
Registers what an asset type is compiled from besides its own file (AssetSourceFilesReporter).
Cleared with the cache handlers.
| 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.
| 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::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.
| void DekiEditor::AssetPipeline::ResyncWithDisk | ( | ) |
Compares the assets with the disk and reprocesses what differs: new files, files changed since their cache was built, files that are gone.
Fires the same callbacks as Tick. Tick calls it when the OS reports that it dropped change events.
|
inline |
| void DekiEditor::AssetPipeline::SetDefaultCacheHandler | ( | AssetCacheHandler | handler | ) |
The handler used for extensions that have none registered.
|
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.
| 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::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.
| 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.
| std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetChanged |
| std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetCreated |
| std::function<void(const std::string& relativePath, const std::string& guid)> DekiEditor::AssetPipeline::onAssetDeleted |
| std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetDiscovered |
| std::function<void()> DekiEditor::AssetPipeline::onImportAllFinished |
|
static |
|
static |
|
static |