Lysa  0.0
Lysa 3D Engine
ResourcesPack Class Reference

Detailed Description

Lysa resources pack binary file format containing all resources for a game, referred by app://

Classes

struct  Entry
 
struct  Header
 

Public Member Functions

 ResourcesPack (const std::filesystem::path &filePath)
 
virtual ~ResourcesPack () = default
 
bool contains (std::string_view relativePath) const
 
virtual void load (std::string_view relativePath, std::vector< char > &out) const
 
bool containsPrefix (std::string_view prefix) const
 
void forEachEntry (std::string_view directoryPath, const std::function< void (bool isDirectory, const std::string &relativePath)> &callback, bool recursive) const
 
virtual std::shared_ptr< ResourcesPackStreambufopenStream (std::string_view relativePath) const
 

Static Public Attributes

static constexpr char MAGIC [] { 'L','Y','P','A','C','K' }
 
static constexpr auto VERSION {1}
 
static constexpr size_t PATH_SIZE {256}
 

Protected Member Functions

const Entryfind (std::string_view relativePath) const
 

Protected Attributes

std::ifstream file
 
std::vector< Entrydirectory
 

Constructor & Destructor Documentation

ResourcesPack ( const std::filesystem::path &  filePath)

Opens and parses a pack file, loading its directory into memory. Automatically done in VirtualFS from the configuration.

virtual ~ResourcesPack ( )
virtualdefault

Member Function Documentation

bool contains ( std::string_view  relativePath) const

Checks whether the pack contains an entry for the given path.

Parameters
relativePathVirtual resource path (e.g. "shaders/pbr.vert").
Returns
true if an entry with that path exists, false otherwise.
bool containsPrefix ( std::string_view  prefix) const

Checks whether the directory contains any entry whose path starts with the given prefix.

Parameters
prefixPath prefix to search for.
Returns
true if at least one entry matches, false otherwise.
const Entry* find ( std::string_view  relativePath) const
protected
void forEachEntry ( std::string_view  directoryPath,
const std::function< void (bool isDirectory, const std::string &relativePath)> &  callback,
bool  recursive 
) const

Iterates over the entries located under a directory prefix.

Directories are implicit in the pack format: they are derived from the stored entry paths and each one is reported exactly once.

Parameters
directoryPathDirectory path inside the pack (empty string for the root).
callbackCalled for each entry with isDirectory and the path relative to directoryPath.
recursiveIf true, also reports the entries of the sub-directories.
virtual void load ( std::string_view  relativePath,
std::vector< char > &  out 
) const
virtual

Loads the raw bytes of a resource into a caller-supplied buffer.

The buffer is resized to fit the resource exactly before the data is copied into it.

Subclasses can override this to transform the loaded bytes (e.g. decryption).

virtual std::shared_ptr<ResourcesPackStreambuf> openStream ( std::string_view  relativePath) const
virtual

Creates a streaming buffer over a resource region without loading the entire resource into memory.

The returned ResourcesPackStreambuf can be wrapped in a std::istream to enable incremental, standard-library-compatible reading.

Parameters
relativePathVirtual resource path.
Returns
A shared pointer to the streambuf; the underlying file handle is owned by this ResourcesPack instance

Member Data Documentation

std::vector<Entry> directory
protected
std::ifstream file
mutableprotected
constexpr char MAGIC[] { 'L','Y','P','A','C','K' }
staticconstexpr
constexpr size_t PATH_SIZE {256}
staticconstexpr
constexpr auto VERSION {1}
staticconstexpr