#pragma once #include "Zone/Zone.h" #include "Zone/ZoneTypes.h" #include #include class Zone; // An indirect asset reference is a reference that is not done per pointer but by mentioning the asset // in a string or requiring the asset to exist in some other way class IndirectAssetReference { public: asset_type_t m_type; std::string m_name; IndirectAssetReference(); IndirectAssetReference(asset_type_t type, std::string name); friend bool operator==(const IndirectAssetReference& lhs, const IndirectAssetReference& rhs); friend bool operator!=(const IndirectAssetReference& lhs, const IndirectAssetReference& rhs); }; template<> struct std::hash { std::size_t operator()(const IndirectAssetReference& v) const noexcept; }; class XAssetInfoGeneric { public: XAssetInfoGeneric(); XAssetInfoGeneric(asset_type_t type, std::string name, void* ptr); XAssetInfoGeneric( asset_type_t type, std::string name, void* ptr, std::vector dependencies, std::vector usedScriptStrings); XAssetInfoGeneric(asset_type_t type, std::string name, void* ptr, std::vector dependencies, std::vector usedScriptStrings, std::vector indirectAssetReferences); XAssetInfoGeneric(asset_type_t type, std::string name, void* ptr, std::vector dependencies, std::vector usedScriptStrings, std::vector indirectAssetReferences, Zone* zone); ~XAssetInfoGeneric() = default; XAssetInfoGeneric(const XAssetInfoGeneric& other) = default; XAssetInfoGeneric(XAssetInfoGeneric&& other) noexcept = default; XAssetInfoGeneric& operator=(const XAssetInfoGeneric& other) = default; XAssetInfoGeneric& operator=(XAssetInfoGeneric&& other) noexcept = default; [[nodiscard]] bool IsReference() const; static std::string NormalizeAssetName(std::string input); asset_type_t m_type; std::string m_name; void* m_ptr; std::vector m_dependencies; std::vector m_used_script_strings; std::vector m_indirect_asset_references; Zone* m_zone; }; template class XAssetInfo : public XAssetInfoGeneric { public: XAssetInfo() = default; XAssetInfo(const asset_type_t type, std::string name, T* ptr) : XAssetInfoGeneric(type, std::move(name), static_cast(ptr)) { } XAssetInfo(const asset_type_t type, std::string name, T* ptr, std::vector dependencies, std::vector usedScriptStrings) : XAssetInfoGeneric(type, std::move(name), static_cast(ptr), std::move(dependencies), std::move(usedScriptStrings)) { } XAssetInfo(const asset_type_t type, std::string name, T* ptr, std::vector dependencies, std::vector usedScriptStrings, std::vector indirectAssetReferences) : XAssetInfoGeneric( type, std::move(name), static_cast(ptr), std::move(dependencies), std::move(usedScriptStrings), std::move(indirectAssetReferences)) { } XAssetInfo(const asset_type_t type, std::string name, T* ptr, std::vector dependencies, std::vector usedScriptStrings, std::vector indirectAssetReferences, Zone* zone) : XAssetInfoGeneric( type, std::move(name), static_cast(ptr), std::move(dependencies), std::move(usedScriptStrings), std::move(indirectAssetReferences), zone) { } ~XAssetInfo() = default; XAssetInfo(const XAssetInfo& other) = default; XAssetInfo(XAssetInfo&& other) noexcept = default; XAssetInfo& operator=(const XAssetInfo& other) = default; XAssetInfo& operator=(XAssetInfo&& other) noexcept = default; T* Asset() { return static_cast(m_ptr); } const T* Asset() const { return static_cast(const_cast(m_ptr)); } };