// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Types/DataContainer.h" #include "../Config.h" /// /// Custom flags for the storage chunk data. /// enum class FlaxChunkFlags { /// /// The none. /// None = 0, /// /// Compress chunk data using LZ4 algorithm. /// CompressedLZ4 = 1, }; DECLARE_ENUM_OPERATORS(FlaxChunkFlags); /// /// Represents chunks of data used by the content storage layer /// class FLAXENGINE_API FlaxChunk { public: /// /// Chunk of data location info /// struct Location { /// /// Address of the chunk beginning in file /// uint32 Address; /// /// Chunk size (in bytes) /// Note: chunk which size equals 0 is considered as not existing /// uint32 Size; /// /// Init /// Location() : Address(0) , Size(0) { } /// /// Init /// /// The location. /// The size. Location(uint32 location, uint32 size) : Address(location) , Size(size) { } }; public: /// /// The chunk location in file. /// Location LocationInFile; /// /// The chunk flags. /// FlaxChunkFlags Flags = FlaxChunkFlags::None; /// /// The last usage time (atomic, ticks of DateTime in UTC). /// int64 LastAccessTime = 0; /// /// The chunk data. /// BytesContainer Data; public: /// /// Initializes a new instance of the class. /// FlaxChunk() { } /// /// Finalizes an instance of the class. /// ~FlaxChunk() { } public: /// /// Gets this chunk data pointer. /// FORCE_INLINE byte* Get() { return Data.Get(); } /// /// Gets this chunk data pointer. /// FORCE_INLINE const byte* Get() const { return Data.Get(); } /// /// Gets this chunk data pointer. /// template FORCE_INLINE T* Get() const { return (T*)Data.Get(); } /// /// Gets this chunk data size (in bytes). /// FORCE_INLINE int32 Size() const { return Data.Length(); } /// /// Determines whether this chunk is loaded. /// FORCE_INLINE bool IsLoaded() const { return Data.IsValid(); } /// /// Determines whether this chunk is missing (no data loaded or assigned). /// FORCE_INLINE bool IsMissing() const { return Data.IsInvalid(); } /// /// Determines whether this chunk exists in a file. /// FORCE_INLINE bool ExistsInFile() const { return LocationInFile.Size > 0; } /// /// Registers the usage operation of chunk data. /// void RegisterUsage(); /// /// Unloads this chunk data. /// void Unload() { Data.Release(); } /// /// Clones this chunk data (doesn't copy location in file). /// /// The cloned chunk. FlaxChunk* Clone() const { auto chunk = New(); chunk->Data.Copy(Data); return chunk; } };