vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::TerrainFile Namespace Reference

A terrain as bytes: the .terrain file the editor writes into a project, and the body of its cooked file. More...

Classes

struct  Names
 What a body names, in the order resolve() reads it back. More...

Functions

std::vector< uint8_t > encode (const TerrainAsset &terrain, const ResourceManager &resources)
 terrain's body: its grid, maps and plants, its handles as their assets' names.
bool decode (const uint8_t *bytes, size_t size, TerrainAsset &out, Names &names, std::string &error)
 Read a body back into out, its handles left empty and their names in names.
void resolve (TerrainAsset &terrain, const Names &names, const ResourceManager &resources)
 Give terrain the handles names names, from resources; a name it does not hold stays empty, and is warned of.
bool write (const std::filesystem::path &path, const TerrainAsset &terrain, const ResourceManager &resources)
 Write terrain to path as a .terrain file, through a temporary file.
bool readBody (const std::filesystem::path &path, std::vector< uint8_t > &body, std::string &error)
 The body of the .terrain file at path, its magic and version checked.

Variables

constexpr char MAGIC [4] = {'V', 'K', 'M', 'T'}
 The magic a .terrain file starts with, then VERSION.
constexpr uint32_t VERSION = 1
 The body's layout; readBody() refuses a file of another.
constexpr uint32_t MAX_NAME = 4096
 The longest name a body keeps.

Detailed Description

A terrain as bytes: the .terrain file the editor writes into a project, and the body of its cooked file.

Kept by name where the asset holds handles - its layers' materials, its plants' meshes and materials - and resolved again against a graph that holds them (resolve()). The file is the terrain's source: its cook copies the body, so what a project carries is what is drawn.

Function Documentation

◆ encode()

std::vector< uint8_t > Vkm::Engine::TerrainFile::encode ( const TerrainAsset & terrain,
const ResourceManager & resources )

terrain's body: its grid, maps and plants, its handles as their assets' names.

Parameters
terrainThe terrain.
resourcesNames its handles; a hidden or unnamed asset is kept as no name, and warned of.
Returns
The bytes.

◆ decode()

bool Vkm::Engine::TerrainFile::decode ( const uint8_t * bytes,
size_t size,
TerrainAsset & out,
Names & names,
std::string & error )

Read a body back into out, its handles left empty and their names in names.

Parameters
bytesWhat encode() wrote.
sizeHow many there are.
outFilled when the body is sound.
namesThe names it keeps.
errorWhy it is not, when it is not.
Returns
False for a body cut short, too long, or out of a terrain's bounds.

◆ resolve()

void Vkm::Engine::TerrainFile::resolve ( TerrainAsset & terrain,
const Names & names,
const ResourceManager & resources )

Give terrain the handles names names, from resources; a name it does not hold stays empty, and is warned of.

Parameters
terrainFilled by decode().
namesWhat decode() read.
resourcesHolds the materials and meshes named.

◆ write()

bool Vkm::Engine::TerrainFile::write ( const std::filesystem::path & path,
const TerrainAsset & terrain,
const ResourceManager & resources )

Write terrain to path as a .terrain file, through a temporary file.

Parameters
pathWhere.
terrainThe terrain.
resourcesNames its handles.
Returns
False, having logged, when it could not be written.

◆ readBody()

bool Vkm::Engine::TerrainFile::readBody ( const std::filesystem::path & path,
std::vector< uint8_t > & body,
std::string & error )

The body of the .terrain file at path, its magic and version checked.

Parameters
pathThe file.
bodyIts body.
errorWhy it could not be read.
Returns
False when it could not.