vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::AssetLibrary Class Reference

In-memory view of the on-disk asset database manifest. More...

#include <asset_library.h>

Public Types

enum class  Truth { Recipes , Manifest }
 Which file says an asset exists, as load() reads a project. More...

Public Member Functions

void load (Truth truth)
 (Re)load the library from disk, replacing current state.
const AssetRecord * find (AssetType type, const std::string &name) const
 Resolve (type, name) to its record, or nullptr if absent.
std::vector< std::string > namesOf (AssetType type) const
 Every registered asset name of type, sorted.
void upsert (AssetRecord record)
 Record record, replacing any record for its (type, name).
void remove (AssetType type, const std::string &name)
 Forget the record for (type, name), in memory until save().
bool save () const
 Write the manifest, every record in key order.
size_t removeUnrecordedCooked () const
 Delete every file in a kind's cooked directory that no record names.

Static Public Member Functions

static std::filesystem::path recipePath (AssetType type, const std::string &name)
 Absolute path to the recipe file of (type, name).
static std::filesystem::path cookedPath (AssetType type, const std::string &name, uint64_t recipeHash)
 Absolute path to the cooked binary of (type, name).
static bool readRecipe (AssetType type, const std::string &name, nlohmann::json &outSource)
 Read the source object out of the recipe file for (type, name).
static bool writeRecipe (AssetType type, const std::string &name, const nlohmann::json &source)
 Write source as the recipe file for (type, name).

Detailed Description

In-memory view of the on-disk asset database manifest.

The manifest (ProjectPaths::assetManifest()) holds every asset's identity (type + name) and recipe hash; scene asset references resolve through it. File locations derive from the identity: recipePath() / cookedPath() use an opaque UID (a content hash of type+name), since a raw asset name may contain path separators or colons.

Member Enumeration Documentation

◆ Truth

Which file says an asset exists, as load() reads a project.

A project's recipes; in a package, which ships only materials' recipes, the manifest.

Enumerator
Recipes 

A host that imports and cooks: a row whose recipe is gone is dropped.

Manifest 

A host that reads only cooked assets: every row stands.

Member Function Documentation

◆ load()

void Vkm::Engine::AssetLibrary::load ( Truth truth)

(Re)load the library from disk, replacing current state.

A recipe with no manifest row is adopted with no cook recorded; under Truth::Recipes a row whose recipe is gone is dropped. A missing manifest is not an error, and one in an unknown layout version is read as missing: re-cooking is cheaper than guessing.

Parameters
truthWhich file says an asset exists, for the host loading it.

◆ find()

const AssetRecord * Vkm::Engine::AssetLibrary::find ( AssetType type,
const std::string & name ) const

Resolve (type, name) to its record, or nullptr if absent.

Parameters
typeAsset type half of the lookup key.
nameAsset name half of the lookup key.
Returns
The matching record, or nullptr.

◆ namesOf()

std::vector< std::string > Vkm::Engine::AssetLibrary::namesOf ( AssetType type) const

Every registered asset name of type, sorted.

Sorted so a selection is reproducible across processes; the backing store is unordered.

Parameters
typeAsset type to enumerate.
Returns
Sorted names; empty if the type has no registered records.

◆ recipePath()

std::filesystem::path Vkm::Engine::AssetLibrary::recipePath ( AssetType type,
const std::string & name )
static

Absolute path to the recipe file of (type, name).

Derived from the identity, so writer and readers cannot disagree about where it is.

Parameters
typeAsset type half of the identity.
nameAsset name half of the identity.
Returns
A path under the project library dir.

◆ cookedPath()

std::filesystem::path Vkm::Engine::AssetLibrary::cookedPath ( AssetType type,
const std::string & name,
uint64_t recipeHash )
static

Absolute path to the cooked binary of (type, name).

Nothing is written here for a Material, whose recipe is its canonical form. The cache key is part of the name, so an artifact baked from a since-changed recipe is not stale, just never asked for.

Parameters
typeAsset type half of the subject's identity.
nameAsset name half of the subject's identity.
recipeHashThe recorded recipe hash (AssetRecord::recipeHash); AssetCook::cacheKey mixes in the kind and the cooker version here, so no caller can name a file without them.
Returns
A path under the project cooked dir.

◆ readRecipe()

bool Vkm::Engine::AssetLibrary::readRecipe ( AssetType type,
const std::string & name,
nlohmann::json & outSource )
static

Read the source object out of the recipe file for (type, name).

A material's recipe is its runtime form; any other kind's is the import to re-run when the cooked cache cannot serve it.

Parameters
typeAsset type half of the identity.
nameAsset name half of the identity.
outSourceReceives the recipe; untouched on failure.
Returns
False, having logged, when the file is missing, malformed or has no source.

◆ writeRecipe()

bool Vkm::Engine::AssetLibrary::writeRecipe ( AssetType type,
const std::string & name,
const nlohmann::json & source )
staticnodiscard

Write source as the recipe file for (type, name).

Written to a temporary and renamed over the file: a cook cannot regenerate a recipe, and one truncated in place would be recorded current and refused by every later load.

Parameters
typeAsset type half of the identity.
nameAsset name half of the identity.
sourceThe recipe the asset was imported or built from.
Returns
False, having logged, when the file could not be written.

◆ upsert()

void Vkm::Engine::AssetLibrary::upsert ( AssetRecord record)

Record record, replacing any record for its (type, name).

In memory until save().

Parameters
recordIdentity and what it was cooked from.

◆ remove()

void Vkm::Engine::AssetLibrary::remove ( AssetType type,
const std::string & name )

Forget the record for (type, name), in memory until save().

Parameters
typeAsset type half of the identity.
nameAsset name half of the identity.

◆ save()

bool Vkm::Engine::AssetLibrary::save ( ) const
nodiscard

Write the manifest, every record in key order.

Returns
False, having logged, when the file could not be written.

◆ removeUnrecordedCooked()

size_t Vkm::Engine::AssetLibrary::removeUnrecordedCooked ( ) const

Delete every file in a kind's cooked directory that no record names.

Catches what no record can name: files under an older COOKER_VERSION, and temporaries of a killed cook. Only for the host that is the one cooking into the project: an editor baking in the background lands artifacts this manifest may not record yet.

Returns
How many files were deleted.

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