#cache #assets #load #framework #source #loading #game

keeshond_datapack

A simple framework for loading and caching game assets

5 releases (breaking)

✓ Uses Rust 2018 edition

0.5.0 Nov 7, 2019
0.4.0 Jun 23, 2019
0.3.0 May 26, 2019
0.2.0 Apr 20, 2019
0.1.0 Apr 14, 2019
Download history 1/week @ 2019-07-24 14/week @ 2019-07-31 14/week @ 2019-08-07 42/week @ 2019-08-21 18/week @ 2019-08-28 18/week @ 2019-09-04 6/week @ 2019-09-11 73/week @ 2019-09-18 14/week @ 2019-09-25 9/week @ 2019-10-02 10/week @ 2019-10-16 25/week @ 2019-10-23 8/week @ 2019-10-30

76 downloads per month
Used in 1 crate

MIT/Apache

37KB
766 lines

🐶 KEESHOND Datapack 🐶

About

Keeshond Datapack lets you easily load resources for your game and cache them in memory, mapped via pathname and accessible by simple numeric ID lookup. 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.

Datapack is used by Keeshond but can work with any engine.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

keeshond_datapack lets you easily load resources for your game and cache them in memory, mapped via pathname and accessible by simple numeric ID lookup. 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.
  • Use [DataStore::load_package()] to ensure the package is loaded at start.
  • When creating objects that need resources, use [DataStore::get_id()] or [DataStore::get_id_mut()] to get a [DataId]. Store this id somewhere it can be used later, as these functions do involve a couple hash lookups.
  • When using a resource, use [DataStore::get()] or [DataStore::get_mut()] with your id to get a reference to it so you can use it.

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

Dependencies

~1.5MB
~30K SLoC