20#include <spdlog/spdlog.h>
73 std::lock_guard<std::mutex> lock(
mutex_);
74 queue_ = std::move(other.queue_);
79 unsigned long size()
const {
80 std::lock_guard<std::mutex> lock(
mutex_);
84 std::optional<T>
pop() {
85 std::lock_guard<std::mutex> lock(
mutex_);
95 std::lock_guard<std::mutex> lock(
mutex_);
110 template <
class T,
typename V>
115 return dynamic_cast<T*
>(
assets[asset].get());
119 bool HasAsset(
const std::string& asset);
126 std::map<std::string, std::unique_ptr<Asset>>
assets;
163 static_assert(std::is_base_of<Asset, T>::value,
"Class is not child of cqsp::asset::Asset");
164 std::size_t separation = key.find(
":");
166 std::string package_name =
"core";
167 if (separation != std::string::npos) {
168 package_name = key.substr(0, separation);
172 if (
packages.count(package_name) == 0) {
176 std::string pkg_key = key.substr(separation + 1, key.length());
177 auto&
package = packages[package_name];
180 if (!package->HasAsset(pkg_key)) {
182 if constexpr (std::is_same<T, asset::Texture>::value) {
188 T* ptr = package->GetAsset<T>(pkg_key);
189 if (ptr ==
nullptr) {
190 SPDLOG_WARN(
"Asset {} is wrong type", key);
213 std::map<std::string, std::unique_ptr<Package>>
packages;
259 std::unique_ptr<Package> LoadPackage(
const std::string& path);
264 void BuildNextAsset();
282 static std::string GetModFilePath();
292 const std::string& key,
const Hjson::Value& hints)>
296 std::optional<PackagePrototype> LoadModPrototype(
const std::string&);
304 const std::string& key,
const Hjson::Value& hints);
310 const std::string& key,
const Hjson::Value& hints);
318 const std::string& key,
const Hjson::Value& hints);
324 const std::string& key,
const Hjson::Value& hints);
338 const std::string& key,
const Hjson::Value& hints);
346 const std::string& key,
const Hjson::Value& hints);
356 const std::string& key,
const Hjson::Value& hints);
364 const std::string& key,
const Hjson::Value& hints);
390 const std::string& key,
const Hjson::Value& hints);
393 const std::string& key,
const Hjson::Value& hints);
418 const std::string& key,
const Hjson::Value& hints);
426 std::unique_ptr<TextDirectoryAsset> LoadScriptDirectory(
VirtualMounter* mount,
const std::string& path,
427 const Hjson::Value& hints);
437 std::unique_ptr<cqsp::asset::Asset> LoadAsset(
const AssetType& type,
const std::string& path,
438 const std::string& key,
const Hjson::Value& hints);
447 void PlaceAsset(
Package& package,
const AssetType& type,
const std::string& path,
const std::string& key,
448 const Hjson::Value& hints);
458 void LoadDirectory(
const std::string& path,
const std::function<
void(std::string)>&
file);
478 void LoadResources(
Package& package,
const std::string& path);
488 void LoadResourceHjsonFile(
Package& package,
const std::string& package_mount_path,
489 const std::string& resource_file_path,
const Hjson::Value& asset_value);
497 bool HjsonPrototypeDirectory(
Package& package,
const std::string& path,
const std::string& name);
Definition: assetmanager.h:218
std::map< AssetType, LoaderFunction > loading_functions
The list of functions that are loading.
Definition: assetmanager.h:526
ThreadsafeQueue< QueueHolder > m_asset_queue
Queue for AssetPrototype when loading in frame.
Definition: assetmanager.h:513
ShaderProgram_t MakeShader(const std::string &key)
VirtualMounter mounter
Definition: assetmanager.h:527
std::function< std::unique_ptr< Asset >(cqsp::asset::VirtualMounter *mount, const std::string &path, const std::string &key, const Hjson::Value &hints)> LoaderFunction
Definition: assetmanager.h:293
std::vector< std::string > missing_assets
List of all assets that are missing
Definition: assetmanager.h:509
std::atomic_int currentloading
All the assets that have already been loaded
Definition: assetmanager.h:521
std::atomic_int & getCurrentLoading()
Definition: assetmanager.h:285
std::vector< std::string > & GetMissingAssets()
Gets the list of assets that were listed in the resource.hjson files, but were not found.
Definition: assetmanager.h:276
std::atomic_int max_loading
Definition: assetmanager.h:516
AssetManager * manager
Definition: assetmanager.h:289
bool QueueHasItems()
Checks if the queue has any remaining items to load on the main thread or not.
Definition: assetmanager.h:270
std::atomic_int & getMaxLoading()
Definition: assetmanager.h:284
Definition: assetmanager.h:145
std::map< std::string, PackagePrototype > m_package_prototype_list
Definition: assetmanager.h:210
friend class AssetLoader
Definition: assetmanager.h:215
ShaderProgram_t MakeShader(const std::string &vert, const std::string &frag)
Definition: assetmanager.cpp:63
std::map< std::string, std::unique_ptr< Package > > packages
Definition: assetmanager.h:213
T * GetAsset(const std::string &key)
Gets an asset.
Definition: assetmanager.h:162
void ClearAssets()
Definition: assetmanager.cpp:132
void LoadDefaultTexture()
Definition: assetmanager.cpp:121
Package * GetPackage(const std::string &name)
Definition: assetmanager.h:200
asset::Texture empty_texture
Definition: assetmanager.h:214
void SaveModList()
Definition: assetmanager.cpp:134
int GetPackageCount()
Definition: assetmanager.h:202
auto begin()
Definition: assetmanager.h:204
auto end()
Definition: assetmanager.h:206
Definition: assetprototype.h:37
The main functionality for this is to read files, so writing to files will not really be supported.
Definition: vfs.h:42
Definition: assetmanager.h:103
auto end()
Definition: assetmanager.h:123
auto begin()
Definition: assetmanager.h:121
std::string author
Definition: assetmanager.h:108
void ClearAssets()
Definition: assetmanager.cpp:56
std::string version
Definition: assetmanager.h:106
std::string name
Definition: assetmanager.h:105
std::string title
Definition: assetmanager.h:107
T * GetAsset(const V asset)
Definition: assetmanager.h:111
std::map< std::string, std::unique_ptr< Asset > > assets
Definition: assetmanager.h:126
bool HasAsset(const char *asset)
Definition: assetmanager.cpp:53
Definition: assetmanager.h:134
std::string author
Definition: assetmanager.h:139
std::string name
Definition: assetmanager.h:136
std::string version
Definition: assetmanager.h:137
std::string path
Definition: assetmanager.h:140
std::string title
Definition: assetmanager.h:138
bool enabled
Definition: assetmanager.h:142
Definition: assetmanager.h:47
QueueHolder()
Definition: assetmanager.h:49
QueueHolder(AssetPrototype *type)
Definition: assetmanager.h:50
AssetPrototype * prototype
Definition: assetmanager.h:52
Definition: assetmanager.h:59
ThreadsafeQueue(const ThreadsafeQueue< T > &)=delete
void push(const T &item)
Definition: assetmanager.h:94
ThreadsafeQueue()=default
bool empty() const
Definition: assetmanager.h:65
std::optional< T > pop()
Definition: assetmanager.h:84
ThreadsafeQueue(ThreadsafeQueue< T > &&other)
Definition: assetmanager.h:72
unsigned long size() const
Definition: assetmanager.h:79
ThreadsafeQueue & operator=(const ThreadsafeQueue< T > &)=delete
virtual ~ThreadsafeQueue()
Definition: assetmanager.h:77
std::mutex mutex_
Definition: assetmanager.h:61
std::queue< T > queue_
Definition: assetmanager.h:60
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
#define ENGINE_LOG_ERROR(...)
Definition: enginelogger.h:31
AssetType
Definition: asset.h:31
std::shared_ptr< ShaderProgram > ShaderProgram_t
The preferred way of using a shader program.
Definition: shader.h:112
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: clientctx.h:21