Expand description
keeshond_datapack
lets you easily load resources for your game and cache them in memory,
mapped via pathname and accessible by handle objects. Define how they load
with the DataObject trait, by implementing a function that takes a Read + Seek object.
Define where they load from by instantiating a source::Source.
Datapack is used by Keeshond but can work with any engine.
§How to use
- Implement the DataObject trait for each type of object you want to be able to load in.
- Instantiate a source::SourceManager object and give it a source::Source such as a source::FilesystemSource
- Create a folder for each package on disk (if using FilesystemSource).
- Create subfolders within each package for each data type and place files within.
- Instantiate a DataStore for each data type you want to load.
- (Optional) use DataStore::load_package() to ensure the package is loaded at start.
- When creating objects that need resources, instantiate a DataHandle with a desired path.
- Resolve this path using a DataStore to access the data. Store this handle somewhere it can be used later, as resolving does involve a couple hash lookups.
Pathnames are of the form path/to/file.png
. They must match exactly, including the use of one
forward slash as a separator, and no separators at the beginning or end. The package name and
data type folders are not included (they are implied). Pathnames are also case-sensitive even on
platforms with case-insensitive filesystems (Windows, macOS).
Modules§
- source
- The
Source
trait and implementations.
Structs§
- Data
Handle - A path to a data resource, resolvable to a cached DataId.
- DataId
- A numeric ID used to refer to a DataObject of a specific type. Should only be used directly when performing operations that need an index into an array or Vec. This value may change between sessions. In most cases you probably want to use a DataHandle instead.
- Data
Multistore - Storage that allows lookup and access of DataObjects of multiple types by wrapping multiple DataStores.
- Data
Store - Storage that allows lookup and access of DataObjects of a given type
- Package
UseToken - A token that indicates that a package is in use and should not be automatically unloaded.
- Prepared
Store - An optional companion to a DataStore. If you have data that needs initialization with a backend (for example, textures you need to upload to a GPU), PreparedStore provides a way to handle this in a two-step process that is borrow-checker-friendly.
Enums§
- Data
Error - Return type when failing to load a DataObject from a DataStore
- Data
Store Ok - Return type when loading information from a DataStore
- Load
Error Mode - Behavior for when automatically loading a resource fails
- Prepared
Store Error - Return type for when PreparedStore operations fail
- Trust
Policy - Trust settings for a given DataObject resource type
Traits§
- Data
Object - Represents a data item loaded from a package. Implement this trait to allow the system to load new types of data.
- Data
Preparer - Used with PreparedStore, this allows the definition of behavior when initializing resources with a backend. See PreparedStore for more information.
- Read
Seek - A boxable trait that implements both Read and Seek, used by the source::Source types.