Finality Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
AssetManager.h
Go to the documentation of this file.
1
6
#pragma once
7
#include <
Assets/Asset.h
>
8
#include <unordered_map>
9
#include <memory>
10
#include <string>
11
12
#include <
Core/Core.h
>
13
#include "
AssetRegistry.h
"
14
15
namespace
FINALITY
16
{
17
class
Texture
;
19
class
FAPI
AssetManager
20
{
21
public
:
22
static
void
Initialize
();
23
static
void
Shutdown
();
24
25
template
<
typename
T,
typename
... Args>
26
static
std::shared_ptr<T>
CreateAsset
(
const
std::string& filePath, Args&&... args)
27
{
28
const
std::string resolved =
AssetRegistry::Resolve
(filePath);
29
if
(resolved.empty())
return
nullptr
;
30
auto
it = s_PathToHandleRegistry.find(resolved);
31
if
(it != s_PathToHandleRegistry.end())
32
{
33
return
std::dynamic_pointer_cast<T>(s_LoadedAssets[it->second]);
34
}
35
36
std::shared_ptr<T> asset;
37
try
{ asset = T::Create(resolved, std::forward<Args>(args)...); }
38
catch
(
const
std::exception&) {
return
nullptr
; }
39
if
(!asset)
return
nullptr
;
40
41
const
auto
* record =
AssetRegistry::FindPath
(resolved);
42
UUID
handle = record ?
UUID
(record->ID) :
UUID
();
43
asset->Handle = handle;
44
45
s_LoadedAssets[handle] = asset;
46
s_PathToHandleRegistry[resolved] = handle;
47
48
return
asset;
49
}
50
51
static
std::shared_ptr<Asset>
GetAsset
(
UUID
handle);
52
static
bool
HasAsset
(
UUID
handle);
53
static
size_t
ReloadMaterialShaders
(
bool
force =
false
);
54
static
void
InvalidateAssetPath
(
const
std::string& filePath);
55
static
std::shared_ptr<Texture>
ReloadTexture
(
const
std::string& filePath);
56
57
private
:
58
static
std::unordered_map<UUID, std::shared_ptr<Asset>> s_LoadedAssets;
59
static
std::unordered_map<std::string, UUID> s_PathToHandleRegistry;
60
};
61
}
Asset.h
AssetRegistry.h
Tracks project assets, metadata and reference resolution.
Core.h
FAPI
#define FAPI
Definition
Core.h:22
FINALITY::AssetManager
Definition
AssetManager.h:20
FINALITY::AssetManager::Initialize
static void Initialize()
FINALITY::AssetManager::HasAsset
static bool HasAsset(UUID handle)
FINALITY::AssetManager::ReloadTexture
static std::shared_ptr< Texture > ReloadTexture(const std::string &filePath)
FINALITY::AssetManager::GetAsset
static std::shared_ptr< Asset > GetAsset(UUID handle)
FINALITY::AssetManager::CreateAsset
static std::shared_ptr< T > CreateAsset(const std::string &filePath, Args &&... args)
Definition
AssetManager.h:26
FINALITY::AssetManager::InvalidateAssetPath
static void InvalidateAssetPath(const std::string &filePath)
FINALITY::AssetManager::ReloadMaterialShaders
static size_t ReloadMaterialShaders(bool force=false)
FINALITY::AssetManager::Shutdown
static void Shutdown()
FINALITY::AssetRegistry::FindPath
static const AssetRecord * FindPath(const std::filesystem::path &path)
FINALITY::AssetRegistry::Resolve
static std::string Resolve(const std::string &reference)
FINALITY::Texture
Definition
Texture.h:16
FINALITY::UUID
Definition
UUID.h:16
FINALITY
Definition
Asset.h:12
FinalityEngine
src
Assets
AssetManager.h
Generated by
1.18.0