diff --git a/src/Common/Game/IAsset.h b/src/Common/Game/IAsset.h index 0cd7d6fd..d51b2abe 100644 --- a/src/Common/Game/IAsset.h +++ b/src/Common/Game/IAsset.h @@ -18,11 +18,11 @@ public: template struct AssetNameAccessor { -public: static_assert(std::is_base_of_v); // static constexpr bool IS_SINGLETON = false; + // using RETURN_TYPE = const char*&; - // const char*& operator()(AssetType::Type& asset) + // static RETURN_TYPE GetAssetName(assetType::Type& asset) // { // throw std::runtime_error("Not implemented"); // } @@ -34,8 +34,9 @@ public: public: \ static_assert(std::is_base_of_v); \ static constexpr bool IS_SINGLETON = false; \ + using RETURN_TYPE = const char*&; \ \ - const char*& operator()(assetType::Type& asset) \ + static RETURN_TYPE GetAssetName(assetType::Type& asset) \ { \ return asset.nameProperty; \ } \ @@ -47,10 +48,17 @@ public: public: \ static_assert(std::is_base_of_v); \ static constexpr bool IS_SINGLETON = true; \ + using RETURN_TYPE = const char* const&; \ \ - const char* const& operator()(assetType::Type& asset) \ + static RETURN_TYPE GetAssetName(assetType::Type& asset) \ { \ static const char* NAME = singletonName; \ return NAME; \ } \ } + +template AssetNameAccessor::RETURN_TYPE AssetName(typename AssetType::Type& asset) +{ + static_assert(std::is_base_of_v); + return AssetNameAccessor::GetAssetName(asset); +} diff --git a/src/ObjLoading/Asset/IDefaultAssetCreator.h b/src/ObjLoading/Asset/IDefaultAssetCreator.h index bcd0963f..cf43ba2a 100644 --- a/src/ObjLoading/Asset/IDefaultAssetCreator.h +++ b/src/ObjLoading/Asset/IDefaultAssetCreator.h @@ -42,7 +42,7 @@ public: AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override { auto* asset = m_memory.Alloc(); - AssetNameAccessor{}(*asset) = m_memory.Dup(assetName.c_str()); + AssetName(*asset) = m_memory.Dup(assetName.c_str()); return AssetCreationResult::Success(context.AddAsset(assetName, asset)); } diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp index ddf907a9..d0283505 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp @@ -2159,7 +2159,7 @@ namespace LINEF("auto* reallocatedAsset = m_zone.Memory().Alloc<{0}>();", info->m_definition->GetFullName()) LINEF("std::memcpy(reallocatedAsset, *pAsset, sizeof({0}));", info->m_definition->GetFullName()) LINE("") - LINEF("m_asset_info = reinterpret_cast*>(LinkAsset(AssetNameAccessor<{1}>()(**pAsset), reallocatedAsset, " + LINEF("m_asset_info = reinterpret_cast*>(LinkAsset(AssetName<{1}>(**pAsset), reallocatedAsset, " "assetInfo.GetDependencies(), " "assetInfo.GetUsedScriptStrings(), assetInfo.GetIndirectAssetReferences()));", info->m_definition->GetFullName(), @@ -2185,7 +2185,7 @@ namespace LINE("") LINE("if (m_asset_info == nullptr && *pAsset != nullptr)") m_intendation++; - LINEF("m_asset_info = reinterpret_cast*>(GetAssetInfo(AssetNameAccessor<{1}>()(**pAsset)));", + LINEF("m_asset_info = reinterpret_cast*>(GetAssetInfo(AssetName<{1}>(**pAsset)));", m_env.m_asset->m_definition->GetFullName(), m_env.m_asset->m_asset_name) m_intendation--; diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp index dc27cb35..3d1aba7b 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneWriteTemplate.cpp @@ -261,8 +261,7 @@ namespace "{0}::{0}({1}* asset, const Zone& zone, IZoneOutputStream& stream)", WriterClassName(m_env.m_asset), m_env.m_asset->m_definition->GetFullName()) m_intendation++; - LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, AssetNameAccessor<{0}>()(*asset)), zone, stream)", - m_env.m_asset->m_asset_name) + LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, AssetName<{0}>(*asset)), zone, stream)", m_env.m_asset->m_asset_name) m_intendation--; LINE("{") diff --git a/src/ZoneCommon/Marking/BaseAssetMarker.h b/src/ZoneCommon/Marking/BaseAssetMarker.h index 7e6cfeb6..6bf94227 100644 --- a/src/ZoneCommon/Marking/BaseAssetMarker.h +++ b/src/ZoneCommon/Marking/BaseAssetMarker.h @@ -15,7 +15,7 @@ protected: { static_assert(std::is_base_of_v); - const auto result = m_visitor.Visit_Dependency(AssetType::EnumEntry, AssetNameAccessor()(*asset)); + const auto result = m_visitor.Visit_Dependency(AssetType::EnumEntry, AssetName(*asset)); if (result.has_value()) asset = static_cast>(result->m_ptr); }