Lysa  0.0
Lysa 3D Engine
VirtualFS Class Reference

Detailed Description

Virtual file system helper used to resolve portable paths.

Public Member Functions

 VirtualFS (const VirtualFSConfiguration &config, const std::shared_ptr< vireo::Vireo > &vireo)
 
template<typename T >
void setResourcesPack (const std::filesystem::path &filePath) const
 
bool fileExists (const std::string &uri) const
 
void forEachDirectoryEntry (const std::string &uri, const std::function< void (DirectoryEntryType, const std::string &)> &callback, bool recursive=false) const
 
bool directoryExists (const std::string &uri) const
 
std::pair< std::shared_ptr< std::streambuf >, std::shared_ptr< std::istream > > openReadStream (const std::string &uri) const
 
std::ofstream openWriteStream (const std::string &uri) const
 
void loadBinaryData (const std::string &uri, std::vector< char > &out) const
 
std::string loadString (const std::string &uri) const
 
std::byte * loadImage (const std::string &uri, uint32 &width, uint32 &height, uint64 &size) const
 
void loadLuaScript (const std::string &scriptName, std::vector< char > &out) const
 
void loadShader (const std::string &shaderName, std::vector< char > &out) const
 
std::string getPath (const std::string &uri) const
 
constexpr const std::string & getLuaScriptsDirectory () const
 
constexpr std::string getLuaScriptsURI () const
 
constexpr std::string getLuaScriptURI (const std::string &scriptName) const
 
constexpr auto useResourcesPack () const
 

Static Public Member Functions

static std::string parentPath (const std::string &uri)
 
static void destroyImage (std::byte *image)
 
static std::string stripAppURI (const std::string &uri)
 
static std::string stripUserURI (const std::string &uri)
 
static std::string getCurrentDirectory ()
 

Static Public Attributes

static constexpr auto APP_URI {"app://"}
 
static constexpr auto USER_URI {"user://"}
 

Constructor & Destructor Documentation

VirtualFS ( const VirtualFSConfiguration config,
const std::shared_ptr< vireo::Vireo > &  vireo 
)

Member Function Documentation

static void destroyImage ( std::byte *  image)
static

Frees an image buffer allocated by loadImage().

Parameters
imagePointer previously returned by loadImage()
bool directoryExists ( const std::string &  uri) const

Tests whether a directory exists at the given path or URI.

Parameters
uriURI.
Returns
True if the file exists; false otherwise.
bool fileExists ( const std::string &  uri) const

Tests whether a regular file exists at the given path or URI.

Parameters
uriURI.
Returns
True if the file exists; false otherwise.
void forEachDirectoryEntry ( const std::string &  uri,
const std::function< void (DirectoryEntryType, const std::string &)> &  callback,
bool  recursive = false 
) const

Iterates over the entries of a directory, transparent pack/filesystem.

Parameters
uriDirectory URI.
callbackCalled for each entry with its type and its path relative to uri (a plain file name for the first level).
recursiveIf true, also traverses the sub-directories.
static std::string getCurrentDirectory ( )
static
constexpr const std::string& getLuaScriptsDirectory ( ) const
inlineconstexpr

Returns the configured Lua script directory

constexpr std::string getLuaScriptsURI ( ) const
inlineconstexpr

Returns the configured Lua script URI

constexpr std::string getLuaScriptURI ( const std::string &  scriptName) const
inlineconstexpr

Builds a Lua script URI from a script name

std::string getPath ( const std::string &  uri) const

Resolves a path or app:// URI to a concrete OS path.

Implementations may expand environment variables, normalize separators, and map app:// to the application data/assets directory.

void loadBinaryData ( const std::string &  uri,
std::vector< char > &  out 
) const

Loads the entire file contents into a byte buffer.

Parameters
uriURI.
outDestination buffer; its contents are replaced by the file bytes.
std::byte* loadImage ( const std::string &  uri,
uint32 width,
uint32 height,
uint64 size 
) const

Loads an image and returns an allocated RGBA (8‑bit per channel) buffer.

The caller owns the returned memory and must release it with destroyImage().

Parameters
uriURI.
widthOutput image width in pixels.
heightOutput image height in pixels.
sizeOutput total buffer size in bytes (width*height*4).
Returns
Pointer to the newly allocated pixel buffer in RGBA8888 format, or nullptr on failure.
void loadLuaScript ( const std::string &  scriptName,
std::vector< char > &  out 
) const

Loads a Lua script from the configured script directory

Parameters
scriptNameScript name without extension, relative to the script directory
outOutput buffer, its contents are replaced by the file bytes.
void loadShader ( const std::string &  shaderName,
std::vector< char > &  out 
) const

Loads a SPIR-V or DXIL shader from the configured shader directory

Parameters
shaderNameShader name without extension and without path
outOutput buffer, its contents are replaced by the file bytes.
std::string loadString ( const std::string &  uri) const
std::pair<std::shared_ptr<std::streambuf>, std::shared_ptr<std::istream> > openReadStream ( const std::string &  uri) const

Opens an input stream for reading a file, transparent pack/filesystem.

When a pack is active, returns a stream backed by a PackStreambuf (zero intermediate copy). When no pack is loaded, wraps the ifstream. Callers own the returned objects and must keep them alive together.

Parameters
uriapp:// URI.
Returns
pair<unique_ptr<streambuf>, unique_ptr<istream>> — streambuf must outlive the istream.
std::ofstream openWriteStream ( const std::string &  uri) const

Opens an output stream for writing the file at URI.

The returned stream is typically opened in binary mode and may create intermediate directories depending on platform support. Callers should check stream.is_open() (or its state) to ensure the file was successfully opened.

Parameters
uriURI.
Returns
std::ofstream positioned at the start of the file.
static std::string parentPath ( const std::string &  uri)
static

Returns the parent directory of the provided path or URI.

For app:// URIs, the parent is computed after resolution. Trailing separators are ignored.

Parameters
uriURI.
Returns
Parent directory path, or an empty string if none.
void setResourcesPack ( const std::filesystem::path &  filePath) const
inline
static std::string stripAppURI ( const std::string &  uri)
static

Removes the app:// prefix from an URI

static std::string stripUserURI ( const std::string &  uri)
static

Removes the user:// prefix from an URI

constexpr auto useResourcesPack ( ) const
inlineconstexpr

Returns true if the virtual FS use a binary resource pack instead of files

Member Data Documentation

constexpr auto APP_URI {"app://"}
staticconstexpr

URI scheme used to reference files relative to the application root.

constexpr auto USER_URI {"user://"}
staticconstexpr

URI scheme used to reference files in the platform-specific user data directory. Windows : %APPDATA%%\Lysa\userdata\[userDirectory] Linux : ~/.local/share/lysa/userdata/[userDirectory]