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.
|
#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< Package > | 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: 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 | |
AssetManager * | manager |
Private Member Functions | |
std::optional< PackagePrototype > | LoadModPrototype (const std::string &) |
std::unique_ptr< cqsp::asset::Asset > | LoadText (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::Asset > | LoadTextDirectory (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::Asset > | LoadTexture (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::Asset > | LoadBinaryAsset (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::Asset > | LoadHjson (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::Asset > | LoadShader (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::Asset > | LoadFont (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::Asset > | LoadAudio (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::Asset > | LoadCubemap (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::Asset > | LoadModel (cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints) |
std::unique_ptr< ShaderDefinition > | LoadShaderDefinition (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< TextDirectoryAsset > | LoadScriptDirectory (VirtualMounter *mount, const std::string &path, const Hjson::Value &hints) |
Loads a script directory. More... | |
std::unique_ptr< cqsp::asset::Asset > | LoadAsset (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... | |
IVirtualFileSystem * | GetVfs (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< QueueHolder > | m_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, LoaderFunction > | loading_functions |
The list of functions that are loading. More... | |
VirtualMounter | mounter |
Friends | |
class | AssetManager |
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 |
cqsp::asset::AssetLoader::AssetLoader | ( | ) |
void cqsp::asset::AssetLoader::BuildNextAsset | ( | ) |
The assets that need to be on the main thread. Takes one asset from the queue and processes it
|
inline |
|
inline |
|
inline |
Gets the list of assets that were listed in the resource.hjson files, but were not found.
|
static |
Get where the mod.hjson file is.
|
private |
Creates a virtual file system starting in path
path |
|
private |
Defines a directory that contains hjson asset data.
package | |
path | |
name | |
mounter |
|
private |
Loads the asset specified in path
type | Type of asset to load |
path | Full virtual path of the asset |
key | Key of the asset to be loaded |
hints | Any hints to give to the loader |
|
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.
|
private |
Loads binary data straight from the file.
|
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:
This will not load the texture more or less than 6 textures are defined in the array.
|
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.
path | Path of directory to read |
file | Function pointer to do something with the path, and it takes the path of the asset as the parameter |
|
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.
|
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.
|
private |
|
private |
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.
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:
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.
package | Path to package folder |
|
private |
Loads all the resources defined in the hjson asset_value
in the hjson resource loading format.
package | Package to load into |
resource_mount_path | root path of the package |
resource_file_path | Resource file path |
asset_value | Hjson value to read from |
|
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:
|
private |
Loads a script directory.
path | |
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.
|
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:
For uniforms, the shader will read the types of uniforms in the shader, and use them.
Matrices are not supported yet
|
private |
Pretty straightforward, loads a text file into a string.
This has no hints
|
private |
Loads a directory of text files into a map of strings keyed by their relative path to the resource.hjson file.
|
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.
|
private |
|
private |
Conducts checks to determine if the asset was loaded correctly. Wraps Load asset, and contains the same parameters
package | Package to load into |
|
inline |
Checks if the queue has any remaining items to load on the main thread or not.
|
friend |
|
private |
All the assets that have already been loaded
|
private |
The list of functions that are loading.
|
private |
Queue for AssetPrototype when loading in frame.
AssetManager* cqsp::asset::AssetLoader::manager |
|
private |
|
private |
List of all assets that are missing
|
private |