5#include <entt/entt.hpp>
6#include <unordered_map>
52 explicit AssetBase(
bool initializeDefaultEntity =
false) :
120 if (
data != entt::null)
140 template <
typename Key,
typename AssetClass>
155 template <
typename... Args>
165 void add(Key path, AssetClass* asset);
203 std::optional<AssetClass*>
getAsset(
const Key& path);
221 template<
typename Func>
223 for (
const auto& [key, asset] :
assets) {
224 if (asset !=
nullptr) {
231 std::unordered_map<Key, AssetClass*>
assets;
234 template<
typename Key,
typename AssetClass>
235 template<
typename... Args>
237 assets[path] =
new AssetClass(std::forward<Args>(args)...);
240 template<
typename Key,
typename AssetClass>
243 assert(asset !=
nullptr);
247 template<
typename Key,
typename AssetClass>
249 return assets.contains(path) &&
assets[path] !=
nullptr;
252 template <
typename Key,
typename AssetClass>
255 return assets.contains(path);
258 template <
typename Key,
typename AssetClass>
262 return assets[path]->getLoadingState();
265 template<
typename Key,
typename AssetClass>
268 if (!
assets.contains(path))
return std::nullopt;
272 template <
typename Key,
typename AssetClass>
276 for (
auto& asset :
assets)
280 asset.second =
nullptr;
#define TRACY_ZONE_SCOPED_NAMED(name)
void requestLoad()
If this asset is in the UNLOADED state it will get added to the assets to load.
virtual void unload()
Base function for unloading the ecs data.
entt::entity getEntity() const
Getter for data.
AssetBase(bool initializeDefaultEntity=false)
virtual void updateLoadingState()
CpuLoadingState loadingState
CpuLoadingState getLoadingState()
Gets the loading state of this asset.
entt::registry & mainRegistry
std::unordered_map< Key, AssetClass * > assets
void declare(Key path, Args &&... args)
Adds an asset to the list in its unloaded state.
CpuLoadingState getAssetLoadingState(const Key &path)
Gets a loading state for an asset. If the asset is not yet declared it will return that it is UNLOADE...
std::optional< AssetClass * > getAsset(const Key &path)
Try's to get an asset. If the asset does not exist (can be checked with exists) it will return a std:...
bool isDeclared(Key path)
Checks if an asset has been declared. If it exists it is also declared.
void forEachAsset(Func &&func) const
Iterates over all assets and calls the provided callback for each.
bool exists(Key path)
Checks if an asset already exists. This means it is declared and there is content.
virtual void clear()
Clears out all resources.
void add(Key path, AssetClass *asset)
Adds or overwrites a previously declared asset at a key.
virtual ~AssetManager()=default
Classes which are related to asset loading are mostly stored in this namespace.
CpuLoadingState
State for assets in the asset loading process.
@ LOADED
All components of the asset have been loaded, and it is ready to be used.
@ REQUESTED_LOAD
An asset has been requested to load and is waiting for an asset pipeline to start working on it.
@ LOADING
While the asset is currently being processed in the asset pipeline.
@ UNLOADED
When the asset is not loaded yet but the frame is already existing for the heavy data to be loaded in...
Data structs for the Entity Component System.