LkEngine 0.1.2
 
Loading...
Searching...
No Matches
AssetManager.h
1#pragma once
2
3#if defined(LK_PLATFORM_WINDOWS)
4#define LK_DEBUG_ASSET_LOG 0
5#elif defined(LK_PLATFORM_LINUX)
6#define LK_DEBUG_ASSET_LOG 1
7#endif
8
9#include "IAssetManager.h"
10
11#include "LkEngine/Project/Project.h"
12
13namespace LkEngine {
14
16 {
17 public:
18 static void Initialize();
19 static void Destroy();
20
21 FORCEINLINE static bool IsAssetHandleValid(const FAssetHandle Handle)
22 {
23 return LProject::GetAssetManager()->IsAssetHandleValid(Handle);
24 }
25
26 FORCEINLINE static EAssetType GetAssetType(const FAssetHandle Handle)
27 {
28 return LProject::GetAssetManager()->GetAssetType(Handle);
29 }
30
31 FORCEINLINE static bool ReloadData(const FAssetHandle Handle)
32 {
33 return LProject::GetAssetManager()->ReloadData(Handle);
34 }
35
36 template<typename T>
37 FORCEINLINE static TObjectPtr<T> GetAsset(const FAssetHandle Handle)
38 {
39 TObjectPtr<LAsset> Asset = LProject::GetAssetManager()->GetAsset(Handle);
40 return Asset.As<T>();
41 }
42
43 template<typename T>
44 static std::unordered_set<FAssetHandle> GetAllAssetsWithType()
45 {
46 return LProject::GetAssetManager()->GetAllAssetsWithType(T::GetStaticType());
47 }
48
49 FORCEINLINE static const std::unordered_map<FAssetHandle, TObjectPtr<LAsset>>& GetLoadedAssets()
50 {
51 return LProject::GetAssetManager()->GetLoadedAssets();
52 }
53
54 FORCEINLINE static const std::unordered_map<FAssetHandle , TObjectPtr<LAsset>>& GetMemoryOnlyAssets()
55 {
56 return LProject::GetAssetManager()->GetMemoryOnlyAssets();
57 }
58
59 FORCEINLINE static FAssetHandle GetAssetHandleFromFilePath(const std::filesystem::path& InFilepath)
60 {
61 return LProject::GetAssetManager()->GetAssetHandleFromFilePath(InFilepath);
62 }
63
64 template<typename TAsset, typename... TArgs>
65 static FAssetHandle CreateMemoryOnlyAsset(TArgs&&... Args)
66 {
67 static_assert(std::is_base_of_v<LAsset, TAsset>, "CreateMemoryOnlyAsset only works for types derived from Asset");
68 TObjectPtr<TAsset> Asset = TObjectPtr<TAsset>::Create(std::forward<TArgs>(Args)...);
69 Asset->Handle = FAssetHandle();
70 LProject::GetAssetManager()->AddMemoryOnlyAsset(Asset);
71
72 return Asset->Handle;
73 }
74
75 template<typename TAsset, typename... TArgs>
76 static FAssetHandle CreateMemoryOnlyRendererAsset(TArgs&&... Args)
77 {
78 static_assert(std::is_base_of_v<LAsset, TAsset>, "CreateMemoryOnlyAsset only works for types derived from Asset");
79 TObjectPtr<TAsset> Asset = TAsset::Create(std::forward<TArgs>(Args)...);
80 Asset->Handle = FAssetHandle();
81 LProject::GetAssetManager()->AddMemoryOnlyAsset(Asset);
82
83 return Asset->Handle;
84 }
85
86 template<typename TAsset, typename... TArgs>
87 static FAssetHandle CreateMemoryOnlyAssetWithHandle(FAssetHandle Handle, TArgs&&... Args)
88 {
89 static_assert(std::is_base_of_v<LAsset, TAsset>, "CreateMemoryOnlyAsset only works for types derived from Asset");
90 TObjectPtr<TAsset> Asset = TObjectPtr<TAsset>::Create(std::forward<TArgs>(Args)...);
91 Asset->Handle = Handle;
92 LProject::GetAssetManager()->AddMemoryOnlyAsset(Asset);
93
94 return Asset->Handle;
95 }
96
97 template<typename TAsset>
98 static FAssetHandle AddMemoryOnlyAsset(TObjectPtr<TAsset> Asset)
99 {
100 static_assert(std::is_base_of_v<LAsset, TAsset>, "AddMemoryOnlyAsset only works for types derived from Asset");
101 Asset->Handle = FAssetHandle();
102 LProject::GetAssetManager()->AddMemoryOnlyAsset(Asset);
103
104 return Asset->Handle;
105 }
106
107 FORCEINLINE static bool IsMemoryAsset(const FAssetHandle Handle)
108 {
109 return LProject::GetAssetManager()->IsMemoryAsset(Handle);
110 }
111
112 };
113
114}
Definition AssetManager.h:16
Definition ObjectPtr.h:102
static TObjectPtr< T > Create(TArgs &&... Args)
Create new pointer instance of type T.
Definition Asset.h:11
EAssetType
Definition AssetTypes.h:24
Definition UUID.h:13