Skip to content

Commit

Permalink
#63. ResourceObject: Make it possible to have unique string id fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinTomashevich committed Feb 6, 2023
1 parent b496f3d commit e09016f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Library/Public/ResourceObject/Resource/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,32 @@ static bool DoPatchesReferenceSamePart (const TypeManifest &_typeManifest,
}

EMERGENCE_ASSERT (_first.GetTypeMapping ().GetField (typeInfo->uniqueId).IsHandleValid ());
EMERGENCE_ASSERT (_first.GetTypeMapping ().GetField (typeInfo->uniqueId).GetArchetype () ==
StandardLayout::FieldArchetype::UINT);
const StandardLayout::FieldArchetype archetype =
_first.GetTypeMapping ().GetField (typeInfo->uniqueId).GetArchetype ();
EMERGENCE_ASSERT (archetype == StandardLayout::FieldArchetype::UINT ||
archetype == StandardLayout::FieldArchetype::UNIQUE_STRING);
EMERGENCE_ASSERT (_first.GetTypeMapping ().GetField (typeInfo->uniqueId).GetSize () == sizeof (UniqueId));

UniqueId firstId = 0u;
UniqueId secondId = 0u;

auto findId = [typeInfo] (const StandardLayout::Patch &_patch, UniqueId &_output)
auto findId = [typeInfo, archetype] (const StandardLayout::Patch &_patch, UniqueId &_output)
{
for (const StandardLayout::Patch::ChangeInfo &changeInfo : _patch)
{
if (changeInfo.field == typeInfo->uniqueId)
{
_output = *static_cast<const UniqueId *> (changeInfo.newValue);
if (archetype == StandardLayout::FieldArchetype::UINT)
{
_output = *static_cast<const UniqueId *> (changeInfo.newValue);
}
else
{
static_assert (sizeof (UniqueId) == sizeof (uintptr_t));
_output =
reinterpret_cast<UniqueId> (**static_cast<const Memory::UniqueString *> (changeInfo.newValue));
}

return true;
}
}
Expand Down

0 comments on commit e09016f

Please sign in to comment.