Files
esengine/packages/asset-system/src/interfaces/IAssetManager.ts

335 lines
6.3 KiB
TypeScript
Raw Normal View History

/**
* Asset manager interfaces
*
*/
import {
AssetGUID,
AssetHandle,
AssetType,
AssetState,
IAssetLoadOptions,
IAssetLoadResult,
IAssetReferenceInfo,
IAssetPreloadGroup,
IAssetLoadProgress
} from '../types/AssetTypes';
import { IAssetLoader } from './IAssetLoader';
/**
* Asset manager interface
*
*/
export interface IAssetManager {
/**
* Load asset by GUID
* GUID加载资产
*/
loadAsset<T = unknown>(
guid: AssetGUID,
options?: IAssetLoadOptions
): Promise<IAssetLoadResult<T>>;
/**
* Load asset by path
*
*/
loadAssetByPath<T = unknown>(
path: string,
options?: IAssetLoadOptions
): Promise<IAssetLoadResult<T>>;
/**
* Load multiple assets
*
*/
loadAssets(
guids: AssetGUID[],
options?: IAssetLoadOptions
): Promise<Map<AssetGUID, IAssetLoadResult>>;
/**
* Preload asset group
*
*/
preloadGroup(
group: IAssetPreloadGroup,
onProgress?: (progress: IAssetLoadProgress) => void
): Promise<void>;
/**
* Get loaded asset
*
*/
getAsset<T = unknown>(guid: AssetGUID): T | null;
/**
* Get asset by handle
*
*/
getAssetByHandle<T = unknown>(handle: AssetHandle): T | null;
/**
* Get loaded asset by path (synchronous)
*
*/
getAssetByPath<T = unknown>(path: string): T | null;
/**
* Check if asset is loaded
*
*/
isLoaded(guid: AssetGUID): boolean;
/**
* Get asset state
*
*/
getAssetState(guid: AssetGUID): AssetState;
/**
* Unload asset
*
*/
unloadAsset(guid: AssetGUID): void;
/**
* Unload all assets
*
*/
unloadAllAssets(): void;
/**
* Unload unused assets
* 使
*/
unloadUnusedAssets(): void;
/**
* Add reference to asset
*
*/
addReference(guid: AssetGUID): void;
/**
* Remove reference from asset
*
*/
removeReference(guid: AssetGUID): void;
/**
* Get reference info
*
*/
getReferenceInfo(guid: AssetGUID): IAssetReferenceInfo | null;
/**
* Register custom loader
*
*/
registerLoader(type: AssetType, loader: IAssetLoader): void;
/**
* Get asset statistics
*
*/
getStatistics(): {
loadedCount: number;
loadQueue: number;
failedCount: number;
};
/**
* Clear cache
*
*/
clearCache(): void;
/**
* Dispose manager
*
*/
dispose(): void;
}
/**
* Asset cache interface
*
*/
export interface IAssetCache {
/**
* Get cached asset
*
*/
get<T = unknown>(guid: AssetGUID): T | null;
/**
* Set cached asset
*
*/
set<T = unknown>(guid: AssetGUID, asset: T, size: number): void;
/**
* Check if asset is cached
*
*/
has(guid: AssetGUID): boolean;
/**
* Remove from cache
*
*/
remove(guid: AssetGUID): void;
/**
* Clear all cache
*
*/
clear(): void;
/**
* Get cache size
*
*/
getSize(): number;
/**
* Get cached asset count
*
*/
getCount(): number;
/**
* Evict assets based on policy
*
*/
evict(targetSize: number): void;
}
/**
* Asset loading queue interface
*
*/
export interface IAssetLoadQueue {
/**
* Add to queue
*
*/
enqueue(
guid: AssetGUID,
priority: number,
options?: IAssetLoadOptions
): void;
/**
* Remove from queue
*
*/
dequeue(): {
guid: AssetGUID;
options?: IAssetLoadOptions;
} | null;
/**
* Check if queue is empty
*
*/
isEmpty(): boolean;
/**
* Get queue size
*
*/
getSize(): number;
/**
* Clear queue
*
*/
clear(): void;
/**
* Reprioritize item
*
*/
reprioritize(guid: AssetGUID, newPriority: number): void;
}
/**
* Asset dependency resolver interface
*
*/
export interface IAssetDependencyResolver {
/**
* Resolve dependencies for asset
*
*/
resolveDependencies(guid: AssetGUID): Promise<AssetGUID[]>;
/**
* Get direct dependencies
*
*/
getDirectDependencies(guid: AssetGUID): AssetGUID[];
/**
* Get all dependencies recursively
*
*/
getAllDependencies(guid: AssetGUID): AssetGUID[];
/**
* Check for circular dependencies
*
*/
hasCircularDependency(guid: AssetGUID): boolean;
/**
* Build dependency graph
*
*/
buildDependencyGraph(guids: AssetGUID[]): Map<AssetGUID, AssetGUID[]>;
}
/**
* Asset streaming interface
*
*/
export interface IAssetStreaming {
/**
* Start streaming assets
*
*/
startStreaming(guids: AssetGUID[]): void;
/**
* Stop streaming
*
*/
stopStreaming(): void;
/**
* Pause streaming
*
*/
pauseStreaming(): void;
/**
* Resume streaming
*
*/
resumeStreaming(): void;
/**
* Set streaming budget per frame
*
*/
setFrameBudget(milliseconds: number): void;
/**
* Get streaming progress
*
*/
getProgress(): IAssetLoadProgress;
}