Correct TypeID and TypeName
All checks were successful
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Successful in 2m31s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Successful in 36s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: OFF) (push) Successful in 1m8s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: ON) (push) Successful in 1m4s
Bigfoot / Build & Test Release (Unity Build: OFF) (push) Successful in 59s
Bigfoot / Build & Test Release (Unity Build: ON) (push) Successful in 54s
Bigfoot / Clang Format Checks (push) Successful in 10s

This commit is contained in:
2026-02-11 01:10:45 +01:00
parent 46c3034ea6
commit e4bcf5563c
2 changed files with 36 additions and 5 deletions

View File

@@ -11,6 +11,7 @@
#include <Engine/EngineAssertHandler.hpp>
#include <EASTL/vector.h>
#include <rapidhash.h>
namespace Bigfoot
{
@@ -34,6 +35,8 @@ class FlatAssetWrapper
FlatAssetWrapper()
{
m_asset.asset_header = eastl::make_unique<Flat::AssetHeaderT>();
m_asset.asset_header->type_id = TypeID();
m_asset.asset_header->type_name = TypeName();
}
FlatAssetWrapper(const eastl::span<const std::byte> p_flatBuffer)
@@ -46,7 +49,17 @@ class FlatAssetWrapper
verifier.VerifyBuffer<FLAT_ASSET>(),
"Flatbuffer verifier failed for FLAT_ASSET!");
flatbuffers::GetRoot<FLAT_ASSET>(p_flatBuffer.data())->UnPackTo(&m_asset);
const FLAT_ASSET* flatAsset = flatbuffers::GetRoot<FLAT_ASSET>(p_flatBuffer.data());
CRITICAL_ASSERT(EngineAssertHandler,
flatAsset->asset_header()->type_id()->value() == TypeID() &&
(std::strcmp(flatAsset->asset_header()->type_name()->c_str(), TypeName().data()) == 0),
"Mismatch between flatbufer type and actual type! flatbuffer = {}/{}; expected = {}/{}",
flatAsset->asset_header()->type_name()->c_str(),
flatAsset->asset_header()->type_id()->value(),
TypeName(),
TypeID());
flatAsset->UnPackTo(&m_asset);
}
FlatAssetWrapper(const FlatAssetWrapper& p_assetWrapper) = delete;
@@ -83,6 +96,21 @@ class FlatAssetWrapper
return m_asset;
}
static AssetTypeID TypeID()
{
static eastl::string_view typeName = TypeName();
static AssetTypeID typeID = rapidhash(typeName.data(), typeName.size());
return typeID;
}
static eastl::string_view TypeName()
{
static eastl::string_view typeName {FLAT_ASSET::GetFullyQualifiedName()};
return typeName;
}
FlatAssetWrapper& operator=(const FlatAssetWrapper p_assetWrapper) = delete;
FlatAssetWrapper& operator=(FlatAssetWrapper&& p_assetWrapper) = delete;

View File

@@ -54,20 +54,23 @@ TEST_F(BigFileFixture, Lol)
test.Asset().mana = 42;
test.Asset().asset_header->name = "Instance";
test.Asset().asset_header->type_id = 1;
test.Asset().asset_header->type_name = "AssetA";
test.Asset().asset_header->uuid = uuid;
test.Asset().asset_header->version = 2;
const eastl::vector<std::byte> flatbuffer = test.Pack();
EXPECT_STREQ(FlatAssetWrapper<Flat::AssetA>::TypeName().data(), "Bigfoot.Flat.AssetA");
EXPECT_EQ(FlatAssetWrapper<Flat::AssetA>::TypeID(),
rapidhash(FlatAssetWrapper<Flat::AssetA>::TypeName().data(),
FlatAssetWrapper<Flat::AssetA>::TypeName().size()));
FlatAssetWrapper<Flat::AssetA> test2 {flatbuffer};
EXPECT_EQ(test2.Asset().health, 100);
EXPECT_EQ(test2.Asset().mana, 42);
EXPECT_STREQ(test2.Asset().asset_header->name.c_str(), "Instance");
EXPECT_EQ(test2.Asset().asset_header->type_id, 1);
EXPECT_STREQ(test2.Asset().asset_header->type_name.c_str(), "AssetA");
EXPECT_EQ(test2.Asset().asset_header->type_id, FlatAssetWrapper<Flat::AssetA>::TypeID());
EXPECT_STREQ(test2.Asset().asset_header->type_name.c_str(), FlatAssetWrapper<Flat::AssetA>::TypeName().data());
EXPECT_EQ(test2.Asset().asset_header->uuid, uuid);
EXPECT_EQ(test2.Asset().asset_header->version, 2);
}