Deki 1.3.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches

Asset pipeline service - handles GUID creation, caching, and asset discovery. More...

#include <AssetPipeline.h>

Public Types

enum class  SyncHandlerPolicy { OnSourceChange , Always }
 When should a registered sync handler fire on ProcessAsset? More...
using AssetSyncHandler
 Asset sync handler callback type Called during ProcessAsset for registered extensions.
using CacheVariantProvider
 Cache-variant provider callback type.

Public Member Functions

 AssetPipeline ()
 ~AssetPipeline ()
void RegisterSyncHandler (const std::string &extension, AssetSyncHandler handler, SyncHandlerPolicy policy=SyncHandlerPolicy::OnSourceChange)
 Register a sync handler for a file extension Handlers are called after an asset is processed during ImportAllAssets() or a watcher-driven Tick(), subject to the supplied policy.
void RegisterCacheHandler (const std::string &extension, AssetCacheHandler handler)
 Register a cache handler for a file extension.
void SetDefaultCacheHandler (AssetCacheHandler handler)
 Set the default cache handler for extensions without a specific handler.
void RegisterCacheVariantProvider (const std::string &extension, CacheVariantProvider provider)
 Register a cache-variant provider for a file extension.
std::string MakeProjectRelative (const std::string &absolutePath) const
 Convert an absolute path to a project-relative path.
void Start (const std::string &assetsPath, const std::string &projectPath)
 Start the pipeline.
void Stop ()
 Stop the pipeline.
void ImportAllAssets ()
 Import all assets (called on project load).
void Tick ()
 Drain pending file-watcher events and reprocess affected assets.
const AssetInfoGetAssetInfo (const std::string &relativePath) const
 Get asset info by project-relative path.
const AssetInfoGetAssetInfoByGuid (const std::string &guid) const
 Get asset info by GUID.
void RefreshAsset (const std::string &relativePath)
 Refresh a specific asset (reimport and regenerate cache).
void RemoveAsset (const std::string &relativePath)
 Remove an asset from the pipeline index and GuidCache.
std::string GetAbsolutePath (const std::string &relativePath) const
 Get absolute path from project-relative path.
const std::string & GetProjectPath () const
 Get project path.
const std::string & GetAssetsPath () const
const std::unordered_map< std::string, AssetInfo > & GetAllAssets () const
 Get all discovered assets.
std::string GetOrCreateAssetGuid (const std::string &relativePath)
 Get or create GUID for an asset (creates .data sidecar file).
int CleanCache ()
 Clean cache - remove orphaned cache files.
void UpdateAssetTable ()
 Update the persistent asset lookup table (cache/asset_table.bin).
void ValidateCache ()
 Validate cache integrity and remove orphaned files.
const std::vector< SubAssetInfo > * GetSubAssets (const std::string &parentGuid) const
 Get all sub-assets for a parent asset.
const SubAssetInfoGetSubAsset (const std::string &guid) const
 Get sub-asset info by GUID.
void RegisterSubAssets (const std::string &parentGuid, const std::vector< SubAssetInfo > &subAssets)
 Register sub-assets for a parent asset (generic for all asset types).
bool CompileSceneFile (const std::string &scenePath, const std::string &binaryPath)
bool CompileAssetFile (const std::string &assetPath, const std::string &cachePath)

Static Public Member Functions

static AssetPipelineInstance ()
 Get the current active pipeline instance.
static void OnStarted (std::function< void(AssetPipeline *)> callback)
 Register a callback to be invoked when a pipeline starts If a pipeline is already active, callback is invoked immediately.
static void OnImportComplete (std::function< void(AssetPipeline *)> callback)
 Register a callback for when all assets have been imported.
static void ClearOnStartedCallbacks ()
 Clear all OnStarted callbacks and sync handlers.
static std::string GetAssetTypeFromExtension (const std::string &ext)
 Get asset type name from file extension.

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

Detailed Description

Asset pipeline service - handles GUID creation, caching, and asset discovery.

Unity-like asset import pipeline. Discovers assets, assigns GUIDs, and compiles to cache format.

Member Typedef Documentation

◆ AssetSyncHandler

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

Asset sync handler callback type Called during ProcessAsset for registered extensions.

Parameters
absolutePathAbsolute path to the asset file
guidAsset's GUID
projectPathAbsolute path to the project root

◆ CacheVariantProvider

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

Cache-variant provider callback type.

For asset types that produce derived cache files (e.g. font baking emits one variant per requested size + atlas siblings), the owning package declares which derived GUIDs belong to a given source asset. The pipeline consults registered providers when sweeping orphaned cache files so still- needed variants are not deleted.

The provider should insert all derived GUIDs into outValidGuids. The source asset's own GUID is already kept by the pipeline — providers only need to enumerate variants.

Member Enumeration Documentation

◆ SyncHandlerPolicy

When should a registered sync handler fire on ProcessAsset?

Enumerator
OnSourceChange 
Always 

Constructor & Destructor Documentation

◆ AssetPipeline()

DekiEditor::AssetPipeline::AssetPipeline ( )

◆ ~AssetPipeline()

DekiEditor::AssetPipeline::~AssetPipeline ( )

Member Function Documentation

◆ Instance()

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

Get the current active pipeline instance.

Returns
Pointer to the active pipeline, or nullptr if not started

◆ OnStarted()

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

Register a callback to be invoked when a pipeline starts If a pipeline is already active, callback is invoked immediately.

Use this to register sync handlers from package initialization code.

Parameters
callbackFunction to call with the pipeline pointer

◆ OnImportComplete()

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

Register a callback for when all assets have been imported.

Called after ImportAllAssets() finishes. Use this to register sub-assets that depend on cache state (e.g., baked font variants).

Parameters
callbackFunction to call with the pipeline pointer

◆ ClearOnStartedCallbacks()

void DekiEditor::AssetPipeline::ClearOnStartedCallbacks ( )
static

Clear all OnStarted callbacks and sync handlers.

Must be called BEFORE unloading package DLLs that registered callbacks. After reload, packages will re-register via DekiPlugin_RegisterComponents.

◆ RegisterSyncHandler()

void DekiEditor::AssetPipeline::RegisterSyncHandler ( const std::string & extension,
AssetSyncHandler handler,
SyncHandlerPolicy policy = SyncHandlerPolicy::OnSourceChange )

Register a sync handler for a file extension Handlers are called after an asset is processed during ImportAllAssets() or a watcher-driven Tick(), subject to the supplied policy.

Default is OnSourceChange so warm reopens are fast.

Parameters
extensionFile extension including dot (e.g., ".ttf")
handlerCallback to invoke for assets with this extension
policyWhen the handler should fire (default: OnSourceChange)

◆ RegisterCacheHandler()

void DekiEditor::AssetPipeline::RegisterCacheHandler ( const std::string & extension,
AssetCacheHandler handler )

Register a cache handler for a file extension.

Cache handlers are called during ProcessAsset to generate cache files. Packages can override built-in handlers by registering for the same extension.

Parameters
extensionFile extension including dot (e.g., ".png")
handlerCallback to invoke for assets with this extension

◆ SetDefaultCacheHandler()

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

Set the default cache handler for extensions without a specific handler.

Parameters
handlerFallback handler called for unregistered extensions

◆ RegisterCacheVariantProvider()

void DekiEditor::AssetPipeline::RegisterCacheVariantProvider ( const std::string & extension,
CacheVariantProvider provider )

Register a cache-variant provider for a file extension.

Called during cache cleanup / validation. Packages that produce derived cache files (font sizes, etc.) register here so the pipeline doesn't delete their variants as orphans.

◆ MakeProjectRelative()

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

Convert an absolute path to a project-relative path.

Parameters
absolutePathAbsolute filesystem path
Returns
Project-relative path with forward slashes

◆ Start()

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

Start the pipeline.

Parameters
assetsPathAbsolute path to assets directory
projectPathAbsolute path to project root

◆ Stop()

void DekiEditor::AssetPipeline::Stop ( )

Stop the pipeline.

◆ ImportAllAssets()

void DekiEditor::AssetPipeline::ImportAllAssets ( )

Import all assets (called on project load).

◆ Tick()

void DekiEditor::AssetPipeline::Tick ( )

Drain pending file-watcher events and reprocess affected assets.

Call once per frame from the editor main loop. Coalesced events delivered by AssetFileWatcher (Added / Modified / Deleted) drive ProcessAsset and fire OnAssetDiscovered / OnAssetChanged / OnAssetDeleted on the main thread (downstream subscribers touch GPU resources, so this must not run on the watcher's worker thread).

◆ GetAssetInfo()

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

Get asset info by project-relative path.

Parameters
relativePathe.g., "assets/textures/player.png"

◆ GetAssetInfoByGuid()

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

Get asset info by GUID.

◆ GetAssetTypeFromExtension()

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

Get asset type name from file extension.

Parameters
extFile extension including dot (e.g., ".scene", ".png")
Returns
Type name (e.g., "Scene", "Sprite") or empty string for unknown

◆ RefreshAsset()

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

Refresh a specific asset (reimport and regenerate cache).

Parameters
relativePathProject-relative path

◆ RemoveAsset()

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

Remove an asset from the pipeline index and GuidCache.

Call before RefreshAsset when an asset has been moved/renamed.

Parameters
relativePathProject-relative path of the OLD location

◆ GetAbsolutePath()

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

Get absolute path from project-relative path.

◆ GetProjectPath()

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

Get project path.

◆ GetAssetsPath()

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

◆ GetAllAssets()

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

Get all discovered assets.

◆ GetOrCreateAssetGuid()

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

Get or create GUID for an asset (creates .data sidecar file).

Parameters
relativePathProject-relative path

◆ CleanCache()

int DekiEditor::AssetPipeline::CleanCache ( )

Clean cache - remove orphaned cache files.

Returns
Number of files removed

◆ UpdateAssetTable()

void DekiEditor::AssetPipeline::UpdateAssetTable ( )

Update the persistent asset lookup table (cache/asset_table.bin).

This maintains cache/asset_table.bin as the single source of truth for asset resolution. Called automatically after ProcessAsset() and asset deletions. PlayMode and ExportToStorage both use this table directly.

◆ ValidateCache()

void DekiEditor::AssetPipeline::ValidateCache ( )

Validate cache integrity and remove orphaned files.

Called on project load to ensure cache is consistent with source assets. Removes any cache files that don't correspond to known assets.

◆ GetSubAssets()

const std::vector< SubAssetInfo > * DekiEditor::AssetPipeline::GetSubAssets ( const std::string & parentGuid) const

Get all sub-assets for a parent asset.

Parameters
parentGuidParent asset's GUID
Returns
Pointer to vector of sub-assets, or nullptr if parent has no sub-assets

◆ GetSubAsset()

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

Get sub-asset info by GUID.

Parameters
guidSub-asset GUID
Returns
Pointer to SubAssetInfo or nullptr

◆ RegisterSubAssets()

void DekiEditor::AssetPipeline::RegisterSubAssets ( const std::string & parentGuid,
const std::vector< SubAssetInfo > & subAssets )

Register sub-assets for a parent asset (generic for all asset types).

Parameters
parentGuidParent asset's GUID
subAssetsVector of sub-asset information

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

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

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