Module crayon::res

source ·
Expand description

The ResourceSystem provides standardized interface to load data asynchronously from various filesystem, and some utilities for modules to implement their own local resource management.

To understand how to properly manage data in crayon, its important to understand how crayon identifies and serializes data. The first key point is the distinction between _asset_s and _resource_s.

Asset

An asset is a file on disk, such like textures, 3D models, or audio clips. Since assets might be be modified by artiest continuous, its usually stored in formats which could producing and editing by authoring tools directly. Its always trival and error-prone to load and managet assets directly at runtime.

Resource

A resource is a abstraction of some piece of data that are fully prepared for using at runtime. We are providing a command line tool crayon-cli that automatically compiles assets into resources for runtime.

UUID

An asset can produces multiple resources eventually. For example, FBX file can have multiple models, and it can also contains a spatial description of objects. For every resource that an asset might produces, a universal-uniqued id (UUID) is assigned to it. UUIDs are stored in .meta files. These .meta files are generated when crayon-cli first imports an asset, and are stored in the same directory as the asset.

Virtual Filesystem (VFS)

The ResourceSystem allows load data asynchronously from web servers, the local host filesystem, or other places if extended by pluggable VFS.

The VFS trait has a pretty simple interface, since it should focus on games that load data asynchronously. A trival Directory is provided to supports local host filesystem. And it should be easy to add features like compression and encrpytion.

Manifest

Every VFS should have a Manifest file which could be used to locate resources in actual path from general UUID or readable identifier. The Manifest file is generated after the build process of crayon-cli.

Modules

Manifest for all the AssetBundles in the build.
A asynchronous loading request.
Central registry for shortcut definitions. Shortcuts are path aliases that could be resolved into full path.
Uniqued resource location.

Structs

Functions

Checks if the resource exists in this registry.
Return the UUID of resource located at provided path, and return None if not exists.
Loads file asynchronously. This method will returns a Request object immediatedly, its user’s responsibility to store the object and frequently check it for completion.
Loads file asynchronously. This method will returns a Request object immediatedly, its user’s responsibility to store the object and frequently check it for completion.
Loads file asynchronously with response callback.
Loads file asynchronously with response callback.
Resolve shortcuts in the provided string recursively and return None if not exists.
Checks if the resource system is enabled.