Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
cqsp::asset::AssetLoader Class Reference

#include <assetmanager.h>

Public Types

typedef std::function< std::unique_ptr< Asset >(cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)> LoaderFunction
 

Public Member Functions

 AssetLoader ()
 
void LoadMods ()
 Checks for all the loaded mods, and loads the assets that the mod loads. More...
 
std::unique_ptr< PackageLoadPackage (const std::string &path)
 Loads a package.
A package contains a few things that it loads by default. First it loads the info.hjson file to check for all the metadata about the package. The metadata of the package looks like this: More...
 
void BuildNextAsset ()
 The assets that need to be on the main thread. Takes one asset from the queue and processes it More...
 
bool QueueHasItems ()
 Checks if the queue has any remaining items to load on the main thread or not. More...
 
std::vector< std::string > & GetMissingAssets ()
 Gets the list of assets that were listed in the resource.hjson files, but were not found. More...
 
std::atomic_int & getMaxLoading ()
 
std::atomic_int & getCurrentLoading ()
 

Static Public Member Functions

static std::string GetModFilePath ()
 Get where the mod.hjson file is. More...
 

Public Attributes

AssetManagermanager
 

Private Member Functions

std::optional< PackagePrototypeLoadModPrototype (const std::string &)
 
std::unique_ptr< cqsp::asset::AssetLoadText (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Pretty straightforward, loads a text file into a string. More...
 
std::unique_ptr< cqsp::asset::AssetLoadTextDirectory (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Loads a directory of text files into a map of strings keyed by their relative path to the resource.hjson file. More...
 
std::unique_ptr< cqsp::asset::AssetLoadTexture (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Textures have one hint, the magfilter hint. If it is present, and set to true, it will enable closest magfilter, which will make the texture look pixellated. If it is not present, then it will be linear mag. More...
 
std::unique_ptr< cqsp::asset::AssetLoadBinaryAsset (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Loads binary data straight from the file. More...
 
std::unique_ptr< cqsp::asset::AssetLoadHjson (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Hjson is rather flexible, it can load a single file or a directory, with just the same option. If the input path is a file, then it will load the hjson file into a Hjson::Value. If the input path is a directory, then it will load all the hjson files in the directory into a hjson value. This is for large amounts of data that would be better to be split up across files. The data in each file is assumed to be an array of objects, and so will load all the arrays of hjson objects in each of the hjson files into one hjson object. More...
 
std::unique_ptr< cqsp::asset::AssetLoadShader (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Shaders have one option, the type hint, to specify what type of shader it is. We have two so far, the frag option for a fragment shader, and vert for a vertex shader. We do not have support for compute and geometry shaders, but we may add support for that in the future. More...
 
std::unique_ptr< cqsp::asset::AssetLoadFont (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Just specify a .ttf file, and it will load it into an opengl texture font object. More...
 
std::unique_ptr< cqsp::asset::AssetLoadAudio (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Only ogg files are supported for now. More...
 
std::unique_ptr< cqsp::asset::AssetLoadCubemap (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Cubemaps are a special type of texture that make up the skybox. Although they are specified differently in the resource.hjson, they become textures when they are loaded. More...
 
std::unique_ptr< cqsp::asset::AssetLoadModel (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 
std::unique_ptr< ShaderDefinitionLoadShaderDefinition (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)
 A shader defintion is a way to simplify the creation of shader objects.
A shader definiton file is loaded in hjson, and follows this format: More...
 
std::unique_ptr< TextDirectoryAssetLoadScriptDirectory (VirtualMounter *mount, const std::string &path, const Hjson::Value &hints)
 Loads a script directory. More...
 
std::unique_ptr< cqsp::asset::AssetLoadAsset (const AssetType &type, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Loads the asset specified in path More...
 
ShaderProgram_t MakeShader (const std::string &key)
 
void PlaceAsset (Package &package, const AssetType &type, const std::string &path, const std::string &key, const Hjson::Value &hints)
 Conducts checks to determine if the asset was loaded correctly. Wraps Load asset, and contains the same parameters More...
 
void LoadDirectory (const std::string &path, const std::function< void(std::string)> &file)
 Loads any type of directory, and executes the function for every single file.
This is a helper function to add to calculate the number of assets loaded so far. More...
 
void LoadResources (Package &package, const std::string &path)
 Loads all the resource.hjson files in the specified directory. It will look recursively and find all the resource.hjson files to load.
resource.hjson files consist of a hjson object. This is the syntax: More...
 
void LoadResourceHjsonFile (Package &package, const std::string &package_mount_path, const std::string &resource_file_path, const Hjson::Value &asset_value)
 Loads all the resources defined in the hjson asset_value in the hjson resource loading format. More...
 
bool HjsonPrototypeDirectory (Package &package, const std::string &path, const std::string &name)
 Defines a directory that contains hjson asset data. More...
 
IVirtualFileSystemGetVfs (const std::string &path)
 Creates a virtual file system starting in path More...
 

Private Attributes

std::vector< std::string > missing_assets
 List of all assets that are missing More...
 
ThreadsafeQueue< QueueHolderm_asset_queue
 Queue for AssetPrototype when loading in frame. More...
 
std::atomic_int max_loading
 
std::atomic_int currentloading
 All the assets that have already been loaded More...
 
std::map< AssetType, LoaderFunctionloading_functions
 The list of functions that are loading. More...
 
VirtualMounter mounter
 

Friends

class AssetManager
 

Member Typedef Documentation

◆ LoaderFunction

typedef std::function<std::unique_ptr<Asset>(cqsp::asset::VirtualMounter* mount, const std::string& path, const std::string& key, const Hjson::Value& hints)> cqsp::asset::AssetLoader::LoaderFunction

Constructor & Destructor Documentation

◆ AssetLoader()

cqsp::asset::AssetLoader::AssetLoader ( )

Member Function Documentation

◆ BuildNextAsset()

void cqsp::asset::AssetLoader::BuildNextAsset ( )

The assets that need to be on the main thread. Takes one asset from the queue and processes it

◆ getCurrentLoading()

std::atomic_int & cqsp::asset::AssetLoader::getCurrentLoading ( )
inline

◆ getMaxLoading()

std::atomic_int & cqsp::asset::AssetLoader::getMaxLoading ( )
inline

◆ GetMissingAssets()

std::vector< std::string > & cqsp::asset::AssetLoader::GetMissingAssets ( )
inline

Gets the list of assets that were listed in the resource.hjson files, but were not found.

Returns

◆ GetModFilePath()

std::string cqsp::asset::AssetLoader::GetModFilePath ( )
static

Get where the mod.hjson file is.

Returns

◆ GetVfs()

IVirtualFileSystem * cqsp::asset::AssetLoader::GetVfs ( const std::string &  path)
private

Creates a virtual file system starting in path

Parameters
path
Returns

◆ HjsonPrototypeDirectory()

bool cqsp::asset::AssetLoader::HjsonPrototypeDirectory ( Package package,
const std::string &  path,
const std::string &  name 
)
private

Defines a directory that contains hjson asset data.

Parameters
package
path
name
mounter

◆ LoadAsset()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadAsset ( const AssetType type,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Loads the asset specified in path

Parameters
typeType of asset to load
pathFull virtual path of the asset
keyKey of the asset to be loaded
hintsAny hints to give to the loader
Returns

◆ LoadAudio()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadAudio ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Only ogg files are supported for now.

If you're looking to add a music file, do not add it by the 'normal' way. This is for performance reasons. Go to binaries/data/core/music/readme.txt for further reading.

◆ LoadBinaryAsset()

std::unique_ptr< cqsp::asset::Asset > cqsp::asset::AssetLoader::LoadBinaryAsset ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Loads binary data straight from the file.

◆ LoadCubemap()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadCubemap ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Cubemaps are a special type of texture that make up the skybox. Although they are specified differently in the resource.hjson, they become textures when they are loaded.

They consist of 6 textures. When loading it, you have to specify a hjson file that links the files of the asset. The syntax of the hjson file will be a simple array of strings, specifing the relative paths relative to that hjson file. You will have 6 images, specifying the left, right, top, bottom, back, and front images respectively in that order.

Example:

[
left.png // The top left texture
right.png // You get the gist
top.png
bottom.png
back.png
front.png // In total there will have 6 textures.
]

This will not load the texture more or less than 6 textures are defined in the array.

◆ LoadDirectory()

void cqsp::asset::AssetLoader::LoadDirectory ( const std::string &  path,
const std::function< void(std::string)> &  file 
)
private

Loads any type of directory, and executes the function for every single file.
This is a helper function to add to calculate the number of assets loaded so far.

Parameters
pathPath of directory to read
fileFunction pointer to do something with the path, and it takes the path of the asset as the parameter

◆ LoadFont()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadFont ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Just specify a .ttf file, and it will load it into an opengl texture font object.

This is for opengl rendering.

Because each UI library has their differing implementation of fonts, to add fonts to the UI, do not use a resource.hjson. You need to go to binaries/data/core/gfx/fonts.hjson to alter and add fonts for the UI.

◆ LoadHjson()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadHjson ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Hjson is rather flexible, it can load a single file or a directory, with just the same option. If the input path is a file, then it will load the hjson file into a Hjson::Value. If the input path is a directory, then it will load all the hjson files in the directory into a hjson value. This is for large amounts of data that would be better to be split up across files. The data in each file is assumed to be an array of objects, and so will load all the arrays of hjson objects in each of the hjson files into one hjson object.

If it refers to directory, and a file that is loaded is not in a hjson array, it will not load that specific file, but it will not fail.

◆ LoadModel()

std::unique_ptr< cqsp::asset::Asset > cqsp::asset::AssetLoader::LoadModel ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

◆ LoadModPrototype()

std::optional< PackagePrototype > cqsp::asset::AssetLoader::LoadModPrototype ( const std::string &  path_string)
private

◆ LoadMods()

void cqsp::asset::AssetLoader::LoadMods ( )

Checks for all the loaded mods, and loads the assets that the mod loads.

It loads first, then loads the mod metadata, then it loads the mods that it needs to load.

◆ LoadPackage()

std::unique_ptr< Package > cqsp::asset::AssetLoader::LoadPackage ( const std::string &  path)

Loads a package.
A package contains a few things that it loads by default. First it loads the info.hjson file to check for all the metadata about the package. The metadata of the package looks like this:

{
name: # Namespace name of the package. Since packages are loaded with a colon, please refrain from
# adding colons in the package name
version: # Version of the package
title: # What you want to call the package
author: # Who wrote the package
# Other information can go here, like contacts and other things, but we won't care about it so far
dependencies: []
}

After that, it will load a couple of important folders.
The base script file, scripts/base.lua, will be loaded into the asset name base as a text file. Next it loads the script folder, scripts/ into a TextDirectoryAsset pointer, to the asset scripts
Then, it loads the goods and recipes as hjson, with the names goods and recipes respectively.
Finally, it recursively loads all the resource.hjson files in the folders. It is not reccomended to override the preloaded resources, but it is possible. If you really want to do so, it is strongly reccomended to keep type of asset the same for the key.

Parameters
packagePath to package folder
Returns
The uniqueptr to the package that is created

◆ LoadResourceHjsonFile()

void cqsp::asset::AssetLoader::LoadResourceHjsonFile ( Package package,
const std::string &  package_mount_path,
const std::string &  resource_file_path,
const Hjson::Value &  asset_value 
)
private

Loads all the resources defined in the hjson asset_value in the hjson resource loading format.

Parameters
packagePackage to load into
resource_mount_pathroot path of the package
resource_file_pathResource file path
asset_valueHjson value to read from

◆ LoadResources()

void cqsp::asset::AssetLoader::LoadResources ( Package package,
const std::string &  path 
)
private

Loads all the resource.hjson files in the specified directory. It will look recursively and find all the resource.hjson files to load.
resource.hjson files consist of a hjson object. This is the syntax:

{
test_asset: { # Asset key
path: # Path relative to the current resource.hjson file.
type: # Type of asset: &lt;none|texture|shader|hjson|text|model|font|cubemap|directory|audio&rt;
hints: {} # Object of whatever information you want when loading the asset.
}
// .. more assets can be specified, as long as they have a different key
}
lib tracy file(GLOB_RECURSE CPP_FILES *.cpp) list(FILTER CPP_FILES EXCLUDE REGEX ".*main.cpp$") file(GLOB_RECURSE H_FILES *.h) set(SOURCE_FILES $
Definition: CMakeLists.txt:22


◆ LoadScriptDirectory()

std::unique_ptr< TextDirectoryAsset > cqsp::asset::AssetLoader::LoadScriptDirectory ( VirtualMounter mount,
const std::string &  path,
const Hjson::Value &  hints 
)
private

Loads a script directory.

Parameters
path
hints
Returns

◆ LoadShader()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadShader ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Shaders have one option, the type hint, to specify what type of shader it is. We have two so far, the frag option for a fragment shader, and vert for a vertex shader. We do not have support for compute and geometry shaders, but we may add support for that in the future.

◆ LoadShaderDefinition()

std::unique_ptr< ShaderDefinition > cqsp::asset::AssetLoader::LoadShaderDefinition ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

A shader defintion is a way to simplify the creation of shader objects.
A shader definiton file is loaded in hjson, and follows this format:

{
vert: (vertex shader name)
frag: (fragment shader name)
uniforms: {
test_vec3: [1, 3, 5]
test_float: 19.5
test_int: 15
test_texture_name: (texture id)
}
}

For uniforms, the shader will read the types of uniforms in the shader, and use them.

Matrices are not supported yet

See also
cqsp::asset::ShaderDefinition for a most up to date version

◆ LoadText()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadText ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Pretty straightforward, loads a text file into a string.

This has no hints

◆ LoadTextDirectory()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadTextDirectory ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Loads a directory of text files into a map of strings keyed by their relative path to the resource.hjson file.

◆ LoadTexture()

std::unique_ptr< Asset > cqsp::asset::AssetLoader::LoadTexture ( cqsp::asset::VirtualMounter mount,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Textures have one hint, the magfilter hint. If it is present, and set to true, it will enable closest magfilter, which will make the texture look pixellated. If it is not present, then it will be linear mag.

◆ MakeShader()

ShaderProgram_t cqsp::asset::AssetLoader::MakeShader ( const std::string &  key)
private

◆ PlaceAsset()

void cqsp::asset::AssetLoader::PlaceAsset ( Package package,
const AssetType type,
const std::string &  path,
const std::string &  key,
const Hjson::Value &  hints 
)
private

Conducts checks to determine if the asset was loaded correctly. Wraps Load asset, and contains the same parameters

Parameters
packagePackage to load into

◆ QueueHasItems()

bool cqsp::asset::AssetLoader::QueueHasItems ( )
inline

Checks if the queue has any remaining items to load on the main thread or not.

Returns

Friends And Related Function Documentation

◆ AssetManager

friend class AssetManager
friend

Member Data Documentation

◆ currentloading

std::atomic_int cqsp::asset::AssetLoader::currentloading
private

All the assets that have already been loaded

◆ loading_functions

std::map<AssetType, LoaderFunction> cqsp::asset::AssetLoader::loading_functions
private

The list of functions that are loading.

See also
LoadScriptDirectory LoadCubemap LoadAudio LoadText LoadTexture LoadHjson LoadShader LoadFont

◆ m_asset_queue

ThreadsafeQueue<QueueHolder> cqsp::asset::AssetLoader::m_asset_queue
private

Queue for AssetPrototype when loading in frame.

◆ manager

AssetManager* cqsp::asset::AssetLoader::manager

◆ max_loading

std::atomic_int cqsp::asset::AssetLoader::max_loading
private

◆ missing_assets

std::vector<std::string> cqsp::asset::AssetLoader::missing_assets
private

List of all assets that are missing

◆ mounter

VirtualMounter cqsp::asset::AssetLoader::mounter
private

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