Compare commits

3 Commits

Author SHA1 Message Date
a21354b4b4 AssetContainer semantic
Some checks failed
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Failing after 2m58s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Failing after 1m10s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: OFF) (push) Failing after 1m47s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: ON) (push) Failing after 1m38s
Bigfoot / Build & Test Release (Unity Build: OFF) (push) Failing after 1m36s
Bigfoot / Build & Test Release (Unity Build: ON) (push) Failing after 1m23s
Bigfoot / Clang Format Checks (push) Successful in 11s
2026-02-13 18:43:21 +01:00
d6df6d8a71 unordered_dense link 2026-02-13 18:40:39 +01:00
bbc8aa3e80 update dependencies 2026-02-13 18:40:30 +01:00
5 changed files with 135 additions and 29 deletions

View File

@@ -7,25 +7,91 @@
#ifndef BIGFOOT_ENGINE_ASSETCONTAINER_HPP
#define BIGFOOT_ENGINE_ASSETCONTAINER_HPP
#include <Engine/BigFile/Asset/Asset.hpp>
#include <Engine/EngineAssertHandler.hpp>
#include <unordered_map>
#include <eastl/vector_map.h>
namespace Bigfoot
{
template<typename ASSET>
concept BigfootAssetConcept = requires(ASSET p_asset) {
concept BigfootAssetConcept = requires(ASSET p_asset, const ASSET p_constAsset) {
requires FlatAssetConcept<typename ASSET::FLAT_ASSET> &&
std::constructible_from<ASSET, FlatAssetWrapper<typename ASSET::FLAT_ASSET>>;
std::constructible_from<ASSET, FlatAssetWrapper<typename ASSET::FLAT_ASSET>*>;
};
template<BigfootAssetConcept ASSET>
class AssetContainer
{
public:
AssetContainer() = default;
AssetContainer(const AssetContainer& p_container) = delete;
AssetContainer(AssetContainer&& p_container) = delete;
[[nodiscard]]
bool Add(const UUID& p_uuid, const eastl::string_view p_name)
{
FlatAssetWrapper<typename ASSET::FLAT_ASSET> flatAsset {};
flatAsset.Asset().asset_header->uuid = p_uuid;
flatAsset.Asset().asset_header->name = p_name;
return Add(p_uuid, flatAsset.Pack());
}
[[nodiscard]]
bool Add(const UUID& p_uuid, const eastl::span<const std::byte> p_flatBuffer)
{
const auto& added = m_assets.emplace(p_uuid, eastl::make_unique<AssetFlatAssetWrapperPair>(p_flatBuffer));
CRITICAL_ASSERT(EngineAssertHandler,
!added.second || added.first->second->m_flatAsset.Asset().asset_header->uuid == p_uuid,
"Added ASSET UUID does not match !");
return added.second;
}
[[nodiscard]]
ASSET* Get(const UUID& p_uuid)
{
return m_assets.contains(p_uuid) ? &m_assets.at_key(p_uuid)->m_asset : nullptr;
}
[[nodiscard]]
const ASSET* Get(const UUID& p_uuid) const
{
return m_assets.contains(p_uuid) ? &m_assets.at_key(p_uuid)->m_asset : nullptr;
}
void Remove(const UUID& p_uuid)
{
m_assets.erase(p_uuid);
}
[[nodiscard]]
eastl::vector<std::byte> Pack(const UUID& p_uuid) const
{
return m_assets.contains(p_uuid) ? m_assets.at_key(p_uuid)->m_flatAsset.Pack() : eastl::vector<std::byte> {};
}
~AssetContainer() = default;
AssetContainer& operator=(const AssetContainer& p_container) = delete;
AssetContainer& operator=(AssetContainer&& p_container) = delete;
private:
struct AssetFlatAssetWrapperPair
{
AssetFlatAssetWrapperPair(const eastl::span<const std::byte> p_flatbuffer):
m_flatAsset(p_flatbuffer),
m_asset(&m_flatAsset)
{
}
FlatAssetWrapper<typename ASSET::FLAT_ASSET> m_flatAsset;
ASSET m_asset;
};
eastl::vector_map<UUID, eastl::unique_ptr<AssetFlatAssetWrapperPair>> m_assets;
};
} // namespace Bigfoot

View File

@@ -2,7 +2,8 @@ get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PackageName})
set(PublicDependencies
$<$<CONFIG:Debug,RelWithDebInfo>:cpptrace::cpptrace>)
$<$<CONFIG:Debug,RelWithDebInfo>:cpptrace::cpptrace>
unordered_dense::unordered_dense)
set(PrivateDependencies)
set(BigfootPublicDependencies)
set(BigfootPrivateDependencies)

View File

@@ -15,6 +15,7 @@
#include <Utils/Singleton.hpp>
#include <Utils/TargetMacros.h>
#include <EngineTests/BigFile/Asset/AssetA.hpp>
#include <EngineTests/BigFile/Asset/AssetA_generated.hpp>
#include <EngineTests/BigFileInfo_generated.hpp>
@@ -36,7 +37,7 @@ class BigFileFixture: public ::testing::Test
m_bigFile.CommitTransaction();
}
FlatAssetWrapper<Flat::AssetA> test;
AssetAContainer m_assetAContainer;
BIGFOOT_NOT_OPTIMIZED_ONLY(Singleton<Log>::Lifetime m_loggerLifetime;)
@@ -48,31 +49,36 @@ 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->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);
UUID uuid;
std::ignore = m_assetAContainer.Add(uuid, "Instance");
EXPECT_STREQ(test2.Asset().asset_header->name.c_str(), "Instance");
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);
AssetA* test = m_assetAContainer.Get(uuid);
test->Health() = 100;
test->Mana() = 42;
const eastl::vector<std::byte> flatbuffer = m_assetAContainer.Pack(uuid);
m_assetAContainer.Remove(uuid);
std::ignore = m_assetAContainer.Add(uuid, flatbuffer);
std::ignore = m_assetAContainer.Add(UUID {}, "Instance2");
std::ignore = m_assetAContainer.Add(UUID {}, "Instance3");
AssetA* test2 = m_assetAContainer.Get(uuid);
EXPECT_EQ(test2->Health(), 100);
EXPECT_EQ(test2->Mana(), 42);
EXPECT_STREQ(test2->AssetHeader()->name.c_str(), "Instance");
EXPECT_EQ(test2->AssetHeader()->type_id, FlatAssetWrapper<Flat::AssetA>::TypeID());
EXPECT_STREQ(test2->AssetHeader()->type_name.c_str(), FlatAssetWrapper<Flat::AssetA>::TypeName().data());
EXPECT_EQ(test2->AssetHeader()->uuid, uuid);
EXPECT_EQ(test2->AssetHeader()->version, 2);
}
UUID uuid;

View File

@@ -17,17 +17,50 @@ class AssetA
public:
using FLAT_ASSET = Flat::AssetA;
AssetA(const FlatAssetWrapper<Flat::AssetA>& p_flatAsset);
AssetA(FlatAssetWrapper<Flat::AssetA>* p_flatAsset):
m_flatAsset(p_flatAsset)
{
// deprecation...
if (m_flatAsset->Asset().asset_header->version < 2)
{
m_flatAsset->Asset().asset_header->version = 2;
}
}
AssetA(const AssetA& p_assetA) = default;
AssetA(AssetA&& p_assetA) = default;
[[nodiscard]]
std::uint32_t& Health()
{
return m_flatAsset->Asset().health;
}
[[nodiscard]]
std::uint32_t& Mana()
{
return m_flatAsset->Asset().mana;
}
[[nodiscard]]
Flat::AssetHeaderT* AssetHeader()
{
return m_flatAsset->Asset().asset_header.get();
}
[[nodiscard]]
const Flat::AssetHeaderT* AssetHeader() const
{
return m_flatAsset->Asset().asset_header.get();
}
~AssetA() = default;
AssetA& operator=(const AssetA& p_assetA) = default;
AssetA& operator=(AssetA&& p_assetA) = default;
private:
FlatAssetWrapper<Flat::AssetA>* m_flatAsset;
};
using AssetAContainer = AssetContainer<AssetA>;

View File

@@ -64,10 +64,10 @@ class Bigfoot(ConanFile):
def requirements(self):
self.requires("eastl/3.27.01@bigfootdev/main", transitive_headers=True)
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("mimalloc/3.2.8@bigfootdev/main", transitive_headers=True)
self.requires("stduuid/1.2.3@bigfootdev/main", transitive_headers=True)
self.requires("sqlite3/3.51.2@bigfootdev/main", transitive_headers=True)
self.requires("cli11/2.6.0")
self.requires("cli11/2.6.1@bigfootdev/main")
self.requires("rapidhash/3.0@bigfootdev/main", transitive_headers=True)
self.requires("effolkronium-random/1.5.0", transitive_headers=True)
self.requires("flatbuffers/25.12.19@bigfootdev/main", transitive_headers=True)
@@ -100,7 +100,7 @@ class Bigfoot(ConanFile):
self.requires("spirv-cross/1.4.313.0")
self.requires("shaderc/2025.3@bigfootdev/main")
self.requires("stb/cci.20240531", override=True)
self.requires("assimp/6.0.2")
self.requires("assimp/6.0.4@bigfootdev/main")
self.requires("meshoptimizer/1.0@bigfootdev/main")
self.requires("libsquish/1.15")