diff --git a/Bigfoot/Sources/Engine/BigFile/BigFile.cpp b/Bigfoot/Sources/Engine/BigFile/BigFile.cpp index 76bb1f1..230e3ed 100644 --- a/Bigfoot/Sources/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Sources/Engine/BigFile/BigFile.cpp @@ -115,6 +115,19 @@ void BigFile::Request::Bind(const std::uint32_t p_index, const std::int64_t p_va /****************************************************************************************/ +void BigFile::Request::Bind(const std::uint32_t p_index, const std::uint64_t p_value) +{ + ASSERT(EngineAssertHandler, + (p_index >= 1) && (p_index <= static_cast(sqlite3_bind_parameter_count(m_statement))), + "Invalid index for statement"); + + [[maybe_unused]] + const int result = sqlite3_bind_int64(m_statement, p_index, std::bit_cast(p_value)); + ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to bind value for statement: {}", sqlite3_errmsg(m_db)); +} + +/****************************************************************************************/ + void BigFile::Request::Bind(const std::uint32_t p_index, const float p_value) { ASSERT(EngineAssertHandler, @@ -230,6 +243,13 @@ BigFile::Request::Column::operator std::int64_t() const /****************************************************************************************/ +BigFile::Request::Column::operator std::uint64_t() const +{ + return std::bit_cast(sqlite3_column_int64(m_statement, m_index)); +} + +/****************************************************************************************/ + BigFile::Request::Column::operator float() const { return static_cast(sqlite3_column_double(m_statement, m_index)); diff --git a/Bigfoot/Sources/Engine/BigFile/BigFileSchema.sql b/Bigfoot/Sources/Engine/BigFile/BigFileSchema.sql index e307f48..e329324 100644 --- a/Bigfoot/Sources/Engine/BigFile/BigFileSchema.sql +++ b/Bigfoot/Sources/Engine/BigFile/BigFileSchema.sql @@ -1,7 +1,6 @@ PRAGMA journal_mode=WAL; PRAGMA foreign_keys = ON; -DROP TABLE IF EXISTS AssetHeader; CREATE TABLE IF NOT EXISTS AssetHeader ( UUID BLOB NOT NULL UNIQUE, Name TEXT NOT NULL UNIQUE, @@ -22,7 +21,6 @@ BEGIN WHERE UUID = NEW.UUID; END; -DROP TABLE IF EXISTS Asset; CREATE TABLE IF NOT EXISTS Asset ( UUID BLOB NOT NULL UNIQUE, diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp index 528371d..9a284a0 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp @@ -51,7 +51,7 @@ class Asset flatbuffers::GetRoot(asset->inner_asset()->data())->UnPackTo(&m_asset, nullptr); } - Asset(const Asset& p_asset) = default; + Asset(const Asset& p_asset) = delete; Asset(Asset&& p_asset) = default; ~Asset() = default; @@ -75,7 +75,7 @@ class Asset } [[nodiscard]] - eastl::vector Save() + eastl::vector Save() const { flatbuffers::FlatBufferBuilder innerAssetFbb; innerAssetFbb.Finish(FLAT_ASSET::Pack(innerAssetFbb, &m_asset)); @@ -116,7 +116,7 @@ class Asset return FLAT_ASSET::GetFullyQualifiedName(); } - Asset& operator=(const Asset& p_asset) = default; + Asset& operator=(const Asset& p_asset) = delete; Asset& operator=(Asset&& p_asset) = default; private: diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp index ba6d270..57c7f60 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp @@ -29,7 +29,10 @@ class AssetContainer AssetContainer(const AssetContainer&) = delete; AssetContainer& operator=(const AssetContainer&) = delete; - ~AssetContainer() = default; + ~AssetContainer() + { + ms_instance = nullptr; + } struct Entry { @@ -44,9 +47,14 @@ class AssetContainer void DecrementHardRefCount(const UUID& p_uuid) { - if (m_entries.contains(p_uuid)) + if (const auto entry = m_entries.find(p_uuid); entry != m_entries.end()) { - --m_entries.at(p_uuid).m_hardRefCount; + CRITICAL_ASSERT( + EngineAssertHandler, + entry->second.m_hardRefCount > 0, + "Double release detected! Decrementing a hard reference to an asset that already does not have any " + "more hardrefs"); + --entry->second.m_hardRefCount; } } @@ -57,22 +65,29 @@ class AssetContainer void DecrementSoftRefCount(const UUID& p_uuid) { - if (m_entries.contains(p_uuid)) + if (const auto entry = m_entries.find(p_uuid); entry != m_entries.end()) { - --m_entries.at(p_uuid).m_softRefCount; + CRITICAL_ASSERT( + EngineAssertHandler, + entry->second.m_softRefCount > 0, + "Double release detected! Decrementing a soft reference to an asset that already does not have any " + "more softrefs"); + --entry->second.m_softRefCount; } } [[nodiscard]] std::uint32_t HardRefCount(const UUID& p_uuid) const { - return m_entries.contains(p_uuid) ? m_entries.at(p_uuid).m_hardRefCount : 0; + const auto entry = m_entries.find(p_uuid); + return entry != m_entries.end() ? entry->second.m_hardRefCount : 0; } [[nodiscard]] std::uint32_t SoftRefCount(const UUID& p_uuid) const { - return m_entries.contains(p_uuid) ? m_entries.at(p_uuid).m_softRefCount : 0; + const auto entry = m_entries.find(p_uuid); + return entry != m_entries.end() ? entry->second.m_softRefCount : 0; } [[nodiscard]] diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetHelper.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetHelper.hpp index dc7f3ad..134be0d 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetHelper.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetHelper.hpp @@ -56,13 +56,13 @@ #define ASSET_HARD_REF_IMPL(AssetName, AssetType) \ namespace flatbuffers \ { \ - Flat::Bigfoot::HardReference PackHardReference##AssetName(const Bigfoot::HardReference& p_softRef) \ + Flat::Bigfoot::HardReference PackHardReference##AssetName(const Bigfoot::HardReference& p_hardRef) \ { \ - return {flatbuffers::Pack(p_softRef.GetUUID())}; \ + return {flatbuffers::Pack(p_hardRef.GetUUID())}; \ } \ - Bigfoot::HardReference UnPackHardReference##AssetName(const Flat::Bigfoot::HardReference& p_softRef) \ + Bigfoot::HardReference UnPackHardReference##AssetName(const Flat::Bigfoot::HardReference& p_hardRef) \ { \ - return {flatbuffers::UnPack(p_softRef.uuid())}; \ + return {flatbuffers::UnPack(p_hardRef.uuid())}; \ } \ } diff --git a/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp b/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp index 0fd7d20..da47512 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/BigFile/BigFile.hpp @@ -63,8 +63,8 @@ class BigFile */ Request(const BigFile& p_bigFile, const eastl::string_view p_request); - Request(const Request& p_request) = default; - Request(Request&& p_request) = default; + Request(const Request& p_request) = delete; + Request(Request&& p_request) = delete; using CopyValue = TaggedType; @@ -92,6 +92,14 @@ class BigFile */ void Bind(const std::uint32_t p_index, const std::int64_t p_value); + /* + * Bind a uint64 value to the Request at index + * + * \param p_index The index to bind to + * \param p_value The value + */ + void Bind(const std::uint32_t p_index, const std::uint64_t p_value); + /* * Bind a float value to the Request at index * @@ -186,6 +194,13 @@ class BigFile */ operator std::int64_t() const; + /* + * Get value as a uint64 + * + * \return The value + */ + operator std::uint64_t() const; + /* * Get value as a float * @@ -236,8 +251,8 @@ class BigFile ~Request(); - Request& operator=(const Request& p_request) = default; - Request& operator=(Request&& p_request) = default; + Request& operator=(const Request& p_request) = delete; + Request& operator=(Request&& p_request) = delete; private: /* diff --git a/Bigfoot/Tests/Engine/Asset/Asset.cpp b/Bigfoot/Tests/Engine/Asset/Asset.cpp index c0d4b11..b5166ed 100644 --- a/Bigfoot/Tests/Engine/Asset/Asset.cpp +++ b/Bigfoot/Tests/Engine/Asset/Asset.cpp @@ -17,8 +17,6 @@ #include #include -#include - #include namespace Bigfoot @@ -218,6 +216,4 @@ TEST_F(AssetFixture, AssetCTests) HardReference {assetAA.GetHeader().uuid}})); EXPECT_EQ(assetC.GetAsset().inner_table->asset_a_refs, assetC_dup.GetAsset().inner_table->asset_a_refs); } - -TEST_F(AssetFixture, MiniReflect) { } } // namespace Bigfoot diff --git a/Bigfoot/Tests/Engine/BigFile/BigFile.cpp b/Bigfoot/Tests/Engine/BigFile/BigFile.cpp index aad2152..0a9315f 100644 --- a/Bigfoot/Tests/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Tests/Engine/BigFile/BigFile.cpp @@ -53,10 +53,12 @@ TEST_F(BigFileFixture, BigFileManipulation) UUID uuid2; UUID uuid3; - eastl::array blob {std::byte {1}, std::byte {2}, std::byte {3}, std::byte {4}}; - eastl::array blob2 {std::byte {1}, std::byte {2}, std::byte {3}, std::byte {5}}; - eastl::array blob3 {std::byte {1}, std::byte {2}, std::byte {3}, std::byte {6}}; - eastl::array blob4 {std::byte {10}, std::byte {11}, std::byte {12}, std::byte {13}}; + constexpr eastl::array blob {std::byte {1}, std::byte {2}, std::byte {3}, std::byte {4}}; + constexpr eastl::array blob2 {std::byte {1}, std::byte {2}, std::byte {3}, std::byte {5}}; + constexpr eastl::array blob3 {std::byte {1}, std::byte {2}, std::byte {3}, std::byte {6}}; + constexpr eastl::array blob4 {std::byte {10}, std::byte {11}, std::byte {12}, std::byte {13}}; + + constexpr std::uint64_t typeIDRef = std::numeric_limits::max() - 1; { BigFile::Request assetHeaderRequest { @@ -64,7 +66,7 @@ TEST_F(BigFileFixture, BigFileManipulation) "INSERT INTO AssetHeader (UUID, Name, TypeID, TypeName) VALUES(?, ?, ?, ?)"}; assetHeaderRequest.Bind(1, static_cast>(uuid)); assetHeaderRequest.Bind(2, "Test"); - assetHeaderRequest.Bind(3, 42); + assetHeaderRequest.Bind(3, typeIDRef); assetHeaderRequest.Bind(4, "TypeTest"); BigFile::Request assetRequest {m_bigFile, "INSERT INTO Asset (UUID, Asset) VALUES(?, ?)"}; @@ -76,7 +78,7 @@ TEST_F(BigFileFixture, BigFileManipulation) "INSERT INTO AssetHeader (UUID, Name, TypeID, TypeName) VALUES(?, ?, ?, ?)"}; assetHeaderRequest2.Bind(1, static_cast>(uuid2)); assetHeaderRequest2.Bind(2, "Test2"); - assetHeaderRequest2.Bind(3, 42); + assetHeaderRequest2.Bind(3, typeIDRef); assetHeaderRequest2.Bind(4, "TypeTest"); BigFile::Request assetRequest2 {m_bigFile, "INSERT INTO Asset (UUID, Asset) VALUES(?, ?)"}; @@ -88,7 +90,7 @@ TEST_F(BigFileFixture, BigFileManipulation) "INSERT INTO AssetHeader (UUID, Name, TypeID, TypeName) VALUES(?, ?, ?, ?)"}; assetHeaderRequest3.Bind(1, static_cast>(uuid3)); assetHeaderRequest3.Bind(2, "Test3"); - assetHeaderRequest3.Bind(3, 42); + assetHeaderRequest3.Bind(3, typeIDRef); assetHeaderRequest3.Bind(4, "TypeTest"); BigFile::Request assetRequest3 {m_bigFile, "INSERT INTO Asset (UUID, Asset) VALUES(?, ?)"}; @@ -96,20 +98,20 @@ TEST_F(BigFileFixture, BigFileManipulation) assetRequest3.Bind(2, blob4); m_bigFile.BeginTransaction(); - [[maybe_unused]] std::uint32_t assetHeaderChangedCount = assetHeaderRequest.Execute(); - [[maybe_unused]] + EXPECT_EQ(assetHeaderChangedCount, 1); std::uint32_t assetChangedCount = assetRequest.Execute(); + EXPECT_EQ(assetChangedCount, 1); - [[maybe_unused]] std::uint32_t assetHeaderChangedCount2 = assetHeaderRequest2.Execute(); - [[maybe_unused]] + EXPECT_EQ(assetHeaderChangedCount2, 1); std::uint32_t assetChangedCount2 = assetRequest2.Execute(); + EXPECT_EQ(assetChangedCount2, 1); - [[maybe_unused]] std::uint32_t assetHeaderChangedCount3 = assetHeaderRequest3.Execute(); - [[maybe_unused]] + EXPECT_EQ(assetHeaderChangedCount3, 1); std::uint32_t assetChangedCount3 = assetRequest3.Execute(); + EXPECT_EQ(assetChangedCount3, 1); m_bigFile.CommitTransaction(); } @@ -120,8 +122,8 @@ TEST_F(BigFileFixture, BigFileManipulation) updateAsset.Bind(2, static_cast>(uuid)); m_bigFile.BeginTransaction(); - [[maybe_unused]] std::uint32_t updateAssetChangedCount = updateAsset.Execute(); + EXPECT_EQ(updateAssetChangedCount, 1); m_bigFile.CommitTransaction(); } @@ -131,53 +133,26 @@ TEST_F(BigFileFixture, BigFileManipulation) "SELECT Name, TypeID, TypeName, CreateTime, ModificationTime FROM AssetHeader WHERE UUID = ?"}; request.Bind(1, static_cast>(uuid)); - [[maybe_unused]] const bool get = request.Step(); + EXPECT_TRUE(get); - [[maybe_unused]] const eastl::string name {static_cast(request.Get(0))}; - [[maybe_unused]] - const std::uint32_t typeId = request.Get(1); - [[maybe_unused]] + EXPECT_STREQ(name.c_str(), "Test"); + const std::uint64_t typeID = static_cast(request.Get(1)); + EXPECT_EQ(typeID, typeIDRef); const eastl::string typeName {static_cast(request.Get(2))}; - [[maybe_unused]] - const Time createTime = static_cast(request.Get(3)); - [[maybe_unused]] - const Time modificationTime = static_cast(request.Get(4)); + EXPECT_STREQ(typeName.c_str(), "TypeTest"); - { - [[maybe_unused]] - const std::uint32_t year = createTime.Year(); - [[maybe_unused]] - const std::uint32_t month = createTime.Month(); - [[maybe_unused]] - const std::uint32_t day = createTime.Day(); - [[maybe_unused]] - const std::uint32_t hour = createTime.Hour(); - [[maybe_unused]] - const std::uint32_t minute = createTime.Minute(); - [[maybe_unused]] - const std::uint32_t second = createTime.Second(); - [[maybe_unused]] - const std::uint32_t microsecond = createTime.Microsecond(); - } + const Time createTime = static_cast(request.Get(3)); + const Time modificationTime = static_cast(request.Get(4)); - { - [[maybe_unused]] - const std::uint32_t year = modificationTime.Year(); - [[maybe_unused]] - const std::uint32_t month = modificationTime.Month(); - [[maybe_unused]] - const std::uint32_t day = modificationTime.Day(); - [[maybe_unused]] - const std::uint32_t hour = modificationTime.Hour(); - [[maybe_unused]] - const std::uint32_t minute = modificationTime.Minute(); - [[maybe_unused]] - const std::uint32_t second = modificationTime.Second(); - [[maybe_unused]] - const std::uint32_t microsecond = modificationTime.Microsecond(); - } + EXPECT_GT(createTime.Epoch(), 0); + EXPECT_GT(modificationTime.Epoch(), 0); + + EXPECT_GE(createTime, modificationTime); + + EXPECT_GT(createTime.Year(), 2025); + EXPECT_GT(modificationTime.Year(), 2025); } } } // namespace Bigfoot diff --git a/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetA.hpp b/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetA.hpp index 1a8bf02..41fcfd2 100644 --- a/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetA.hpp +++ b/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetA.hpp @@ -27,12 +27,12 @@ class AssetA: public Asset { } - AssetA(const AssetA& p_asset) = default; + AssetA(const AssetA& p_asset) = delete; AssetA(AssetA&& p_asset) = default; ~AssetA() = default; - AssetA& operator=(const AssetA& p_asset) = default; + AssetA& operator=(const AssetA& p_asset) = delete; AssetA& operator=(AssetA&& p_asset) = default; }; } // namespace Bigfoot diff --git a/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetB.hpp b/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetB.hpp index 296b8e9..768efdb 100644 --- a/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetB.hpp +++ b/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetB.hpp @@ -27,12 +27,12 @@ class AssetB: public Asset { } - AssetB(const AssetB& p_asset) = default; + AssetB(const AssetB& p_asset) = delete; AssetB(AssetB&& p_asset) = default; ~AssetB() = default; - AssetB& operator=(const AssetB& p_asset) = default; + AssetB& operator=(const AssetB& p_asset) = delete; AssetB& operator=(AssetB&& p_asset) = default; }; } // namespace Bigfoot diff --git a/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetC.hpp b/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetC.hpp index 28817c7..0488a91 100644 --- a/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetC.hpp +++ b/Bigfoot/Tests/Engine/Include/EngineTests/Asset/AssetC.hpp @@ -30,12 +30,12 @@ class AssetC: public Asset { } - AssetC(const AssetC& p_asset) = default; + AssetC(const AssetC& p_asset) = delete; AssetC(AssetC&& p_asset) = default; ~AssetC() = default; - AssetC& operator=(const AssetC& p_asset) = default; + AssetC& operator=(const AssetC& p_asset) = delete; AssetC& operator=(AssetC&& p_asset) = default; }; } // namespace Bigfoot