mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-27 20:41:49 +00:00
chore: adjust asset name method based on asset to not require constructor
This commit is contained in:
@@ -18,11 +18,11 @@ public:
|
|||||||
|
|
||||||
template<typename AssetType> struct AssetNameAccessor
|
template<typename AssetType> struct AssetNameAccessor
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||||
// static constexpr bool IS_SINGLETON = false;
|
// 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");
|
// throw std::runtime_error("Not implemented");
|
||||||
// }
|
// }
|
||||||
@@ -34,8 +34,9 @@ public:
|
|||||||
public: \
|
public: \
|
||||||
static_assert(std::is_base_of_v<IAssetBase, assetType>); \
|
static_assert(std::is_base_of_v<IAssetBase, assetType>); \
|
||||||
static constexpr bool IS_SINGLETON = false; \
|
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; \
|
return asset.nameProperty; \
|
||||||
} \
|
} \
|
||||||
@@ -47,10 +48,17 @@ public:
|
|||||||
public: \
|
public: \
|
||||||
static_assert(std::is_base_of_v<IAssetBase, assetType>); \
|
static_assert(std::is_base_of_v<IAssetBase, assetType>); \
|
||||||
static constexpr bool IS_SINGLETON = true; \
|
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; \
|
static const char* NAME = singletonName; \
|
||||||
return NAME; \
|
return NAME; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename AssetType> AssetNameAccessor<AssetType>::RETURN_TYPE AssetName(typename AssetType::Type& asset)
|
||||||
|
{
|
||||||
|
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||||
|
return AssetNameAccessor<AssetType>::GetAssetName(asset);
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override
|
AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override
|
||||||
{
|
{
|
||||||
auto* asset = m_memory.Alloc<typename AssetType::Type>();
|
auto* asset = m_memory.Alloc<typename AssetType::Type>();
|
||||||
AssetNameAccessor<AssetType>{}(*asset) = m_memory.Dup(assetName.c_str());
|
AssetName<AssetType>(*asset) = m_memory.Dup(assetName.c_str());
|
||||||
|
|
||||||
return AssetCreationResult::Success(context.AddAsset<AssetType>(assetName, asset));
|
return AssetCreationResult::Success(context.AddAsset<AssetType>(assetName, asset));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2159,7 +2159,7 @@ namespace
|
|||||||
LINEF("auto* reallocatedAsset = m_zone.Memory().Alloc<{0}>();", info->m_definition->GetFullName())
|
LINEF("auto* reallocatedAsset = m_zone.Memory().Alloc<{0}>();", info->m_definition->GetFullName())
|
||||||
LINEF("std::memcpy(reallocatedAsset, *pAsset, sizeof({0}));", info->m_definition->GetFullName())
|
LINEF("std::memcpy(reallocatedAsset, *pAsset, sizeof({0}));", info->m_definition->GetFullName())
|
||||||
LINE("")
|
LINE("")
|
||||||
LINEF("m_asset_info = reinterpret_cast<XAssetInfo<{0}>*>(LinkAsset(AssetNameAccessor<{1}>()(**pAsset), reallocatedAsset, "
|
LINEF("m_asset_info = reinterpret_cast<XAssetInfo<{0}>*>(LinkAsset(AssetName<{1}>(**pAsset), reallocatedAsset, "
|
||||||
"assetInfo.GetDependencies(), "
|
"assetInfo.GetDependencies(), "
|
||||||
"assetInfo.GetUsedScriptStrings(), assetInfo.GetIndirectAssetReferences()));",
|
"assetInfo.GetUsedScriptStrings(), assetInfo.GetIndirectAssetReferences()));",
|
||||||
info->m_definition->GetFullName(),
|
info->m_definition->GetFullName(),
|
||||||
@@ -2185,7 +2185,7 @@ namespace
|
|||||||
LINE("")
|
LINE("")
|
||||||
LINE("if (m_asset_info == nullptr && *pAsset != nullptr)")
|
LINE("if (m_asset_info == nullptr && *pAsset != nullptr)")
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
LINEF("m_asset_info = reinterpret_cast<XAssetInfo<{0}>*>(GetAssetInfo(AssetNameAccessor<{1}>()(**pAsset)));",
|
LINEF("m_asset_info = reinterpret_cast<XAssetInfo<{0}>*>(GetAssetInfo(AssetName<{1}>(**pAsset)));",
|
||||||
m_env.m_asset->m_definition->GetFullName(),
|
m_env.m_asset->m_definition->GetFullName(),
|
||||||
m_env.m_asset->m_asset_name)
|
m_env.m_asset->m_asset_name)
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
|
|||||||
@@ -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())
|
"{0}::{0}({1}* asset, const Zone& zone, IZoneOutputStream& stream)", WriterClassName(m_env.m_asset), m_env.m_asset->m_definition->GetFullName())
|
||||||
|
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, AssetNameAccessor<{0}>()(*asset)), zone, stream)",
|
LINEF(": AssetWriter(zone.m_pools->GetAssetOrAssetReference({0}::EnumEntry, AssetName<{0}>(*asset)), zone, stream)", m_env.m_asset->m_asset_name)
|
||||||
m_env.m_asset->m_asset_name)
|
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
|
|
||||||
LINE("{")
|
LINE("{")
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ protected:
|
|||||||
{
|
{
|
||||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||||
|
|
||||||
const auto result = m_visitor.Visit_Dependency(AssetType::EnumEntry, AssetNameAccessor<AssetType>()(*asset));
|
const auto result = m_visitor.Visit_Dependency(AssetType::EnumEntry, AssetName<AssetType>(*asset));
|
||||||
if (result.has_value())
|
if (result.has_value())
|
||||||
asset = static_cast<std::add_pointer_t<typename AssetType::Type>>(result->m_ptr);
|
asset = static_cast<std::add_pointer_t<typename AssetType::Type>>(result->m_ptr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user