#pragma once #include #include #include #include #include #include #include #include struct AssetBase { public: int64_t ID; }; struct AssetGUID { AssetGUID() = default; AssetGUID(const char* data) : AssetGUID(std::string_view(data, 32)) {}; AssetGUID(std::string_view data) { for (size_t i = 0; i < 16; ++i) Data[0] = (Data[0] << 4) | hexToVal(data[i]); for (size_t i = 16; i < 32; ++i) Data[1] = (Data[1] << 4) | hexToVal(data[i]); } static uint64_t hexToVal(char c) { return (c >= '0' && c <= '9') ? (c - '0') : (c - 'a' + 10); } bool operator==(const AssetGUID& other) const { return Data[0] == other.Data[0] && Data[1] == other.Data[1]; } static constexpr uint64_t DefaultVal = 0xe000000000000000; std::array Data{ 0, DefaultVal }; }; namespace std { template <> struct hash { size_t operator()(const AssetGUID& v) const noexcept { auto h1 = std::hash{}(v.Data[0]); auto h2 = std::hash{}(v.Data[1]); return h1 ^ (h2 << 1); } }; } template T* ParseAssetRef(const ryml::ConstNodeRef& node) { T* asset; node["fileID"] >> asset; return asset; } template bool LinkAssetRef(const std::unordered_map& assetsMap, T*& asset) { auto it = assetsMap.find(reinterpret_cast(asset)); if (it != assetsMap.end()) { asset = reinterpret_cast(it->second); return true; } asset = nullptr; return false; } inline AssetGUID ParseAssetGUID(const ryml::ConstNodeRef& node) { auto guidStringSpan2 = node["guid"].val(); assert(guidStringSpan2.size() == 32); return AssetGUID{std::string_view(guidStringSpan2.data(), guidStringSpan2.size())}; }