BigFile implementing DataAccessor
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 13m52s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 14m16s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 14m17s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 13m52s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 14m22s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 14m48s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m0s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 14m30s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 15m27s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 15m5s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 16m44s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 14m45s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m25s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m28s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 14m57s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 17m22s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 17m23s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 15m12s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 16m53s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 15m1s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 16m9s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 16m7s
Bigfoot / Clang Format Checks (push) Failing after 10s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 16m20s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 16m1s
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 13m52s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 14m16s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 14m17s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 13m52s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 14m22s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 14m48s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m0s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 14m30s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 15m27s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 15m5s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 16m44s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 14m45s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m25s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m28s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 14m57s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 17m22s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 17m23s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 15m12s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 16m53s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 15m1s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 16m9s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 16m7s
Bigfoot / Clang Format Checks (push) Failing after 10s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 16m20s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 16m1s
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
#ifdef BIGFOOT_TOOLMODE
|
||||
BigFile::BigFile(const File& p_file)
|
||||
{
|
||||
[[maybe_unused]]
|
||||
@@ -59,6 +60,85 @@ BigFile::~BigFile()
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
eastl::vector<std::byte> BigFile::GetAssetFlatbuffer(const UUID& p_uuid) const
|
||||
{
|
||||
BigFile::Request assetRequest {*this,
|
||||
"SELECT Asset.Asset FROM Asset "
|
||||
"JOIN AssetMetadata ON AssetMetadata.UUID = Asset.UUID "
|
||||
"WHERE Asset.UUID = ?1;"};
|
||||
assetRequest.Bind(1, p_uuid.ToBytes());
|
||||
|
||||
if (!assetRequest.Step())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
const eastl::span<const std::byte> flatbuffer = assetRequest.Get(0);
|
||||
return eastl::vector<std::byte> {flatbuffer.begin(), flatbuffer.end()};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
AssetMetadata BigFile::GetAssetMetadata(const UUID& p_uuid) const
|
||||
{
|
||||
BigFile::Request assetRequest {
|
||||
*this,
|
||||
"SELECT UUID, Name, TypeID, TypeName, CreateTime, ModificationTime FROM AssetMetadata WHERE UUID = ?1;"};
|
||||
assetRequest.Bind(1, p_uuid.ToBytes());
|
||||
|
||||
if (!assetRequest.Step())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return AssetMetadata {.m_uuid = UUID {std::span<const std::byte, UUID::UUID_BYTE_SIZE> {
|
||||
static_cast<eastl::span<const std::byte>>(assetRequest.Get(0)).data(),
|
||||
UUID::UUID_BYTE_SIZE}},
|
||||
.m_name = eastl::string {static_cast<eastl::string_view>(assetRequest.Get(1))},
|
||||
.m_typeID = assetRequest.Get(2),
|
||||
.m_typeName = eastl::string {static_cast<eastl::string_view>(assetRequest.Get(3))},
|
||||
.m_creationTime = Time {static_cast<std::uint64_t>(assetRequest.Get(4))},
|
||||
.m_modificationTime = Time {static_cast<std::uint64_t>(assetRequest.Get(5))}};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
void BigFile::SaveAssetFlatbuffer(const AssetMetadata& p_metadata, const eastl::span<const std::byte> p_flatbuffer)
|
||||
{
|
||||
BeginTransaction();
|
||||
|
||||
BigFile::Request metadataRequest {
|
||||
*this,
|
||||
"INSERT INTO AssetMetadata (UUID, Name, TypeID, TypeName) VALUES (?1, ?2, ?3, ?4) "
|
||||
"ON CONFLICT(UUID) DO UPDATE SET Name = excluded.Name, TypeID = excluded.TypeID, TypeName = excluded.TypeName;"};
|
||||
metadataRequest.Bind(1, p_metadata.m_uuid.ToBytes());
|
||||
metadataRequest.Bind(2, p_metadata.m_name);
|
||||
metadataRequest.Bind(3, p_metadata.m_typeID);
|
||||
metadataRequest.Bind(4, p_metadata.m_typeName);
|
||||
metadataRequest.Execute();
|
||||
|
||||
BigFile::Request assetRequest {*this,
|
||||
"INSERT INTO Asset (UUID, Asset) VALUES (?1, ?2) "
|
||||
"ON CONFLICT(UUID) DO UPDATE SET Asset = excluded.Asset;"};
|
||||
assetRequest.Bind(1, p_metadata.m_uuid.ToBytes());
|
||||
assetRequest.Bind(2, p_flatbuffer);
|
||||
assetRequest.Execute();
|
||||
|
||||
CommitTransaction();
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
bool BigFile::Has(const UUID& p_uuid) const
|
||||
{
|
||||
BigFile::Request request {*this, "SELECT 1 FROM AssetMetadata WHERE UUID = ?1;"};
|
||||
request.Bind(1, p_uuid.ToBytes());
|
||||
|
||||
return request.Step();
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
BigFile::Request::Request(const BigFile& p_bigFile, const eastl::string_view p_request):
|
||||
m_db(p_bigFile.m_db)
|
||||
{
|
||||
@@ -296,4 +376,5 @@ BigFile::Request::~Request()
|
||||
const int result = sqlite3_finalize(m_statement);
|
||||
CRITICAL_ASSERT(EngineAssertHandler, result == SQLITE_OK, "Failed to finalize statement: {}", sqlite3_errmsg(m_db));
|
||||
}
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
PRAGMA journal_mode=WAL;
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS AssetHeader (
|
||||
CREATE TABLE IF NOT EXISTS AssetMetadata (
|
||||
UUID BLOB NOT NULL UNIQUE,
|
||||
Name TEXT NOT NULL UNIQUE,
|
||||
TypeID INTEGER NOT NULL,
|
||||
TypeName TEXT NOT NULL,
|
||||
|
||||
CreateTime INTEGER NOT NULL DEFAULT(CAST(unixepoch('subsec') AS INTEGER) * 1000000),
|
||||
ModificationTime INTEGER NOT NULL DEFAULT(CAST(unixepoch('subsec') AS INTEGER) * 1000000),
|
||||
CreateTime INTEGER NOT NULL DEFAULT(CAST(unixepoch('subsec') * 1000000 AS INTEGER)),
|
||||
ModificationTime INTEGER NOT NULL DEFAULT(CAST(unixepoch('subsec') * 1000000 AS INTEGER)),
|
||||
|
||||
PRIMARY KEY(UUID)
|
||||
);
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS AssetHeader_UpdateTime
|
||||
AFTER UPDATE OF Name, TypeID, TypeName ON AssetHeader FOR EACH ROW
|
||||
CREATE TRIGGER IF NOT EXISTS AssetMetadata_UpdateTime
|
||||
AFTER UPDATE OF Name, TypeID, TypeName ON AssetMetadata FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE AssetHeader
|
||||
SET ModificationTime = CAST(unixepoch('subsec') AS INTEGER) * 1000000
|
||||
UPDATE AssetMetadata
|
||||
SET ModificationTime = CAST(unixepoch('subsec') * 1000000 AS INTEGER)
|
||||
WHERE UUID = NEW.UUID;
|
||||
END;
|
||||
|
||||
@@ -27,13 +27,13 @@ CREATE TABLE IF NOT EXISTS Asset (
|
||||
Asset BLOB NOT NULL,
|
||||
|
||||
PRIMARY KEY(UUID),
|
||||
FOREIGN KEY(UUID) REFERENCES AssetHeader(UUID) ON DELETE CASCADE
|
||||
FOREIGN KEY(UUID) REFERENCES AssetMetadata(UUID) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS Asset_UpdateTime
|
||||
AFTER UPDATE OF Asset ON Asset FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE AssetHeader
|
||||
SET ModificationTime = CAST(unixepoch('subsec') AS INTEGER) * 1000000
|
||||
UPDATE AssetMetadata
|
||||
SET ModificationTime = CAST(unixepoch('subsec') * 1000000 AS INTEGER)
|
||||
WHERE UUID = NEW.UUID;
|
||||
END;
|
||||
@@ -6,6 +6,8 @@
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_BIGFILE_BIGFILE_HPP
|
||||
#define BIGFOOT_ENGINE_BIGFILE_BIGFILE_HPP
|
||||
#include <Engine/DataAccessor/DataAccessor.hpp>
|
||||
|
||||
#include <System/File.hpp>
|
||||
|
||||
#include <Utils/TaggedType.hpp>
|
||||
@@ -15,7 +17,8 @@
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class BigFile
|
||||
#ifdef BIGFOOT_TOOLMODE
|
||||
class BigFile: public DataAccessor
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -48,6 +51,38 @@ class BigFile
|
||||
|
||||
~BigFile();
|
||||
|
||||
/**
|
||||
* Get an Asset flatbuffer
|
||||
*
|
||||
* \param p_uuid The asset to get the flatbuffer of
|
||||
* \return The flatbuffer, can be empty if asset was not found
|
||||
*/
|
||||
eastl::vector<std::byte> GetAssetFlatbuffer(const UUID& p_uuid) const override;
|
||||
|
||||
/**
|
||||
* Get an Asset metadata
|
||||
*
|
||||
* \param p_uuid The asset to get the metadata of
|
||||
* \return The metadata, default initialized if not found (ie: UUID = NULL)
|
||||
*/
|
||||
AssetMetadata GetAssetMetadata(const UUID& p_uuid) const override;
|
||||
|
||||
/**
|
||||
* Save an asset
|
||||
*
|
||||
* \p_metadata The metadata
|
||||
* \p_flatbuffer The flatbuffer of the asset
|
||||
*/
|
||||
void SaveAssetFlatbuffer(const AssetMetadata& p_metadata, const eastl::span<const std::byte> p_flatbuffer) override;
|
||||
|
||||
/**
|
||||
* Check if the Asset exists
|
||||
*
|
||||
* \param p_uuid The asset to check
|
||||
* \param True if it exists, false otherwise
|
||||
*/
|
||||
bool Has(const UUID& p_uuid) const override;
|
||||
|
||||
BigFile& operator=(const BigFile& p_bigFile) = delete;
|
||||
BigFile& operator=(BigFile&& p_bigFile) = delete;
|
||||
|
||||
@@ -140,7 +175,7 @@ class BigFile
|
||||
/*
|
||||
* Step through the request
|
||||
*
|
||||
* \return True if the request can continue (get next row), false otherwise
|
||||
* \return True if a row is available to read via Get(), false once the statement is done
|
||||
*/
|
||||
[[nodiscard]]
|
||||
bool Step();
|
||||
@@ -148,7 +183,7 @@ class BigFile
|
||||
/*
|
||||
* Execute the request once
|
||||
*
|
||||
* The number of modified rows
|
||||
* \return The number of rows modified by the statement
|
||||
*/
|
||||
[[maybe_unused]]
|
||||
std::uint32_t Execute();
|
||||
@@ -271,6 +306,7 @@ class BigFile
|
||||
*/
|
||||
sqlite3* m_db;
|
||||
};
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user