// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Types/Guid.h" #include "Engine/Core/Types/Pair.h" #include "Engine/Core/Types/String.h" #if USE_EDITOR #include "Engine/Core/Collections/Array.h" #endif #include "FlaxChunk.h" /// /// Marco that computes chunk flag value from chunk zero-index /// #define GET_CHUNK_FLAG(chunkIndex) (1 << chunkIndex) typedef uint16 AssetChunksFlag; #define ALL_ASSET_CHUNKS MAX_uint16 /// /// Flax Asset header /// struct FLAXENGINE_API AssetHeader { /// /// Unique asset ID /// Guid ID; /// /// Asset type name /// String TypeName; /// /// The asset chunks. /// FlaxChunk* Chunks[ASSET_FILE_DATA_CHUNKS]; public: /// /// Initializes a new instance of the struct. /// AssetHeader() { // Cleanup all data ID = Guid::Empty; Platform::MemoryClear(Chunks, sizeof(Chunks)); } public: /// /// Gets the chunks. /// /// The output data. template void GetChunks(Array& output) const { for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++) { if (Chunks[i] != nullptr) output.Add(Chunks[i]); } } /// /// Gets the chunks that are loaded. /// /// The output data. template void GetLoadedChunks(Array& output) const { for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++) { if (Chunks[i] != nullptr && Chunks[i]->IsLoaded()) output.Add(Chunks[i]); } } /// /// Gets the amount of created asset chunks. /// /// Created asset chunks int32 GetChunksCount() const { int32 result = 0; for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++) { if (Chunks[i] != nullptr) result++; } return result; } /// /// Deletes all chunks. Warning! Chunks are managed internally, use with caution! /// void DeleteChunks() { for (int32 i = 0; i < ASSET_FILE_DATA_CHUNKS; i++) { SAFE_DELETE(Chunks[i]); } } /// /// Unlinks all chunks. /// void UnlinkChunks() { Platform::MemoryClear(Chunks, sizeof(Chunks)); } /// /// Gets string with a human-readable info about that header /// /// Header info string String ToString() const; }; /// /// Flax Asset header data /// struct FLAXENGINE_API AssetInitData { /// /// The asset header. /// AssetHeader Header; /// /// The serialized asset version /// uint32 SerializedVersion = 0; /// /// The custom asset data (should be small, for eg. texture description structure). /// BytesContainer CustomData; #if USE_EDITOR /// /// The asset metadata information. Stored in a Json format. /// BytesContainer Metadata; /// /// Asset dependencies list used by the asset for tracking (eg. material functions used by material asset). The pair of asset ID and cached file edit time (for tracking modification). /// Array> Dependencies; #endif public: /// /// Gets the hash code. /// uint32 GetHashCode() const { // Note: do not use Metadata/Dependencies because it may not be loaded (it's optional) uint32 hashCode = GetHash(Header.ID); hashCode = (hashCode * 397) ^ SerializedVersion; hashCode = (hashCode * 397) ^ CustomData.Length(); return hashCode; } };