Grindstone Game Engine
v0.2.0
An open source game engine and toolkit.
Toggle main menu visibility
Loading...
Searching...
No Matches
AssetImporter.hpp
1
#pragma once
2
3
#include <string>
4
#include <map>
5
6
#include <Common/ResourcePipeline/Uuid.hpp>
7
#include <Common/ResourcePipeline/AssetType.hpp>
8
#include <EngineCore/Assets/Asset.hpp>
9
10
namespace
Grindstone {
11
class
AssetImporter
{
12
public
:
13
virtual
~AssetImporter
() {};
14
15
virtual
void
QueueReloadAsset(
Uuid
uuid) = 0;
16
virtual
void
* LoadAsset(
Uuid
uuid) = 0;
17
virtual
bool
TryGetIfLoaded(
Uuid
uuid,
void
*& output) = 0;
18
virtual
void
* IncrementAssetUse(
Uuid
uuid) = 0;
19
virtual
void
DecrementAssetUse(
Uuid
uuid) = 0;
20
virtual
void
IncrementOrLoad(
Uuid
uuid) = 0;
21
virtual
AssetType GetAssetType() {
return
assetType; }
22
23
protected
:
24
AssetType assetType = AssetType::Undefined;
25
26
};
27
28
template
<
typename
AssetStructType, AssetType
int
ernalAssetType>
29
class
SpecificAssetImporter :
public
AssetImporter
{
30
public
:
31
32
SpecificAssetImporter() { assetType = internalAssetType; }
33
static
AssetType GetStaticAssetType() {
return
internalAssetType; }
34
static
const
char
* GetStaticAssetTypeName() {
return
GetAssetTypeToString(internalAssetType); }
35
virtual
void
OnDeleteAsset(AssetStructType& asset) {}
36
37
virtual
void
* IncrementAssetUse(
Uuid
uuid)
override
{
38
void
* output =
nullptr
;
39
if
(TryGetIfLoaded(uuid, output)) {
40
AssetStructType* asset =
static_cast<
AssetStructType*
>
(output);
41
42
if
(asset->assetLoadStatus == AssetLoadStatus::Ready) {
43
++asset->referenceCount;
44
return
asset;
45
}
46
47
return
nullptr
;
48
}
49
else
{
50
return
LoadAsset(uuid);
51
}
52
53
return
nullptr
;
54
}
55
56
virtual
void
DecrementAssetUse(
Uuid
uuid)
override
{
57
void
* output =
nullptr
;
58
59
if
(TryGetIfLoaded(uuid, output) && output !=
nullptr
) {
60
AssetStructType* asset =
static_cast<
AssetStructType*
>
(output);
61
if
(asset->referenceCount <= 1) {
62
OnDeleteAsset(*asset);
63
assets.erase(uuid);
64
}
65
else
{
66
--asset->referenceCount;
67
}
68
}
69
}
70
71
virtual
bool
TryGetIfLoaded(
Uuid
uuid,
void
*& output)
override
{
72
auto
assetInMap = assets.find(uuid);
73
if
(assetInMap != assets.end()) {
74
output = &assetInMap->second;
75
return
true
;
76
}
77
78
return
false
;
79
}
80
81
virtual
void
IncrementOrLoad(
Uuid
uuid)
override
{
82
auto
assetInMap = assets.find(uuid);
83
if
(assetInMap != assets.end()) {
84
++assetInMap->second.referenceCount;
85
return
;
86
}
87
88
LoadAsset(uuid);
89
}
90
91
size_t
AssetCount()
const
{
return
assets.size(); }
92
bool
HasAssets()
const
{
return
assets.size() != 0; }
93
94
auto
begin()
noexcept
{
return
assets.begin(); }
95
auto
cbegin()
const
noexcept
{
return
assets.begin(); }
96
auto
end()
noexcept
{
return
assets.end(); }
97
auto
cend()
const
noexcept
{
return
assets.cend(); }
98
99
protected
:
100
std::map<Uuid, AssetStructType> assets;
101
102
};
103
}
Grindstone::AssetImporter
Definition
AssetImporter.hpp:11
Grindstone::Uuid
Definition
Uuid.hpp:7
sources
code
EngineCore
Assets
AssetImporter.hpp
Generated by
1.17.0