FlatAssetWrapper
All checks were successful
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Successful in 2m25s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Successful in 35s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: OFF) (push) Successful in 1m9s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: ON) (push) Successful in 1m3s
Bigfoot / Build & Test Release (Unity Build: OFF) (push) Successful in 1m3s
Bigfoot / Build & Test Release (Unity Build: ON) (push) Successful in 59s
Bigfoot / Clang Format Checks (push) Successful in 11s

This commit is contained in:
2026-02-10 17:52:07 +01:00
parent f5ad5adff6
commit 46c3034ea6
5 changed files with 142 additions and 19 deletions

View File

@@ -0,0 +1,94 @@
/*********************************************************************
* \file Asset.hpp
*
* \author Romain BOULLARD
* \date February 2026
*********************************************************************/
#ifndef BIGFOOT_ENGINE_ASSET_HPP
#define BIGFOOT_ENGINE_ASSET_HPP
#include <Engine/BigFile/Asset/AssetHeader_generated.hpp>
#include <Engine/EngineAssertHandler.hpp>
#include <EASTL/vector.h>
namespace Bigfoot
{
template<typename FLAT_ASSET>
concept FlatAssetConcept = requires(FLAT_ASSET p_flatAsset) {
requires std::is_base_of_v<::flatbuffers::Table, FLAT_ASSET>;
requires std::derived_from<typename FLAT_ASSET::NativeTableType, ::flatbuffers::NativeTable>;
{ FLAT_ASSET::GetFullyQualifiedName() } -> std::convertible_to<const char*>;
{ p_flatAsset.asset_header() } -> std::same_as<const Bigfoot::Flat::AssetHeader*>;
};
template<FlatAssetConcept FLAT_ASSET>
class FlatAssetWrapper
{
private:
using FLAT_ASSET_NATIVE = FLAT_ASSET::NativeTableType;
using FLAT_ASSET_BUILDER = FLAT_ASSET::Builder;
public:
FlatAssetWrapper()
{
m_asset.asset_header = eastl::make_unique<Flat::AssetHeaderT>();
}
FlatAssetWrapper(const eastl::span<const std::byte> p_flatBuffer)
{
flatbuffers::Verifier::Options verifierOptions;
flatbuffers::Verifier verifier {std::bit_cast<const std::uint8_t*>(p_flatBuffer.data()),
p_flatBuffer.size(),
verifierOptions};
CRITICAL_ASSERT(EngineAssertHandler,
verifier.VerifyBuffer<FLAT_ASSET>(),
"Flatbuffer verifier failed for FLAT_ASSET!");
flatbuffers::GetRoot<FLAT_ASSET>(p_flatBuffer.data())->UnPackTo(&m_asset);
}
FlatAssetWrapper(const FlatAssetWrapper& p_assetWrapper) = delete;
FlatAssetWrapper(FlatAssetWrapper&& p_assetWrapper) = delete;
~FlatAssetWrapper() = default;
eastl::vector<std::byte> Pack() const
{
flatbuffers::FlatBufferBuilder builder;
builder.Finish(FLAT_ASSET::Pack(builder, &m_asset));
eastl::vector<std::byte> result {builder.GetSize()};
eastl::transform(builder.GetBufferSpan().begin(),
builder.GetBufferSpan().end(),
result.begin(),
[](const std::uint8_t p_value)
{
return static_cast<std::byte>(p_value);
});
return result;
}
[[nodiscard]]
FLAT_ASSET_NATIVE& Asset()
{
return m_asset;
}
[[nodiscard]]
const FLAT_ASSET_NATIVE& Asset() const
{
return m_asset;
}
FlatAssetWrapper& operator=(const FlatAssetWrapper p_assetWrapper) = delete;
FlatAssetWrapper& operator=(FlatAssetWrapper&& p_assetWrapper) = delete;
private:
FLAT_ASSET_NATIVE m_asset;
};
} // namespace Bigfoot
#endif

View File

@@ -6,6 +6,8 @@
*********************************************************************/
#include <Engine/BigFile/BigFile.hpp>
#include <Engine/BigFile/Asset/Asset.hpp>
#include <System/Log/Log.hpp>
#include <System/Time/Time.hpp>
#include <System/UUID/UUID.hpp>
@@ -34,6 +36,8 @@ class BigFileFixture: public ::testing::Test
m_bigFile.CommitTransaction();
}
FlatAssetWrapper<Flat::AssetA> test;
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::Lifetime m_loggerLifetime;)
BigFile m_bigFile {File {BIGFILE_ENGINETESTS_LOCATION}};
@@ -43,6 +47,31 @@ class BigFileFixture: public ::testing::Test
TEST_F(BigFileFixture, Lol)
{
{
UUID uuid;
test.Asset().health = 100;
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();
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->uuid, uuid);
EXPECT_EQ(test2.Asset().asset_header->version, 2);
}
UUID uuid;
UUID uuid2;

View File

@@ -7,7 +7,7 @@ table AssetA
asset_header: AssetHeader;
health: uint;
hp: uint;
mana: uint;
}
root_type AssetA;

View File

@@ -37,7 +37,7 @@ struct AssetAT : public ::flatbuffers::NativeTable {
}
eastl::unique_ptr<Bigfoot::Flat::AssetHeaderT> asset_header{};
uint32_t health = 0;
uint32_t hp = 0;
uint32_t mana = 0;
AssetAT() = default;
AssetAT(const AssetAT &o);
AssetAT(AssetAT&&) FLATBUFFERS_NOEXCEPT = default;
@@ -57,7 +57,7 @@ struct AssetA FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_ASSET_HEADER = 4,
VT_HEALTH = 6,
VT_HP = 8
VT_MANA = 8
};
const Bigfoot::Flat::AssetHeader *asset_header() const {
return GetPointer<const Bigfoot::Flat::AssetHeader *>(VT_ASSET_HEADER);
@@ -65,8 +65,8 @@ struct AssetA FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
uint32_t health() const {
return GetField<uint32_t>(VT_HEALTH, 0);
}
uint32_t hp() const {
return GetField<uint32_t>(VT_HP, 0);
uint32_t mana() const {
return GetField<uint32_t>(VT_MANA, 0);
}
template <bool B = false>
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
@@ -74,7 +74,7 @@ struct AssetA FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
VerifyOffset(verifier, VT_ASSET_HEADER) &&
verifier.VerifyTable(asset_header()) &&
VerifyField<uint32_t>(verifier, VT_HEALTH, 4) &&
VerifyField<uint32_t>(verifier, VT_HP, 4) &&
VerifyField<uint32_t>(verifier, VT_MANA, 4) &&
verifier.EndTable();
}
AssetAT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
@@ -92,8 +92,8 @@ struct AssetABuilder {
void add_health(uint32_t health) {
fbb_.AddElement<uint32_t>(AssetA::VT_HEALTH, health, 0);
}
void add_hp(uint32_t hp) {
fbb_.AddElement<uint32_t>(AssetA::VT_HP, hp, 0);
void add_mana(uint32_t mana) {
fbb_.AddElement<uint32_t>(AssetA::VT_MANA, mana, 0);
}
explicit AssetABuilder(::flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
@@ -110,9 +110,9 @@ inline ::flatbuffers::Offset<AssetA> CreateAssetA(
::flatbuffers::FlatBufferBuilder &_fbb,
::flatbuffers::Offset<Bigfoot::Flat::AssetHeader> asset_header = 0,
uint32_t health = 0,
uint32_t hp = 0) {
uint32_t mana = 0) {
AssetABuilder builder_(_fbb);
builder_.add_hp(hp);
builder_.add_mana(mana);
builder_.add_health(health);
builder_.add_asset_header(asset_header);
return builder_.Finish();
@@ -128,13 +128,13 @@ struct AssetA::Traits {
inline AssetAT::AssetAT(const AssetAT &o)
: asset_header((o.asset_header) ? new Bigfoot::Flat::AssetHeaderT(*o.asset_header) : nullptr),
health(o.health),
hp(o.hp) {
mana(o.mana) {
}
inline AssetAT &AssetAT::operator=(AssetAT o) FLATBUFFERS_NOEXCEPT {
std::swap(asset_header, o.asset_header);
std::swap(health, o.health);
std::swap(hp, o.hp);
std::swap(mana, o.mana);
return *this;
}
@@ -149,7 +149,7 @@ inline void AssetA::UnPackTo(AssetAT *_o, const ::flatbuffers::resolver_function
(void)_resolver;
{ auto _e = asset_header(); if (_e) { if(_o->asset_header) { _e->UnPackTo(_o->asset_header.get(), _resolver); } else { _o->asset_header = eastl::unique_ptr<Bigfoot::Flat::AssetHeaderT>(_e->UnPack(_resolver)); } } else if (_o->asset_header) { _o->asset_header.reset(); } }
{ auto _e = health(); _o->health = _e; }
{ auto _e = hp(); _o->hp = _e; }
{ auto _e = mana(); _o->mana = _e; }
}
inline ::flatbuffers::Offset<AssetA> CreateAssetA(::flatbuffers::FlatBufferBuilder &_fbb, const AssetAT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
@@ -162,12 +162,12 @@ inline ::flatbuffers::Offset<AssetA> AssetA::Pack(::flatbuffers::FlatBufferBuild
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const AssetAT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
auto _asset_header = _o->asset_header ? CreateAssetHeader(_fbb, _o->asset_header.get(), _rehasher) : 0;
auto _health = _o->health;
auto _hp = _o->hp;
auto _mana = _o->mana;
return Bigfoot::Flat::CreateAssetA(
_fbb,
_asset_header,
_health,
_hp);
_mana);
}
inline const ::flatbuffers::TypeTable *AssetATypeTable() {
@@ -182,7 +182,7 @@ inline const ::flatbuffers::TypeTable *AssetATypeTable() {
static const char * const names[] = {
"asset_header",
"health",
"hp"
"mana"
};
static const ::flatbuffers::TypeTable tt = {
::flatbuffers::ST_TABLE, 3, type_codes, type_refs, nullptr, nullptr, names

View File

@@ -66,7 +66,7 @@ class Bigfoot(ConanFile):
self.requires("unordered_dense/4.8.1@bigfootdev/main", transitive_headers=True)
self.requires("mimalloc/3.1.5@bigfootdev/main", transitive_headers=True)
self.requires("stduuid/1.2.3@bigfootdev/main", transitive_headers=True)
self.requires("sqlite3/3.51.0@bigfootdev/main", transitive_headers=True)
self.requires("sqlite3/3.51.2@bigfootdev/main", transitive_headers=True)
self.requires("cli11/2.6.0")
self.requires("rapidhash/3.0@bigfootdev/main", transitive_headers=True)
self.requires("effolkronium-random/1.5.0", transitive_headers=True)
@@ -77,10 +77,10 @@ class Bigfoot(ConanFile):
self.requires("cpptrace/1.0.4", transitive_headers=True)
if(self.options.tracy):
self.requires("tracy/0.12.2", transitive_headers=True)
self.requires("tracy/0.13.1", transitive_headers=True)
self.requires("glm/1.0.1", transitive_headers=True)
self.requires("lodepng/cci.20250727@bigfootdev/main", transitive_headers=True)
self.requires("lodepng/cci.20260210@bigfootdev/main", transitive_headers=True)
self.requires("imgui/1.92.5-docking", transitive_headers=True)
if(self.options.vulkan):