DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
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

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

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:101

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

◆ Instance()

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

The running pipeline, or nullptr if none has started.

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

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

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

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

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

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

◆ FindExportEncoder()

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

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

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

◆ IsRunning()

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

◆ GetEditorTarget()

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

◆ SetDefaultCacheHandler()

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

The handler used for extensions that have none registered.

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

◆ MakeProjectRelative()

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

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

◆ 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 ( )

◆ ImportAllAssets()

void DekiEditor::AssetPipeline::ImportAllAssets ( )

Imports every asset. Called when a project loads.

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

◆ 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

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

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

◆ RefreshAsset()

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

Reimports one asset and rebuilds its cache.

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

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

◆ GetAbsolutePath()

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

◆ GetProjectPath()

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

◆ GetAssetsPath()

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

◆ GetAllAssets()

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

Every discovered asset, keyed by project-relative path.

◆ GetOrCreateAssetGuid()

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

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

◆ CleanCache()

int DekiEditor::AssetPipeline::CleanCache ( )

Removes orphaned cache files. Returns how many were removed.

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

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

◆ GetSubAsset()

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

The sub-asset with this GUID, or nullptr.

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

◆ CompileSceneFile()

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

◆ CompileAssetFile()

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

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

Member Data Documentation

◆ onAssetDiscovered

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

◆ onAssetChanged

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

◆ onAssetDeleted

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

◆ onAssetCreated

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

◆ onImportAllFinished

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

◆ s_Instance

AssetPipeline* DekiEditor::AssetPipeline::s_Instance
static

◆ s_OnStartedCallbacks

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

◆ s_OnImportCompleteCallbacks

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

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