Skip to content

Commit e6d0431

Browse files
committed
Work on asset loading
1 parent 7b93485 commit e6d0431

File tree

10 files changed

+39
-1789
lines changed

10 files changed

+39
-1789
lines changed

Mahakam/src/Mahakam/Asset/Asset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ namespace Mahakam
260260

261261
block->Control.UseCount = 0;
262262
block->Control.ID = 0;
263+
block->Control.State = AssetDatabase::AssetState::Loaded;
263264
block->Control.MoveData = mover;
264265
block->Control.DeleteData = deleter;
265266

Mahakam/src/Mahakam/Asset/AssetDatabase.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ namespace Mahakam
103103

104104
return asset;
105105
};
106+
serializer.Load = [](AssetDatabase::Reader& reader) -> Asset<void>
107+
{
108+
return nullptr;
109+
};
106110

107111
return serializer;
108112
}
@@ -281,16 +285,6 @@ namespace Mahakam
281285
RecursiveCacheAssets(FileUtility::ASSET_PATH);
282286
};
283287

284-
//const std::filesystem::path& AssetDatabase::GetAssetImportPath(AssetDatabase::AssetID id)
285-
MH_DEFINE_FUNC(AssetDatabase::GetAssetImportPath, const std::filesystem::path&, AssetDatabase::AssetID id)
286-
{
287-
auto iter = s_AssetPaths.find(id);
288-
if (iter != s_AssetPaths.end())
289-
return iter->second;
290-
291-
return EmptyPath;
292-
};
293-
294288
//const AssetDatabase::AssetMap& AssetDatabase::GetAssetHandles()
295289
MH_DEFINE_FUNC(AssetDatabase::GetAssetHandles, const AssetDatabase::AssetMap&)
296290
{

Mahakam/src/Mahakam/Asset/AssetDatabase.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,24 @@ namespace Mahakam
3131
// - A move function is used in the control block for moving another asset (of the same type) into this space
3232
// - A delete function is used in the control block for deleting when no longer used
3333

34-
typedef uint64_t AssetID;
34+
using AssetID = uint64_t;
3535

3636
// TODO: Remove
3737
typedef std::string ExtensionType;
3838

39+
enum class AssetState
40+
{
41+
Loaded = 0,
42+
Processing,
43+
Streaming
44+
};
45+
3946
struct ControlBlock
4047
{
4148
// ID 0 is guaranteed to be invalid
4249
size_t UseCount;
4350
AssetID ID;
51+
AssetState State;
4452
void (*MoveData)(void*, void*);
4553
void (*DeleteData)(void*);
4654
};
@@ -51,36 +59,31 @@ namespace Mahakam
5159
struct StreamBlock
5260
{
5361
Reader File;
54-
void (*Stream)(void*) = nullptr;
55-
void (*Load)(void*) = nullptr;
5662
};
5763

5864
struct AssetSerializer
5965
{
6066
bool (*Serialize)(Writer&, const std::filesystem::path& filepath, Asset<void>) = nullptr;
6167
Asset<void> (*Deserialize)(Reader&, const std::filesystem::path& filepath) = nullptr;
68+
Asset<void> (*Load)(Reader&) = nullptr;
6269
};
6370

6471
private:
6572
using AssetMap = UnorderedMap<AssetID, std::filesystem::path>;
66-
67-
using ImporterMap = UnorderedMap<ExtensionType, Ref<AssetImporter>>;
6873
using LoadedMap = UnorderedMap<AssetID, ControlBlock*>;
6974

70-
// TODO: Use AssetInfo instead of filepath
75+
// TODO: Remove since filepaths are the same as ID
7176
inline static AssetMap s_AssetPaths;
72-
73-
inline static ImporterMap s_AssetImporters; // Legacy importers
7477
inline static LoadedMap s_LoadedAssets;
7578

76-
77-
// TODO: Move into own class
78-
inline static const std::filesystem::path EmptyPath = "";
79-
8079
inline static UnorderedMap<std::string, AssetSerializer> s_Serializers;
8180

81+
// Legacy importers
82+
using ImporterMap = UnorderedMap<ExtensionType, Ref<AssetImporter>>;
83+
inline static ImporterMap s_AssetImporters;
8284
template<const char* Extension, const char* LegacyExt>
8385
static void LoadLegacySerializer();
86+
// Legacy importers
8487

8588
static void LoadDefaultSerializers();
8689

@@ -100,7 +103,6 @@ namespace Mahakam
100103
MH_DECLARE_FUNC(RefreshAssetPaths, void); // Refreshes the asset paths, finding new assets and removing unused ones
101104

102105
// Various getters
103-
MH_DECLARE_FUNC(GetAssetImportPath, const std::filesystem::path&, AssetID id); // Gets the import path of a given asset
104106
MH_DECLARE_FUNC(GetAssetHandles, const AssetMap&); // Gets a reference to all assets, whether they're currently loaded or not
105107
MH_DECLARE_FUNC(GetAssetReferences, size_t, AssetID id); // Gets the amount of references to this asset, if any
106108

Mahakam/src/Mahakam/Asset/AssetLookup.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ namespace Mahakam
2222
template<fixed_string S>
2323
struct AssetLookup {};
2424

25-
template<AssetDatabase::AssetID I>
25+
template<typename T, AssetDatabase::AssetID I>
2626
struct AssetBaseLookup
2727
{
2828
constexpr static AssetDatabase::AssetID ID = I;
2929

30-
template<typename T>
3130
operator Asset<T>()
3231
{
3332
return Asset<T>(ID);
3433
}
3534
};
3635

36+
class Material;
37+
3738
template<>
38-
struct AssetLookup<"test/assets/materials/skybox"> : AssetBaseLookup<1413214623375882268ULL> {};
39+
struct AssetLookup<"test/assets/materials/skybox"> : AssetBaseLookup<Material, 1413214623375882268ULL> {};
3940
}

Mahakam/src/Mahakam/BinarySerialization/FileStream.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace Mahakam::Serialization
1818
FileReader(const std::filesystem::path& filepath) :
1919
m_File(std::fopen(filepath.string().c_str(), "rb")) {}
2020

21+
FileReader(const FileReader&) = delete;
22+
FileReader(FileReader&&) = delete;
23+
2124
~FileReader()
2225
{
2326
if (m_File)
@@ -83,6 +86,9 @@ namespace Mahakam::Serialization
8386
FileWriter(const std::filesystem::path& filepath) :
8487
m_File(std::fopen(filepath.string().c_str(), "wb")) {}
8588

89+
FileWriter(const FileWriter&) = delete;
90+
FileWriter(FileWriter&&) = delete;
91+
8692
~FileWriter()
8793
{
8894
if (m_File)

Mahakam/src/Mahakam/Core/Random.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ namespace Mahakam
55
{
66
std::random_device Random::rd;
77
std::default_random_engine Random::generator(rd());
8-
std::uniform_int_distribution<uint64_t> Random::distribution(0, 0xFFFFFFFFFFFFFFFF);
8+
std::uniform_int_distribution<uint64_t> Random::distribution(1, 0xFFFFFFFFFFFFFFFF);
99

1010
uint64_t Random::GetRandomID64()
1111
{
12-
uint64_t id = 0;
13-
while (id == 0)
14-
id = distribution(generator);
15-
return id;
12+
return distribution(generator);
1613
}
1714
}

Sandbox/imgui.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DockId=0x00000009,0
3333

3434
[Window][Scene Hierarchy]
3535
Pos=0,22
36-
Size=381,643
36+
Size=370,643
3737
Collapsed=0
3838
DockId=0x00000002,0
3939

@@ -44,8 +44,8 @@ Collapsed=0
4444
DockId=0x00000003,0
4545

4646
[Window][Scene View]
47-
Pos=383,22
48-
Size=1026,643
47+
Pos=372,22
48+
Size=1037,643
4949
Collapsed=0
5050
DockId=0x00000007,0
5151

@@ -250,8 +250,8 @@ Column 2 Width=75
250250
DockSpace ID=0x3FC20BEE Window=0x9A404470 Pos=0,45 Size=1920,995 Split=X
251251
DockNode ID=0x00000001 Parent=0x3FC20BEE SizeRef=1409,995 Split=Y
252252
DockNode ID=0x00000005 Parent=0x00000001 SizeRef=1920,643 Split=X
253-
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=381,993 Selected=0x2E9237F7
254-
DockNode ID=0x00000009 Parent=0x00000005 SizeRef=1026,993 Split=Y
253+
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=370,993 Selected=0x2E9237F7
254+
DockNode ID=0x00000009 Parent=0x00000005 SizeRef=1037,993 Split=Y
255255
DockNode ID=0x00000004 Parent=0x00000009 SizeRef=727,150 Selected=0x968648AE
256256
DockNode ID=0x00000007 Parent=0x00000009 SizeRef=727,748 CentralNode=1 Selected=0x08AA43A5
257257
DockNode ID=0x0000000A Parent=0x00000001 SizeRef=1920,350 Split=X Selected=0xBF096F38

0 commit comments

Comments
 (0)