DEKI/ENGINE docs
manual api reference
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
Loading...
Searching...
No Matches

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

Detailed Description

The asset import pipeline, like Unity's: finds assets, gives them GUIDs and compiles them into the cache.

Member Typedef Documentation

◆ AssetSyncHandler

Initial value:
std::function<void(const std::string& absolutePath, const std::string& guid, const std::string& projectPath)>

Called by ProcessAsset for a registered extension, with the asset's absolute path, its GUID and the absolute project root.

◆ CacheVariantProvider

Initial value:
std::function<void(const AssetInfo& info, std::unordered_set<std::string>& outValidGuids)>
A discovered asset.
Definition AssetPipeline.h:142

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.

Member Enumeration Documentation

◆ SyncHandlerPolicy

When a sync handler runs during ProcessAsset.

Enumerator
OnSourceChange 
Always 

Constructor & Destructor Documentation

◆ AssetPipeline()

DekiEditor::AssetPipeline::AssetPipeline ( )

◆ ~AssetPipeline()

DekiEditor::AssetPipeline::~AssetPipeline ( )

Member Function Documentation

◆ CleanCache()

int DekiEditor::AssetPipeline::CleanCache ( )

Removes orphaned cache files. Returns how many were removed.

◆ ClearOnStartedCallbacks()

void DekiEditor::AssetPipeline::ClearOnStartedCallbacks ( )
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.

◆ CompileAssetFile()

bool DekiEditor::AssetPipeline::CompileAssetFile ( const std::string & assetPath,
const std::string & cachePath )

◆ CompileSceneFile()

bool DekiEditor::AssetPipeline::CompileSceneFile ( const std::string & scenePath,
const std::string & binaryPath )

◆ FindDependencyReporter()

const AssetDependencyReporter * DekiEditor::AssetPipeline::FindDependencyReporter ( const std::string & extension) const

The dependency reporter for an extension (any case, with dot), or null.

◆ FindExportEncoder()

const AssetExportEncoder * DekiEditor::AssetPipeline::FindExportEncoder ( const std::string & extension) const

The encoder for an extension (lowercase, with dot), or null.

◆ GetAbsolutePath()

std::string DekiEditor::AssetPipeline::GetAbsolutePath ( const std::string & relativePath) const

◆ GetAllAssets()

const std::unordered_map< std::string, AssetInfo > & DekiEditor::AssetPipeline::GetAllAssets ( ) const
inline

Every discovered asset, keyed by project-relative path.

◆ GetAssetInfo()

const AssetInfo * DekiEditor::AssetPipeline::GetAssetInfo ( const std::string & relativePath) const

Asset info by project-relative path, e.g. "assets/textures/player.png".

◆ GetAssetInfoByGuid()

const AssetInfo * DekiEditor::AssetPipeline::GetAssetInfoByGuid ( const std::string & guid) const

◆ GetAssetsPath()

const std::string & DekiEditor::AssetPipeline::GetAssetsPath ( ) const
inline

◆ GetAssetTypeFromExtension()

std::string DekiEditor::AssetPipeline::GetAssetTypeFromExtension ( const std::string & ext)
static

The type name for an extension with dot (".scene" gives "Scene", ".png" gives "Sprite"), or "" when unknown.

◆ GetEditorTarget()

const AssetExportTarget & DekiEditor::AssetPipeline::GetEditorTarget ( ) const
inline

◆ GetOrCreateAssetGuid()

std::string DekiEditor::AssetPipeline::GetOrCreateAssetGuid ( const std::string & relativePath)

The asset's GUID, creating its .data sidecar if needed.

◆ GetProjectPath()

const std::string & DekiEditor::AssetPipeline::GetProjectPath ( ) const
inline

◆ GetSubAsset()

const SubAssetInfo * DekiEditor::AssetPipeline::GetSubAsset ( const std::string & guid) const

The sub-asset with this GUID, or nullptr.

◆ GetSubAssets()

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.

◆ ImportAllAssets()

void DekiEditor::AssetPipeline::ImportAllAssets ( )

Imports every asset. Called when a project loads.

◆ Instance()

AssetPipeline * DekiEditor::AssetPipeline::Instance ( )
static

The running pipeline, or nullptr if none has started.

◆ IsBdfFont()

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).

◆ IsRunning()

bool DekiEditor::AssetPipeline::IsRunning ( ) const
inline

◆ MakeCacheStamp()

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.

◆ MakeProjectRelative()

std::string DekiEditor::AssetPipeline::MakeProjectRelative ( const std::string & absolutePath) const

An absolute path made project-relative, with forward slashes.

◆ OnImportComplete()

void DekiEditor::AssetPipeline::OnImportComplete ( std::function< void(AssetPipeline *)> callback)
static

Calls callback after ImportAllAssets() finishes.

Use it for sub-assets that depend on cache state, such as baked font variants.

◆ OnStarted()

void DekiEditor::AssetPipeline::OnStarted ( std::function< void(AssetPipeline *)> callback)
static

Calls callback when a pipeline starts, or right away if one is running.

Packages use it to register their handlers at load.

◆ RecompileStaleScenes()

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.

◆ RefreshAsset()

void DekiEditor::AssetPipeline::RefreshAsset ( const std::string & relativePath)

Reimports one asset and rebuilds its cache.

◆ RegisterCacheHandler()

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.

◆ RegisterCacheVariantProvider()

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.

◆ RegisterDependencyReporter()

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.

◆ RegisterExportEncoder()

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.

◆ RegisterSceneExportCheck()

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.

◆ RegisterSourceFilesReporter()

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.

◆ RegisterSubAssets()

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.

◆ RegisterSyncHandler()

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.

◆ RemoveAsset()

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.

◆ ResyncWithDisk()

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.

◆ SceneExportChecks()

const std::unordered_map< std::string, SceneExportCheck > & DekiEditor::AssetPipeline::SceneExportChecks ( ) const
inline

◆ SetDefaultCacheHandler()

void DekiEditor::AssetPipeline::SetDefaultCacheHandler ( AssetCacheHandler handler)

The handler used for extensions that have none registered.

◆ SetEditorTarget()

void DekiEditor::AssetPipeline::SetEditorTarget ( const AssetExportTarget & target)
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.

◆ Start()

void DekiEditor::AssetPipeline::Start ( const std::string & assetsPath,
const std::string & projectPath )

Starts the pipeline on the absolute assets folder and project root.

◆ Stop()

void DekiEditor::AssetPipeline::Stop ( )

◆ Tick()

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.

◆ UpdateAssetTable()

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.

◆ ValidateCache()

void DekiEditor::AssetPipeline::ValidateCache ( )

Removes cache files that match no known asset. Called on project load.

Member Data Documentation

◆ onAssetChanged

std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetChanged

◆ onAssetCreated

std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetCreated

◆ onAssetDeleted

std::function<void(const std::string& relativePath, const std::string& guid)> DekiEditor::AssetPipeline::onAssetDeleted

◆ onAssetDiscovered

std::function<void(const std::string&)> DekiEditor::AssetPipeline::onAssetDiscovered

◆ onImportAllFinished

std::function<void()> DekiEditor::AssetPipeline::onImportAllFinished

◆ s_Instance

AssetPipeline* DekiEditor::AssetPipeline::s_Instance
static

◆ s_OnImportCompleteCallbacks

std::vector<std::function<void(AssetPipeline*)> > DekiEditor::AssetPipeline::s_OnImportCompleteCallbacks
static

◆ s_OnStartedCallbacks

std::vector<std::function<void(AssetPipeline*)> > DekiEditor::AssetPipeline::s_OnStartedCallbacks
static

The documentation for this class was generated from the following file: