Initial commit
This commit is contained in:
3
Bigfoot/Sources/CMakeLists.txt
Normal file
3
Bigfoot/Sources/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/System)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Utils)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Engine)
|
||||
11
Bigfoot/Sources/Engine/BigFile/BigFileSchema.sql
Normal file
11
Bigfoot/Sources/Engine/BigFile/BigFileSchema.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
PRAGMA journal_mode=WAL;
|
||||
|
||||
DROP TABLE IF EXISTS FsEntry;
|
||||
CREATE TABLE IF NOT EXISTS FsEntry (
|
||||
UUID BLOB NOT NULL UNIQUE,
|
||||
Name TEXT NOT NULL UNIQUE,
|
||||
CreateTime INTEGER NOT NULL,
|
||||
ModificationTime INTEGER NOT NULL,
|
||||
Asset BLOB,
|
||||
PRIMARY KEY(UUID)
|
||||
);
|
||||
12
Bigfoot/Sources/Engine/BigFile/Database.cpp
Normal file
12
Bigfoot/Sources/Engine/BigFile/Database.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
/*********************************************************************
|
||||
* \file Database.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <Engine/BigFile/Database.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
|
||||
} // namespace Bigfoot
|
||||
0
Bigfoot/Sources/Engine/BigFile/Statement.cpp
Normal file
0
Bigfoot/Sources/Engine/BigFile/Statement.cpp
Normal file
24
Bigfoot/Sources/Engine/CMakeLists.txt
Normal file
24
Bigfoot/Sources/Engine/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
set(PublicDependencies
|
||||
SQLite::SQLite3)
|
||||
set(PrivateDependencies)
|
||||
set(BigfootPublicDependencies
|
||||
Utils)
|
||||
set(BigfootPrivateDependencies)
|
||||
|
||||
set(BIGFOOT_MAJOR 0)
|
||||
set(BIGFOOT_MINOR 1)
|
||||
set(BIGFOOT_PATCH 0)
|
||||
set(BIGFOOT_NAME "Bigfoot")
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Include/Engine/EngineInfo.generated.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/Include/Engine/EngineInfo.generated.hpp @ONLY)
|
||||
|
||||
bigfoot_create_logger(${PackageName})
|
||||
|
||||
bigfoot_create_package_lib(
|
||||
${PackageName}
|
||||
"${PublicDependencies}"
|
||||
"${PrivateDependencies}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"")
|
||||
@@ -0,0 +1,19 @@
|
||||
@AUTO_GENERATED_COMMENT@
|
||||
|
||||
/*********************************************************************
|
||||
* \file BigFileInfo.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_BIGFILE_BIGFILEINFO_GENERATED_HPP
|
||||
#define BIGFOOT_ENGINE_BIGFILE_BIGFILEINFO_GENERATED_HPP
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* BigFile location
|
||||
*/
|
||||
constexpr std::string_view BIGFILE_@BIGFILE_NAME@_LOCATION{"@BIGFILE_LOCATION@"};
|
||||
}
|
||||
#endif
|
||||
19
Bigfoot/Sources/Engine/Include/Engine/BigFile/Database.hpp
Normal file
19
Bigfoot/Sources/Engine/Include/Engine/BigFile/Database.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/*********************************************************************
|
||||
* \file Database.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_BIGFILE_DATABASE_HPP
|
||||
#define BIGFOOT_ENGINE_BIGFILE_DATABASE_HPP
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file EngineInfo.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_ENGINEINFO_GENERATED_HPP
|
||||
#define BIGFOOT_ENGINE_ENGINEINFO_GENERATED_HPP
|
||||
#include <Utils/Version.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* Engine version
|
||||
*/
|
||||
constexpr Version BIGFOOT_VERSION{0, 1, 0};
|
||||
|
||||
/*
|
||||
* Engine name
|
||||
*/
|
||||
constexpr std::string_view BIGFOOT_NAME{"Bigfoot"};
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
@AUTO_GENERATED_COMMENT@
|
||||
|
||||
/*********************************************************************
|
||||
* \file EngineInfo.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_ENGINEINFO_GENERATED_HPP
|
||||
#define BIGFOOT_ENGINE_ENGINEINFO_GENERATED_HPP
|
||||
#include <Utils/Version.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* Engine version
|
||||
*/
|
||||
constexpr Version BIGFOOT_VERSION{@BIGFOOT_MAJOR@, @BIGFOOT_MINOR@, @BIGFOOT_PATCH@};
|
||||
|
||||
/*
|
||||
* Engine name
|
||||
*/
|
||||
constexpr std::string_view BIGFOOT_NAME{"@BIGFOOT_NAME@"};
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file EngineLogger.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINELOGGER_GENERATED_HPP
|
||||
#define BIGFOOT_ENGINELOGGER_GENERATED_HPP
|
||||
#include <Utils/Log.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
inline Log::LoggerInfo ENGINE_LOGGER {"ENGINE_LOGGER", Log::LogLevel::Trace};
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
26
Bigfoot/Sources/System/CMakeLists.txt
Normal file
26
Bigfoot/Sources/System/CMakeLists.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
set(PublicDependencies
|
||||
mimalloc
|
||||
magic_enum::magic_enum
|
||||
unordered_dense::unordered_dense
|
||||
EASTL::EASTL
|
||||
stduuid::stduuid
|
||||
$<$<BOOL:${TRACY}>:Tracy::TracyClient>)
|
||||
set(PrivateDependencies)
|
||||
set(BigfootPublicDependencies)
|
||||
set(BigfootPrivateDependencies)
|
||||
|
||||
bigfoot_create_package_lib(
|
||||
${PackageName}
|
||||
"${PublicDependencies}"
|
||||
"${PrivateLibraries}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"")
|
||||
|
||||
target_compile_definitions(${PackageName}
|
||||
PUBLIC MI_SHARED_LIB
|
||||
PUBLIC $<$<BOOL:${TRACY}>:TRACY>)
|
||||
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/MimallocImpl.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
|
||||
|
||||
64
Bigfoot/Sources/System/Include/System/Profiler.hpp
Normal file
64
Bigfoot/Sources/System/Include/System/Profiler.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*********************************************************************
|
||||
* \file Profiler.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_CONCAT_PROFILER_HPP
|
||||
#define BIGFOOT_CONCAT_PROFILER_HPP
|
||||
|
||||
#ifdef TRACY
|
||||
#include <tracy/Tracy.hpp>
|
||||
#define BIGFOOT_PROFILER_THREADNAME(p_name) tracy::SetThreadName(p_name)
|
||||
|
||||
#define BIGFOOT_PROFILER_FRAME() FrameMark
|
||||
#define BIGFOOT_PROFILER_FRAME_START(p_name) FrameMarkStart(p_name)
|
||||
#define BIGFOOT_PROFILER_FRAME_STOP(p_name) FrameMarkEnd(p_name)
|
||||
|
||||
#define BIGFOOT_PROFILER_PROFILE_FUNCTION() ZoneScoped
|
||||
#define BIGFOOT_PROFILER_PROFILE(p_name) ZoneScopedN(p_name)
|
||||
|
||||
#define BIGFOOT_PROFILER_TEXT(p_text, p_size) ZoneText(p_text, p_size)
|
||||
|
||||
#define BIGFOOT_PROFILER_MEMORY_ALLOC(p_ptr, p_size) TracyAlloc(p_ptr, p_size)
|
||||
#define BIGFOOT_PROFILER_MEMORY_FREE(p_ptr) TracyFree(p_ptr)
|
||||
|
||||
#define BIGFOOT_PROFILER_LOCKABLE(p_type, p_name) TracyLockable(p_type, p_name)
|
||||
#define BIGFOOT_PROFILER_LOCK(p_name) LockMark(p_name)
|
||||
|
||||
#define BIGFOOT_PROFILER_APPINFO(p_text, p_size) TracyAppInfo(p_text, p_size)
|
||||
|
||||
#define BIGFOOT_PROFILER_ATTACH_FRAME_IMAGE(p_imageData, p_width, p_height, p_offset) \
|
||||
FrameImage(p_imageData, p_width, p_height, p_offset, false)
|
||||
|
||||
#define BIGFOOT_PROFILER
|
||||
|
||||
#define BIGFOOT_PROFILER_ONLY(...) __VA_ARGS__
|
||||
// TODO: profile GPU
|
||||
#else
|
||||
#define BIGFOOT_PROFILER_THREADNAME(p_name)
|
||||
|
||||
#define BIGFOOT_PROFILER_FRAME()
|
||||
#define BIGFOOT_PROFILER_FRAME_START(p_name)
|
||||
#define BIGFOOT_PROFILER_FRAME_STOP(p_name)
|
||||
|
||||
#define BIGFOOT_PROFILER_PROFILE_FUNCTION()
|
||||
#define BIGFOOT_PROFILER_PROFILE(p_name)
|
||||
|
||||
#define BIGFOOT_PROFILER_TEXT_FUNCTION(p_text, p_size)
|
||||
#define BIGFOOT_PROFILER_TEXT(p_text, p_size)
|
||||
|
||||
#define BIGFOOT_PROFILER_MEMORY_ALLOC(p_ptr, p_size)
|
||||
#define BIGFOOT_PROFILER_MEMORY_FREE(p_ptr)
|
||||
|
||||
#define BIGFOOT_PROFILER_LOCKABLE(p_type, p_name) p_type p_name
|
||||
#define BIGFOOT_PROFILER_LOCK(p_name)
|
||||
|
||||
#define BIGFOOT_PROFILER_APPINFO(p_text, p_size)
|
||||
|
||||
#define BIGFOOT_PROFILER_ATTACH_FRAME_IMAGE(p_imageData, p_width, p_height, p_offset)
|
||||
|
||||
#define BIGFOOT_PROFILER_ONLY(...)
|
||||
// TODO: profile GPU
|
||||
#endif
|
||||
#endif
|
||||
106
Bigfoot/Sources/System/Include/System/UUID.hpp
Normal file
106
Bigfoot/Sources/System/Include/System/UUID.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*********************************************************************
|
||||
* \file UUID.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_SYSTEM_UUID_HPP
|
||||
#define BIGFOOT_SYSTEM_UUID_HPP
|
||||
|
||||
#include <uuid.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class UUID
|
||||
{
|
||||
public:
|
||||
static constexpr std::uint32_t UUID_BYTE_SIZE = 16;
|
||||
|
||||
UUID();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \param p_string String to create the UUID, should be a UUID V4
|
||||
*/
|
||||
explicit UUID(const std::string_view p_string);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param p_raw The raw UUID
|
||||
*/
|
||||
explicit UUID(const std::span<const std::byte, UUID_BYTE_SIZE> p_raw);
|
||||
|
||||
UUID(const UUID& p_uuid) = default;
|
||||
UUID(UUID&& p_uuid) noexcept = default;
|
||||
|
||||
~UUID() = default;
|
||||
|
||||
[[nodiscard]] operator std::span<const std::byte, UUID_BYTE_SIZE>() const;
|
||||
[[nodiscard]] operator std::string() const;
|
||||
[[nodiscard]] operator bool() const;
|
||||
|
||||
UUID& operator=(const UUID& p_uuid) = default;
|
||||
UUID& operator=(UUID&& p_uuid) noexcept = default;
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator==(const UUID& p_uuid) const = default;
|
||||
[[nodiscard]]
|
||||
bool operator!=(const UUID& p_uuid) const = default;
|
||||
[[nodiscard]]
|
||||
bool operator<(const UUID& p_uuid) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get a random generator
|
||||
*
|
||||
* \return A random generator
|
||||
*/
|
||||
static std::mt19937 GetRandomGenerator();
|
||||
|
||||
/**
|
||||
* Get a UUID generator
|
||||
*
|
||||
* \return A UUID generator
|
||||
*/
|
||||
static uuids::uuid_random_generator GetUUIDGenerator();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Null UUID.
|
||||
*/
|
||||
static UUID NULL_UUID;
|
||||
|
||||
private:
|
||||
friend struct std::hash<UUID>;
|
||||
|
||||
/**
|
||||
* The uuid.
|
||||
*/
|
||||
uuids::uuid m_uuid;
|
||||
|
||||
/**
|
||||
* Random generator for the UUID
|
||||
*/
|
||||
inline static std::mt19937 ms_randomGenerator = GetRandomGenerator();
|
||||
|
||||
/**
|
||||
* UUID generator
|
||||
*/
|
||||
inline static uuids::uuid_random_generator ms_uuidGenerator = GetUUIDGenerator();
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
template<>
|
||||
struct std::hash<Bigfoot::UUID>
|
||||
{
|
||||
std::size_t operator()(const Bigfoot::UUID& p_uuid) const noexcept
|
||||
{
|
||||
return std::hash<uuids::uuid>()(p_uuid.m_uuid);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
98
Bigfoot/Sources/System/MimallocImpl.cpp
Normal file
98
Bigfoot/Sources/System/MimallocImpl.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*********************************************************************
|
||||
* \file MimallocImpl.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <System/Profiler.hpp>
|
||||
|
||||
#if defined BIGFOOT_WINDOWS
|
||||
#pragma comment(linker, "/include:mi_version")
|
||||
#pragma warning(disable: 4100 4559)
|
||||
#elif defined BIGFOOT_LINUX
|
||||
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#else
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Taken from mimalloc-new-delete.h
|
||||
|
||||
// clang-format off
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// This header provides convenient overrides for the new and
|
||||
// delete operations in C++.
|
||||
//
|
||||
// This header should be included in only one source file!
|
||||
//
|
||||
// On Windows, or when linking dynamically with mimalloc, these
|
||||
// can be more performant than the standard new-delete operations.
|
||||
// See <https://en.cppreference.com/w/cpp/memory/new/operator_new>
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(__cplusplus)
|
||||
#include <new>
|
||||
#include <mimalloc.h>
|
||||
|
||||
#if defined(_MSC_VER) && defined(_Ret_notnull_) && defined(_Post_writable_byte_size_)
|
||||
// stay consistent with VCRT definitions
|
||||
#define mi_decl_new(n) mi_decl_nodiscard mi_decl_restrict _Ret_notnull_ _Post_writable_byte_size_(n)
|
||||
#define mi_decl_new_nothrow(n) mi_decl_nodiscard mi_decl_restrict _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(n)
|
||||
#else
|
||||
#define mi_decl_new(n) mi_decl_nodiscard mi_decl_restrict
|
||||
#define mi_decl_new_nothrow(n) mi_decl_nodiscard mi_decl_restrict
|
||||
#endif
|
||||
|
||||
void operator delete(void* p) noexcept { mi_free(p); BIGFOOT_PROFILER_MEMORY_FREE(p); };
|
||||
void operator delete[](void* p) noexcept { mi_free(p); BIGFOOT_PROFILER_MEMORY_FREE(p); };
|
||||
|
||||
void operator delete (void* p, const std::nothrow_t&) noexcept { mi_free(p); BIGFOOT_PROFILER_MEMORY_FREE(p); }
|
||||
void operator delete[](void* p, const std::nothrow_t&) noexcept { mi_free(p); BIGFOOT_PROFILER_MEMORY_FREE(p); }
|
||||
|
||||
mi_decl_new(n) void* operator new(std::size_t n) noexcept(false) { void* p = mi_new(n); BIGFOOT_PROFILER_MEMORY_ALLOC(p, n); return p; }
|
||||
mi_decl_new(n) void* operator new[](std::size_t n) noexcept(false) { void* p = mi_new(n); BIGFOOT_PROFILER_MEMORY_ALLOC(p, n); return p; }
|
||||
|
||||
mi_decl_new_nothrow(n) void* operator new (std::size_t n, const std::nothrow_t& tag) noexcept { (void)(tag); void* p = mi_new_nothrow(n); BIGFOOT_PROFILER_MEMORY_ALLOC(p, n); return p; }
|
||||
mi_decl_new_nothrow(n) void* operator new[](std::size_t n, const std::nothrow_t& tag) noexcept { (void)(tag); void* p = mi_new_nothrow(n); BIGFOOT_PROFILER_MEMORY_ALLOC(p, n); return p; }
|
||||
|
||||
// Not from mimalloc-new-delete.h, but necessary for EASTL
|
||||
void* operator new[](size_t size, const char* name, int flags, unsigned debugFlags, const char* file, int line) noexcept(false) { void* p = mi_new(size); BIGFOOT_PROFILER_MEMORY_ALLOC(p, size); return p; }
|
||||
|
||||
#if (__cplusplus >= 201402L || _MSC_VER >= 1916)
|
||||
void operator delete (void* p, std::size_t n) noexcept { mi_free_size(p,n); BIGFOOT_PROFILER_MEMORY_FREE(p); };
|
||||
void operator delete[](void* p, std::size_t n) noexcept { mi_free_size(p,n); BIGFOOT_PROFILER_MEMORY_FREE(p); };
|
||||
#endif
|
||||
|
||||
#if (__cplusplus > 201402L || defined(__cpp_aligned_new))
|
||||
void operator delete (void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_FREE(p); }
|
||||
void operator delete[](void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_FREE(p); }
|
||||
void operator delete (void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_FREE(p); };
|
||||
void operator delete[](void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_FREE(p); };
|
||||
void operator delete (void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_FREE(p); }
|
||||
void operator delete[](void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_FREE(p); }
|
||||
|
||||
void* operator new (std::size_t n, std::align_val_t al) noexcept(false) { void* p = mi_new_aligned(n, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_ALLOC(p, n); return p; }
|
||||
void* operator new[](std::size_t n, std::align_val_t al) noexcept(false) { void* p = mi_new_aligned(n, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_ALLOC(p, n); return p; }
|
||||
void* operator new (std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { void* p = mi_new_aligned_nothrow(n, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_ALLOC(p, n); return p; }
|
||||
void* operator new[](std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { void* p = mi_new_aligned_nothrow(n, static_cast<size_t>(al)); BIGFOOT_PROFILER_MEMORY_ALLOC(p, n); return p; }
|
||||
|
||||
// Not from mimalloc-new-delete.h, but necessary for EASTL
|
||||
void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, const char* pName, int flags, unsigned debugFlags, const char* file, int line) noexcept(false) { void* p = mi_new_aligned(size, alignment); BIGFOOT_PROFILER_MEMORY_ALLOC(p, size); return p; }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
#if defined BIGFOOT_WINDOWS
|
||||
#pragma warning(default: 4100 4559)
|
||||
#elif defined BIGFOOT_LINUX
|
||||
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
|
||||
#pragma GCC diagnostic pop
|
||||
#else
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
#endif
|
||||
87
Bigfoot/Sources/System/UUID.cpp
Normal file
87
Bigfoot/Sources/System/UUID.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*********************************************************************
|
||||
* \file UUID.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <System/UUID.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
UUID UUID::NULL_UUID {"00000000-0000-0000-0000-000000000000"};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
UUID::UUID():
|
||||
m_uuid(ms_uuidGenerator())
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
UUID::UUID(const std::string_view p_string):
|
||||
UUID(NULL_UUID)
|
||||
{
|
||||
if (const std::optional<uuids::uuid> value = uuids::uuid::from_string(p_string); value.has_value())
|
||||
{
|
||||
m_uuid = value.value();
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
UUID::UUID(const std::span<const std::byte, UUID_BYTE_SIZE> p_raw)
|
||||
{
|
||||
const std::span<std::uint8_t, UUID_BYTE_SIZE> raw {
|
||||
const_cast<std::uint8_t*>(std::bit_cast<const std::uint8_t*>(p_raw.data())),
|
||||
UUID_BYTE_SIZE};
|
||||
|
||||
m_uuid = uuids::uuid {raw};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
UUID::operator std::span<const std::byte, UUID::UUID_BYTE_SIZE>() const
|
||||
{
|
||||
return m_uuid.as_bytes();
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
UUID::operator std::string() const
|
||||
{
|
||||
return uuids::to_string(m_uuid);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
UUID::operator bool() const
|
||||
{
|
||||
return *this != NULL_UUID;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
bool UUID::operator<(const UUID& p_uuid) const
|
||||
{
|
||||
return m_uuid < p_uuid.m_uuid;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
std::mt19937 UUID::GetRandomGenerator()
|
||||
{
|
||||
std::random_device randomDevice;
|
||||
std::array<std::uint32_t, std::mt19937::state_size> seed {};
|
||||
std::generate(seed.begin(), seed.end(), std::reference_wrapper {randomDevice});
|
||||
std::seed_seq seedSeq(seed.begin(), seed.end());
|
||||
return std::mt19937 {seedSeq};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
uuids::uuid_random_generator UUID::GetUUIDGenerator()
|
||||
{
|
||||
return uuids::uuid_random_generator {ms_randomGenerator};
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
21
Bigfoot/Sources/Utils/CMakeLists.txt
Normal file
21
Bigfoot/Sources/Utils/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
set(PublicDependencies
|
||||
$<$<CONFIG:Debug,RelWithDebInfo>:quill::quill>
|
||||
$<$<CONFIG:Debug,RelWithDebInfo>:cpptrace::cpptrace>)
|
||||
set(PrivateDependencies)
|
||||
set(BigfootPublicDependencies
|
||||
System)
|
||||
set(BigfootPrivateDependencies)
|
||||
|
||||
bigfoot_create_package_lib(
|
||||
${PackageName}
|
||||
"${PublicDependencies}"
|
||||
"${PrivateLibraries}"
|
||||
"${BigfootPublicDependencies}"
|
||||
"${BigfootPrivateDependencies}"
|
||||
"")
|
||||
|
||||
target_compile_definitions(${PackageName}
|
||||
PUBLIC $<$<CONFIG:Debug,RelWithDebInfo>:QUILL_NO_EXCEPTIONS>
|
||||
PUBLIC $<$<CONFIG:Debug,RelWithDebInfo>:QUILL_DISABLE_NON_PREFIXED_MACROS>)
|
||||
95
Bigfoot/Sources/Utils/Include/Utils/Assert.hpp
Normal file
95
Bigfoot/Sources/Utils/Include/Utils/Assert.hpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/*********************************************************************
|
||||
* \file Assert.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILS_ASSERT_HPP
|
||||
#define BIGFOOT_UTILS_ASSERT_HPP
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#if defined BIGFOOT_LINUX
|
||||
#include <csignal>
|
||||
#endif
|
||||
|
||||
#if defined BIGFOOT_WINDOWS
|
||||
#define BREAK \
|
||||
do \
|
||||
{ \
|
||||
__debugbreak(); \
|
||||
} while (false)
|
||||
#elif defined BIGFOOT_LINUX
|
||||
#define BREAK \
|
||||
do \
|
||||
{ \
|
||||
std::raise(SIGTRAP); \
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
#define ASSERT(HANDLER, p_assert, p_message, ...) \
|
||||
do \
|
||||
{ \
|
||||
constexpr std::source_location location = std::source_location::current(); \
|
||||
if (!(p_assert)) [[unlikely]] \
|
||||
{ \
|
||||
constexpr auto stacktrace = []() -> std::string \
|
||||
{ \
|
||||
const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \
|
||||
return stacktrace.to_string(); \
|
||||
}; \
|
||||
\
|
||||
HANDLER::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \
|
||||
BREAK; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define SOFT_ASSERT(HANDLER, p_assert, p_message, ...) \
|
||||
do \
|
||||
{ \
|
||||
constexpr std::source_location location = std::source_location::current(); \
|
||||
if (!(p_assert)) [[unlikely]] \
|
||||
{ \
|
||||
constexpr auto stacktrace = []() -> std::string \
|
||||
{ \
|
||||
const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \
|
||||
return stacktrace.to_string(); \
|
||||
}; \
|
||||
\
|
||||
HANDLER::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \
|
||||
BREAK; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define CRITICAL_ASSERT(HANDLER, p_assert, p_message, ...) \
|
||||
do \
|
||||
{ \
|
||||
constexpr std::source_location location = std::source_location::current(); \
|
||||
if (!(p_assert)) [[unlikely]] \
|
||||
{ \
|
||||
constexpr auto stacktrace = []() -> std::string \
|
||||
{ \
|
||||
const cpptrace::stacktrace stacktrace = cpptrace::generate_trace(); \
|
||||
return stacktrace.to_string(); \
|
||||
}; \
|
||||
\
|
||||
HANDLER::Handle(location, stacktrace(), p_message __VA_OPT__(, ) __VA_ARGS__); \
|
||||
BREAK; \
|
||||
std::abort(); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#else
|
||||
#define ASSERT(HANDLER, p_assert, p_message, ...)
|
||||
|
||||
#define SOFT_ASSERT(HANDLER, p_assert, p_message, ...)
|
||||
|
||||
#define CRITICAL_ASSERT(HANDLER, p_assert, p_message, ...)
|
||||
#endif
|
||||
#endif
|
||||
60
Bigfoot/Sources/Utils/Include/Utils/Caster.hpp
Normal file
60
Bigfoot/Sources/Utils/Include/Utils/Caster.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*********************************************************************
|
||||
* \file Caster.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILS_CASTER_HPP
|
||||
#define BIGFOOT_UTILS_CASTER_HPP
|
||||
#include <Utils/UtilsAssertHandler.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
template<class TO, class FROM>
|
||||
constexpr TO* Cast(FROM* p_object)
|
||||
{
|
||||
constexpr bool same = std::is_base_of_v<FROM, TO> || std::is_base_of_v<TO, FROM>;
|
||||
static_assert(same, "Trying to cast to an incompatible type!");
|
||||
return static_cast<TO*>(p_object);
|
||||
}
|
||||
|
||||
template<class TO, class FROM>
|
||||
constexpr const TO* Cast(const FROM* p_object)
|
||||
{
|
||||
constexpr bool same = std::is_base_of_v<FROM, TO> || std::is_base_of_v<TO, FROM>;
|
||||
static_assert(same, "Trying to cast to an incompatible type!");
|
||||
return static_cast<const TO*>(p_object);
|
||||
}
|
||||
|
||||
template<class TO, class FROM>
|
||||
constexpr TO& Cast(FROM& p_object)
|
||||
{
|
||||
constexpr bool same = std::is_base_of_v<FROM, TO> || std::is_base_of_v<TO, FROM>;
|
||||
static_assert(same, "Trying to cast to an incompatible type!");
|
||||
return static_cast<TO&>(p_object);
|
||||
}
|
||||
|
||||
template<class TO, class FROM>
|
||||
constexpr const TO& Cast(const FROM& p_object)
|
||||
{
|
||||
constexpr bool same = std::is_base_of_v<FROM, TO> || std::is_base_of_v<TO, FROM>;
|
||||
static_assert(same, "Trying to cast to an incompatible type!");
|
||||
return static_cast<const TO&>(p_object);
|
||||
}
|
||||
|
||||
template<typename TO, typename FROM, std::enable_if_t<std::is_integral_v<FROM> && std::is_integral_v<TO>, bool> = true>
|
||||
constexpr TO NumericCast(const FROM& p_from)
|
||||
{
|
||||
const TO to = static_cast<TO>(p_from);
|
||||
SOFT_ASSERT(UtilsAssertHandler, static_cast<FROM>(to) == p_from, "We are losing data for this cast!");
|
||||
|
||||
return to;
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
|
||||
#define BIGFOOT_NUMERIC_CAST(p_to, p_data) Bigfoot::NumericCast<p_to>(p_data)
|
||||
|
||||
#define BIGFOOT_OBJECT_CAST(p_to, p_object) Bigfoot::Cast<p_to>(p_object)
|
||||
#endif
|
||||
17
Bigfoot/Sources/Utils/Include/Utils/Concat.h
Normal file
17
Bigfoot/Sources/Utils/Include/Utils/Concat.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*********************************************************************
|
||||
* \file Concat.h
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILS_CONCAT_H
|
||||
#define BIGFOOT_UTILS_CONCAT_H
|
||||
|
||||
#define CONCAT_IMPL(a, b) a b
|
||||
#define CONCAT(a, b) CONCAT_IMPL(a, b)
|
||||
|
||||
#define UNIQUE_IMPL(prefix, line) prefix##_##line
|
||||
#define UNIQUE(prefix, line) UNIQUE_IMPL(prefix, line)
|
||||
#define MAKE_UNIQUE_VARIABLE_NAME(prefix) UNIQUE(prefix, __LINE__)
|
||||
|
||||
#endif
|
||||
187
Bigfoot/Sources/Utils/Include/Utils/Log.hpp
Normal file
187
Bigfoot/Sources/Utils/Include/Utils/Log.hpp
Normal file
@@ -0,0 +1,187 @@
|
||||
/*********************************************************************
|
||||
* \file Log.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILS_LOG_HPP
|
||||
#define BIGFOOT_UTILS_LOG_HPP
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
#include <Utils/Singleton.hpp>
|
||||
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
#ifdef BIGFOOT_WINDOWS
|
||||
#pragma warning(disable: 4702)
|
||||
#endif
|
||||
#include <quill/Backend.h>
|
||||
#include <quill/Frontend.h>
|
||||
#include <quill/LogMacros.h>
|
||||
#include <quill/Logger.h>
|
||||
#include <quill/sinks/ConsoleSink.h>
|
||||
#if defined BIGFOOT_WINDOWS
|
||||
#pragma warning(default: 4702)
|
||||
#endif
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
enum class LogLevel
|
||||
{
|
||||
Debug,
|
||||
Trace,
|
||||
Info,
|
||||
Warn,
|
||||
Error,
|
||||
Critical
|
||||
};
|
||||
|
||||
struct LoggerInfo
|
||||
{
|
||||
std::string m_name;
|
||||
LogLevel m_level;
|
||||
};
|
||||
|
||||
Log();
|
||||
|
||||
Log(const Log& p_logger) = delete;
|
||||
Log(Log&& p_logger) = delete;
|
||||
|
||||
/**
|
||||
* Register a logger.
|
||||
*
|
||||
* \param p_loggerInfo The logger to register
|
||||
*/
|
||||
[[nodiscard]]
|
||||
quill::Logger* RegisterLogger(const LoggerInfo& p_loggerInfo);
|
||||
|
||||
/**
|
||||
* Register a logger.
|
||||
*
|
||||
* \param p_loggerInfo The logger to get
|
||||
* \return The logger, nullptr if it does not exist
|
||||
*/
|
||||
[[nodiscard]]
|
||||
quill::Logger* GetLogger(const LoggerInfo& p_loggerInfo);
|
||||
|
||||
/**
|
||||
* Changes the loglevel of a Logger.
|
||||
*
|
||||
* \param p_loggerInfo The logger to change
|
||||
* \param p_level The new level
|
||||
*/
|
||||
void ChangeLoggerLogLevel(LoggerInfo& p_loggerInfo, const LogLevel p_level);
|
||||
|
||||
~Log();
|
||||
|
||||
Log& operator=(const Log& p_logger) = delete;
|
||||
Log& operator=(Log&& p_logger) = delete;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Set the LogLevel of a logger
|
||||
*
|
||||
* \param p_loggerInfo The logger to set
|
||||
*/
|
||||
void SetLoggerLevel(const LoggerInfo& p_loggerInfo);
|
||||
|
||||
enum class SinkType
|
||||
{
|
||||
Console
|
||||
};
|
||||
|
||||
/*
|
||||
* The sinks
|
||||
*/
|
||||
std::array<std::shared_ptr<quill::Sink>, magic_enum::enum_count<SinkType>()> m_sinks;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (quill::Logger* logger = Bigfoot::Singleton<Bigfoot::Log>::Instance().GetLogger(loggerName)) \
|
||||
{ \
|
||||
QUILL_LOG_DEBUG(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
QUILL_LOG_DEBUG(Bigfoot::Singleton<Bigfoot::Log>::Instance().RegisterLogger(loggerName), \
|
||||
fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_TRACE(loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (quill::Logger* logger = Bigfoot::Singleton<Bigfoot::Log>::Instance().GetLogger(loggerName)) \
|
||||
{ \
|
||||
QUILL_LOG_TRACE_L3(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
QUILL_LOG_TRACE_L3(Bigfoot::Singleton<Bigfoot::Log>::Instance().RegisterLogger(loggerName), \
|
||||
fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_INFO(loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (quill::Logger* logger = Bigfoot::Singleton<Bigfoot::Log>::Instance().GetLogger(loggerName)) \
|
||||
{ \
|
||||
QUILL_LOG_INFO(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
QUILL_LOG_INFO(Bigfoot::Singleton<Bigfoot::Log>::Instance().RegisterLogger(loggerName), \
|
||||
fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_WARN(loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (quill::Logger* logger = Bigfoot::Singleton<Bigfoot::Log>::Instance().GetLogger(loggerName)) \
|
||||
{ \
|
||||
QUILL_LOG_WARNING(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
QUILL_LOG_WARNING(Bigfoot::Singleton<Bigfoot::Log>::Instance().RegisterLogger(loggerName), \
|
||||
fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_ERROR(loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (quill::Logger* logger = Bigfoot::Singleton<Bigfoot::Log>::Instance().GetLogger(loggerName)) \
|
||||
{ \
|
||||
QUILL_LOG_ERROR(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
QUILL_LOG_ERROR(Bigfoot::Singleton<Bigfoot::Log>::Instance().RegisterLogger(loggerName), \
|
||||
fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_FATAL(loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (quill::Logger* logger = Bigfoot::Singleton<Bigfoot::Log>::Instance().GetLogger(loggerName)) \
|
||||
{ \
|
||||
QUILL_LOG_CRITICAL(logger, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
QUILL_LOG_CRITICAL(Bigfoot::Singleton<Bigfoot::Log>::Instance().RegisterLogger(loggerName), \
|
||||
fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
106
Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp
Normal file
106
Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*********************************************************************
|
||||
* \file Singleton.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILS_SINGLETON_HPP
|
||||
#define BIGFOOT_UTILS_SINGLETON_HPP
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
template<class TYPE>
|
||||
class Singleton
|
||||
{
|
||||
public:
|
||||
Singleton() = delete;
|
||||
|
||||
Singleton(const Singleton& p_singleton) = delete;
|
||||
Singleton(Singleton&& p_singleton) = delete;
|
||||
|
||||
~Singleton() = delete;
|
||||
|
||||
/**
|
||||
* Get the instance.
|
||||
*
|
||||
* \return The instance
|
||||
*/
|
||||
static constexpr TYPE& Instance()
|
||||
{
|
||||
return *std::bit_cast<TYPE*>(ms_instance.data());
|
||||
}
|
||||
|
||||
class Lifetime
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \param p_args Arguments for the singleton
|
||||
*/
|
||||
template<typename... ARGS, typename = std::enable_if_t<!(std::is_same_v<Lifetime, std::decay_t<ARGS>> || ...)>>
|
||||
explicit Lifetime(ARGS&&... p_args)
|
||||
{
|
||||
Initialize(std::forward<ARGS>(p_args)...);
|
||||
}
|
||||
|
||||
Lifetime(const Lifetime& p_lifetime) = delete;
|
||||
Lifetime(Lifetime&& p_lifetime) = delete;
|
||||
|
||||
~Lifetime()
|
||||
{
|
||||
Finalize();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Lifetime& operator=(const Lifetime& p_lifetime) = delete;
|
||||
[[nodiscard]]
|
||||
Lifetime& operator=(Lifetime&& p_lifetime) = delete;
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
Singleton& operator=(const Singleton& p_singleton) = delete;
|
||||
[[nodiscard]]
|
||||
Singleton& operator=(Singleton&& p_singleton) = delete;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initialize the singleton.
|
||||
*
|
||||
* \param p_args Arguments for the singleton
|
||||
*/
|
||||
template<typename... ARGS>
|
||||
static void Initialize(ARGS&&... p_args)
|
||||
{
|
||||
new (ms_instance.data()) TYPE(std::forward<ARGS>(p_args)...);
|
||||
|
||||
ms_initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the singleton.
|
||||
*
|
||||
*/
|
||||
static void Finalize()
|
||||
{
|
||||
std::bit_cast<TYPE*>(ms_instance.data())->~TYPE();
|
||||
|
||||
ms_initialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The singleton.
|
||||
*/
|
||||
alignas(alignof(TYPE)) inline static std::array<std::byte, sizeof(TYPE)> ms_instance;
|
||||
|
||||
/**
|
||||
* Is the singleton initialized?
|
||||
*/
|
||||
inline static bool ms_initialized = false;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
@AUTO_GENERATED_COMMENT@
|
||||
|
||||
/*********************************************************************
|
||||
* \file @LOGGER_FILENAME@.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_@LOGGER_FILENAME_UPPER@_GENERATED_HPP
|
||||
#define BIGFOOT_@LOGGER_FILENAME_UPPER@_GENERATED_HPP
|
||||
#include <Utils/Log.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
inline Log::LoggerInfo @LOGGER_NAME@ {"@LOGGER_NAME@", Log::LogLevel::Trace};
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
21
Bigfoot/Sources/Utils/Include/Utils/TargetMacros.h
Normal file
21
Bigfoot/Sources/Utils/Include/Utils/TargetMacros.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*********************************************************************
|
||||
* \file TargetMacros.h
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILS_TARGETMACROS_H
|
||||
#define BIGFOOT_UTILS_TARGETMACROS_H
|
||||
|
||||
#if defined BIGFOOT_OPTIMIZED
|
||||
#define BIGFOOT_OPTIMIZED_ONLY(...) __VA_ARGS__
|
||||
#define BIGFOOT_NOT_OPTIMIZED_ONLY(...)
|
||||
#define BIGFOOT_OPTIMIZED_OR_NOT(p_optimized, p_notOptimized) p_optimized
|
||||
#endif
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
#define BIGFOOT_OPTIMIZED_ONLY(...)
|
||||
#define BIGFOOT_NOT_OPTIMIZED_ONLY(...) __VA_ARGS__
|
||||
#define BIGFOOT_OPTIMIZED_OR_NOT(p_optimized, p_notOptimized) p_notOptimized
|
||||
#endif
|
||||
#endif
|
||||
49
Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp
Normal file
49
Bigfoot/Sources/Utils/Include/Utils/UtilsAssertHandler.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*********************************************************************
|
||||
* \file UtilsAssertHandler.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILS_UTILSASSERTHANDLER_HPP
|
||||
#define BIGFOOT_UTILS_UTILSASSERTHANDLER_HPP
|
||||
#include <Utils/Assert.hpp>
|
||||
|
||||
#include <format>
|
||||
#include <source_location>
|
||||
#include <string_view>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class UtilsAssertHandler
|
||||
{
|
||||
public:
|
||||
UtilsAssertHandler() = delete;
|
||||
|
||||
UtilsAssertHandler(const UtilsAssertHandler& p_handler) = delete;
|
||||
UtilsAssertHandler(UtilsAssertHandler&& p_handler) = delete;
|
||||
|
||||
~UtilsAssertHandler() = delete;
|
||||
|
||||
/**
|
||||
* Handle an assertion.
|
||||
*
|
||||
* \param p_location Location of the assertion.
|
||||
* \param p_stacktrace The stack trace
|
||||
* \param p_format Format string for the assertion message.
|
||||
* \param p_args Arguments for the format string.
|
||||
*/
|
||||
template<typename... ARGS>
|
||||
static void Handle([[maybe_unused]] const std::source_location& p_location,
|
||||
[[maybe_unused]] const std::string_view p_stacktrace,
|
||||
[[maybe_unused]] std::format_string<ARGS...> p_format,
|
||||
[[maybe_unused]] ARGS&&... p_args)
|
||||
{
|
||||
// We dont have access to logging capabilities here
|
||||
// So no log
|
||||
}
|
||||
|
||||
UtilsAssertHandler& operator=(const UtilsAssertHandler& p_handler) = delete;
|
||||
UtilsAssertHandler& operator=(UtilsAssertHandler&& p_handler) = delete;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
158
Bigfoot/Sources/Utils/Include/Utils/Version.hpp
Normal file
158
Bigfoot/Sources/Utils/Include/Utils/Version.hpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/*********************************************************************
|
||||
* \file Version.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILS_VERSION_HPP
|
||||
#define BIGFOOT_UTILS_VERSION_HPP
|
||||
#include <Utils/Caster.hpp>
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class Version
|
||||
{
|
||||
public:
|
||||
Version() = default;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \param p_combined The combined version.
|
||||
*/
|
||||
explicit constexpr Version(const std::uint32_t p_combined):
|
||||
m_combined(p_combined)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \param p_major Major
|
||||
* \param p_minor Minor
|
||||
* \param p_patch Patch
|
||||
*/
|
||||
constexpr Version(const std::uint8_t p_major, const std::uint8_t p_minor, const std::uint8_t p_patch):
|
||||
m_combined((p_major << 16) | (p_minor << 8) | p_patch)
|
||||
{
|
||||
}
|
||||
|
||||
Version(const Version& p_version) = default;
|
||||
Version(Version&& p_version) = default;
|
||||
|
||||
~Version() = default;
|
||||
|
||||
/**
|
||||
* Get the major part of the version.
|
||||
*
|
||||
* \return The major part of the version.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
constexpr std::uint8_t Major() const
|
||||
{
|
||||
constexpr std::uint32_t mask = 0b00000000111111110000000000000000;
|
||||
|
||||
return BIGFOOT_NUMERIC_CAST(std::uint8_t, (m_combined & mask) >> 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minor part of the version.
|
||||
*
|
||||
* \return The minor part of the version.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
constexpr std::uint8_t Minor() const
|
||||
{
|
||||
constexpr std::uint32_t mask = 0b00000000000000001111111100000000;
|
||||
|
||||
return BIGFOOT_NUMERIC_CAST(std::uint8_t, (m_combined & mask) >> 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the patch part of the version.
|
||||
*
|
||||
* \return The patch part of the version.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
constexpr std::uint8_t Patch() const
|
||||
{
|
||||
constexpr std::uint32_t mask = 0b00000000000000000000000011111111;
|
||||
|
||||
return BIGFOOT_NUMERIC_CAST(std::uint8_t, (m_combined & mask));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr operator std::uint32_t() const
|
||||
{
|
||||
return m_combined;
|
||||
}
|
||||
|
||||
[[nodiscard]] operator std::string() const;
|
||||
|
||||
constexpr Version& operator=(const Version& p_version) = default;
|
||||
|
||||
constexpr Version& operator=(Version&& p_version) = default;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator>(const Version& p_version) const
|
||||
{
|
||||
return m_combined > p_version.m_combined;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator<(const Version& p_version) const
|
||||
{
|
||||
return m_combined < p_version.m_combined;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator>=(const Version& p_version) const
|
||||
{
|
||||
return m_combined >= p_version.m_combined;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator<=(const Version& p_version) const
|
||||
{
|
||||
return m_combined <= p_version.m_combined;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator==(const Version& p_version) const = default;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator!=(const Version& p_version) const = default;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The combined version.
|
||||
*/
|
||||
std::uint32_t m_combined = 0;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
template<>
|
||||
struct std::formatter<Bigfoot::Version>
|
||||
{
|
||||
template<typename ParseContext>
|
||||
constexpr auto parse(ParseContext& p_context)
|
||||
{
|
||||
return p_context.begin();
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const Bigfoot::Version& p_version, FormatContext& p_context) const
|
||||
{
|
||||
return std::format_to(p_context.out(), "{}", static_cast<std::string>(p_version));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
90
Bigfoot/Sources/Utils/Log.cpp
Normal file
90
Bigfoot/Sources/Utils/Log.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
/*******************************************************************
|
||||
* \file Log.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <Utils/Log.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
Log::Log()
|
||||
{
|
||||
quill::Backend::start();
|
||||
|
||||
m_sinks[magic_enum::enum_integer(SinkType::Console)] = quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
|
||||
std::string {magic_enum::enum_name(SinkType::Console)});
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
quill::Logger* Log::RegisterLogger(const LoggerInfo& p_loggerInfo)
|
||||
{
|
||||
quill::Logger* logger = quill::Frontend::create_or_get_logger(p_loggerInfo.m_name,
|
||||
m_sinks[magic_enum::enum_integer(SinkType::Console)]);
|
||||
SetLoggerLevel(p_loggerInfo);
|
||||
|
||||
return logger;
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
quill::Logger* Log::GetLogger(const LoggerInfo& p_loggerInfo)
|
||||
{
|
||||
return quill::Frontend::get_logger(p_loggerInfo.m_name);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
void Log::ChangeLoggerLogLevel(LoggerInfo& p_loggerInfo, const LogLevel p_level)
|
||||
{
|
||||
p_loggerInfo.m_level = p_level;
|
||||
SetLoggerLevel(p_loggerInfo);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
void Log::SetLoggerLevel(const LoggerInfo& p_loggerInfo)
|
||||
{
|
||||
constexpr auto logLevelToQuillLogLevel = [](const LogLevel p_level) constexpr -> quill::LogLevel
|
||||
{
|
||||
switch (p_level)
|
||||
{
|
||||
case LogLevel::Debug:
|
||||
return quill::LogLevel::Debug;
|
||||
case LogLevel::Trace:
|
||||
return quill::LogLevel::TraceL3;
|
||||
case LogLevel::Info:
|
||||
return quill::LogLevel::Info;
|
||||
case LogLevel::Warn:
|
||||
return quill::LogLevel::Warning;
|
||||
case LogLevel::Error:
|
||||
return quill::LogLevel::Error;
|
||||
case LogLevel::Critical:
|
||||
return quill::LogLevel::Critical;
|
||||
}
|
||||
|
||||
return quill::LogLevel::TraceL3;
|
||||
};
|
||||
|
||||
if (quill::Logger* logger = GetLogger(p_loggerInfo))
|
||||
{
|
||||
logger->set_log_level(logLevelToQuillLogLevel(p_loggerInfo.m_level));
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
Log::~Log()
|
||||
{
|
||||
for (quill::Logger* logger: quill::Frontend::get_all_loggers())
|
||||
{
|
||||
quill::Frontend::remove_logger(logger);
|
||||
}
|
||||
|
||||
quill::Backend::stop();
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
15
Bigfoot/Sources/Utils/Version.cpp
Normal file
15
Bigfoot/Sources/Utils/Version.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*********************************************************************
|
||||
* \file Version.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date January 2023
|
||||
*********************************************************************/
|
||||
#include <Utils/Version.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
Version::operator std::string() const
|
||||
{
|
||||
return std::format("{}.{}.{}", Major(), Minor(), Patch());
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
3
Bigfoot/Tests/CMakeLists.txt
Normal file
3
Bigfoot/Tests/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/System)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Utils)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Engine)
|
||||
1
Bigfoot/Tests/Engine/BigFile/Database.cpp
Normal file
1
Bigfoot/Tests/Engine/BigFile/Database.cpp
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
0
Bigfoot/Tests/Engine/BigFile/Statement.cpp
Normal file
0
Bigfoot/Tests/Engine/BigFile/Statement.cpp
Normal file
7
Bigfoot/Tests/Engine/CMakeLists.txt
Normal file
7
Bigfoot/Tests/Engine/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
bigfoot_create_bigfile(${PackageName}Tests "Tests/Bigfoot")
|
||||
|
||||
bigfoot_create_package_tests(
|
||||
${PackageName}
|
||||
"")
|
||||
@@ -0,0 +1,19 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file BigFileInfo.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_BIGFOOT_BIGFILEINFO_GENERATED_HPP
|
||||
#define BIGFOOT_BIGFOOT_BIGFILEINFO_GENERATED_HPP
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* BigFile location
|
||||
*/
|
||||
constexpr std::string_view BIGFILE_BIGFOOT_LOCATION{"D:/Development/bigfootdev/bigfoot2/build/Bigfoot/Tests/Engine/Bigfoot-bigfile.db"};
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file BigFileInfo.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_BIGFILE_BIGFILEINFO_GENERATED_HPP
|
||||
#define BIGFOOT_ENGINE_BIGFILE_BIGFILEINFO_GENERATED_HPP
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* BigFile location
|
||||
*/
|
||||
constexpr std::string_view BIGFILE_ENGINETESTS_LOCATION{"D:/Development/bigfootdev/bigfoot2/build/Bigfoot/Tests/Engine/EngineTests-bigfile.db"};
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file BigFileInfo.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINETESTS_BIGFILEINFO_GENERATED_HPP
|
||||
#define BIGFOOT_ENGINETESTS_BIGFILEINFO_GENERATED_HPP
|
||||
|
||||
#include <EASTL/string_view.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* BigFile location
|
||||
*/
|
||||
constexpr eastl::string_view BIGFILE_ENGINETESTS_LOCATION {"./EngineTests-bigfile.db"};
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
7
Bigfoot/Tests/System/CMakeLists.txt
Normal file
7
Bigfoot/Tests/System/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
set(Dependencies)
|
||||
|
||||
bigfoot_create_package_tests(
|
||||
${PackageName}
|
||||
"")
|
||||
182
Bigfoot/Tests/System/UUID.cpp
Normal file
182
Bigfoot/Tests/System/UUID.cpp
Normal file
@@ -0,0 +1,182 @@
|
||||
/*********************************************************************
|
||||
* \file UUID.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <System/UUID.hpp>
|
||||
|
||||
#include <ankerl/unordered_dense.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class UUIDFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
UUID m_a;
|
||||
UUID m_b {"47183823-2574-4bfd-b411-99ed177d3e43"};
|
||||
UUID m_c {"4bfd-b411-99ed177d3e43"};
|
||||
|
||||
std::array<std::byte, 16> m_raw {
|
||||
std::byte {0},
|
||||
std::byte {1},
|
||||
std::byte {2},
|
||||
std::byte {3},
|
||||
std::byte {4},
|
||||
std::byte {5},
|
||||
std::byte {6},
|
||||
std::byte {7},
|
||||
std::byte {8},
|
||||
std::byte {9},
|
||||
std::byte {10},
|
||||
std::byte {11},
|
||||
std::byte {12},
|
||||
std::byte {13},
|
||||
std::byte {14},
|
||||
std::byte {15},
|
||||
};
|
||||
UUID m_d {m_raw};
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, DumpingRawAndConstructAnUUIDWithItShouldGiveTheSameUUID)
|
||||
{
|
||||
std::span<const std::byte, UUID::UUID_BYTE_SIZE> raw = m_a;
|
||||
EXPECT_EQ(m_a, UUID {raw});
|
||||
|
||||
raw = m_b;
|
||||
EXPECT_EQ(m_b, UUID {raw});
|
||||
|
||||
raw = m_d;
|
||||
EXPECT_EQ(m_d, UUID {raw});
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, ValidIDFromStringShouldBeEqualToString)
|
||||
{
|
||||
EXPECT_EQ(static_cast<std::string>(m_b), "47183823-2574-4bfd-b411-99ed177d3e43");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, InvalidIDFromStringShouldNotBeEqualToString)
|
||||
{
|
||||
EXPECT_NE(static_cast<std::string>(m_c), "4bfd-b411-99ed177d3e43");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, NullIDStringShouldBeEqualToNullIDString)
|
||||
{
|
||||
EXPECT_EQ(static_cast<std::string>(UUID::NULL_UUID), "00000000-0000-0000-0000-000000000000");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, DefaultConstructedIDShouldBeValid)
|
||||
{
|
||||
EXPECT_TRUE(m_a);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, StringConstructedIDFromAValidStringShouldBeValid)
|
||||
{
|
||||
EXPECT_TRUE(m_b);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, StringConstructedIDFromAnInvalidStringShouldBeInvalid)
|
||||
{
|
||||
EXPECT_FALSE(m_c);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, RawConstructedIDShouldBeValid)
|
||||
{
|
||||
EXPECT_TRUE(m_d);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, ConstructingFromRawShouldAlwaysGiveTheSameUUID)
|
||||
{
|
||||
EXPECT_EQ(m_d, UUID {"00010203-0405-0607-0809-0a0b0c0d0e0f"});
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, NullIDShouldNotBeValid)
|
||||
{
|
||||
EXPECT_FALSE(UUID::NULL_UUID);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, IDShouldBeEqualToItself)
|
||||
{
|
||||
EXPECT_EQ(m_a, m_a);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, IDConstructedFromOtherIDShouldBeEqual)
|
||||
{
|
||||
EXPECT_EQ(m_a, UUID {m_a});
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, IDCopiedFromOtherIDShouldBeEqual)
|
||||
{
|
||||
const UUID m_aDuplicate = m_a;
|
||||
EXPECT_EQ(m_a, m_aDuplicate);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, ValidIDsShouldNotBeEqualToNullID)
|
||||
{
|
||||
EXPECT_NE(m_a, UUID::NULL_UUID);
|
||||
EXPECT_NE(m_b, UUID::NULL_UUID);
|
||||
EXPECT_NE(m_d, UUID::NULL_UUID);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, InvalidIDsShouldBeEqualToNullID)
|
||||
{
|
||||
EXPECT_EQ(m_c, UUID::NULL_UUID);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, GeneratingFiveMillionUniqueID)
|
||||
{
|
||||
ankerl::unordered_dense::set<UUID> m_ids;
|
||||
|
||||
for (std::uint32_t index = 0; index < 5'000'000; ++index)
|
||||
{
|
||||
EXPECT_TRUE(m_ids.insert(UUID {}).second);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(UUIDFixture, Raw_ShouldGiveBackTheRawDataOfTheID)
|
||||
{
|
||||
std::span<const std::byte, UUID::UUID_BYTE_SIZE> d = m_d;
|
||||
std::span<const std::byte, UUID::UUID_BYTE_SIZE> raw = m_raw;
|
||||
|
||||
for (std::uint32_t i = 0; i < UUID::UUID_BYTE_SIZE; ++i)
|
||||
{
|
||||
EXPECT_EQ(d[i], raw[i]);
|
||||
}
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
9
Bigfoot/Tests/Utils/CMakeLists.txt
Normal file
9
Bigfoot/Tests/Utils/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
set(Dependencies)
|
||||
|
||||
bigfoot_create_logger(${PackageName}Tests)
|
||||
|
||||
bigfoot_create_package_tests(
|
||||
${PackageName}
|
||||
"")
|
||||
121
Bigfoot/Tests/Utils/Caster.cpp
Normal file
121
Bigfoot/Tests/Utils/Caster.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/*********************************************************************
|
||||
* \file Caster.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <Utils/Caster.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class Parent
|
||||
{
|
||||
public:
|
||||
Parent(const std::uint32_t p_value):
|
||||
m_value(p_value)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Parent() = default;
|
||||
|
||||
std::uint32_t GetParentValue() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
virtual std::uint32_t GetChildValue() const = 0;
|
||||
|
||||
private:
|
||||
std::uint32_t m_value;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
class ChildA final: public Parent
|
||||
{
|
||||
public:
|
||||
ChildA(const std::uint32_t p_value):
|
||||
Parent(28),
|
||||
m_value(p_value)
|
||||
{
|
||||
}
|
||||
|
||||
~ChildA() override = default;
|
||||
|
||||
std::uint32_t GetChildValue() const override
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
std::uint32_t m_value;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
class ChildB final: public Parent
|
||||
{
|
||||
public:
|
||||
ChildB(const std::uint32_t p_value):
|
||||
Parent(34),
|
||||
m_value(p_value)
|
||||
{
|
||||
}
|
||||
|
||||
~ChildB() override = default;
|
||||
|
||||
std::uint32_t GetChildValue() const override
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
std::uint32_t m_value;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
class CasterFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::unique_ptr<Parent> m_a = std::make_unique<ChildA>(42);
|
||||
ChildB m_b {12};
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(CasterFixture, ObjectCast)
|
||||
{
|
||||
EXPECT_EQ(m_a->GetParentValue(), 28);
|
||||
EXPECT_EQ(m_a->GetChildValue(), 42);
|
||||
const ChildA* child = BIGFOOT_OBJECT_CAST(ChildA, m_a.get());
|
||||
EXPECT_EQ(child->GetParentValue(), 28);
|
||||
EXPECT_EQ(child->GetChildValue(), 42);
|
||||
|
||||
EXPECT_EQ(m_b.GetParentValue(), 34);
|
||||
EXPECT_EQ(m_b.GetChildValue(), 12);
|
||||
const Parent& parent = BIGFOOT_OBJECT_CAST(Parent, m_b);
|
||||
EXPECT_EQ(parent.GetParentValue(), 34);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(CasterFixture, NumericCast)
|
||||
{
|
||||
const std::uint32_t a = 128;
|
||||
const std::uint8_t b = BIGFOOT_NUMERIC_CAST(std::uint8_t, a);
|
||||
EXPECT_EQ(a, b);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
#ifdef BIGFOOT_NOT_OPTIMIZED
|
||||
TEST_F(CasterFixture, NumericCast_ShouldAssertIfWeLoseDataDuringTheCast)
|
||||
{
|
||||
const std::uint32_t a = 1000;
|
||||
EXPECT_DEATH(BIGFOOT_NUMERIC_CAST(std::uint8_t, a), "");
|
||||
}
|
||||
#endif
|
||||
} // namespace Bigfoot
|
||||
36
Bigfoot/Tests/Utils/Concat.cpp
Normal file
36
Bigfoot/Tests/Utils/Concat.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/*********************************************************************
|
||||
* \file Concat.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <Utils/Concat.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class ConcatFixture: public ::testing::Test
|
||||
{
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(ConcatFixture, ShouldConcatTheTwoStrings)
|
||||
{
|
||||
constexpr std::string_view result = CONCAT("a", "b");
|
||||
EXPECT_STREQ(result.data(), "ab");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(ConcatFixture, UniqueName)
|
||||
{
|
||||
// this looks wrong, but this should expand to test_30 and test_31
|
||||
constexpr std::uint32_t MAKE_UNIQUE_VARIABLE_NAME(test) = 1;
|
||||
constexpr std::uint32_t MAKE_UNIQUE_VARIABLE_NAME(test) = 2;
|
||||
|
||||
EXPECT_EQ(test_30, 1);
|
||||
EXPECT_EQ(test_31, 2);
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
@@ -0,0 +1,21 @@
|
||||
// AUTO-GENERATED DO NOT TOUCH
|
||||
|
||||
/*********************************************************************
|
||||
* \file UtilsTestsLogger.generated.hpp
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_UTILSTESTSLOGGER_GENERATED_HPP
|
||||
#define BIGFOOT_UTILSTESTSLOGGER_GENERATED_HPP
|
||||
#include <Utils/Log.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
inline Log::LoggerInfo UTILSTESTS_LOGGER {"UTILSTESTS_LOGGER", Log::LogLevel::Trace};
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
130
Bigfoot/Tests/Utils/Log.cpp
Normal file
130
Bigfoot/Tests/Utils/Log.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/*********************************************************************
|
||||
* \file Log.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date December 2022
|
||||
*********************************************************************/
|
||||
#include <Utils/Log.hpp>
|
||||
|
||||
#include <UtilsTests/UtilsTestsLogger.generated.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class LogFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
UTILSTESTS_LOGGER = {"UTILSTESTS_LOGGER", Log::LogLevel::Trace};
|
||||
}
|
||||
|
||||
constexpr Log::LogLevel QuillLogLevelToLogLevel(const quill::LogLevel p_level)
|
||||
{
|
||||
switch (p_level)
|
||||
{
|
||||
case quill::LogLevel::Debug:
|
||||
return Log::LogLevel::Debug;
|
||||
case quill::LogLevel::TraceL3:
|
||||
return Log::LogLevel::Trace;
|
||||
case quill::LogLevel::Info:
|
||||
return Log::LogLevel::Info;
|
||||
case quill::LogLevel::Warning:
|
||||
return Log::LogLevel::Warn;
|
||||
case quill::LogLevel::Error:
|
||||
return Log::LogLevel::Error;
|
||||
case quill::LogLevel::Critical:
|
||||
return Log::LogLevel::Critical;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Log::LogLevel::Trace;
|
||||
}
|
||||
|
||||
Singleton<Log>::Lifetime m_log;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, RegisterLogger_ShouldRegisterTheLogger)
|
||||
{
|
||||
const quill::Logger* logger = Singleton<Log>::Instance().RegisterLogger(UTILSTESTS_LOGGER);
|
||||
EXPECT_TRUE(logger);
|
||||
EXPECT_EQ(logger, Singleton<Log>::Instance().GetLogger(UTILSTESTS_LOGGER));
|
||||
EXPECT_EQ(logger->get_logger_name(), UTILSTESTS_LOGGER.m_name);
|
||||
EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), UTILSTESTS_LOGGER.m_level);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, GetLogger_ShouldReturnNullptrIfTheLoggerDoesNotExist)
|
||||
{
|
||||
EXPECT_FALSE(Singleton<Log>::Instance().GetLogger(UTILSTESTS_LOGGER));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, GetLogger_ShouldReturnTheLoggerIfItExists)
|
||||
{
|
||||
[[maybe_unused]]
|
||||
const quill::Logger* logger = Singleton<Log>::Instance().RegisterLogger(UTILSTESTS_LOGGER);
|
||||
EXPECT_TRUE(Singleton<Log>::Instance().GetLogger(UTILSTESTS_LOGGER));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, ChangeLoggerLogLevel_ShouldChangeTheLoggerLogLevel)
|
||||
{
|
||||
const quill::Logger* logger = Singleton<Log>::Instance().RegisterLogger(UTILSTESTS_LOGGER);
|
||||
|
||||
Singleton<Log>::Instance().ChangeLoggerLogLevel(UTILSTESTS_LOGGER, Log::LogLevel::Critical);
|
||||
EXPECT_EQ(QuillLogLevelToLogLevel(logger->get_log_level()), Log::LogLevel::Critical);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, LogDebug)
|
||||
{
|
||||
BIGFOOT_LOG_DEBUG(UTILSTESTS_LOGGER, "Hello");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, LogTrace)
|
||||
{
|
||||
BIGFOOT_LOG_TRACE(UTILSTESTS_LOGGER, "Hello");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, LogInfo)
|
||||
{
|
||||
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "Hello");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, LogWarn)
|
||||
{
|
||||
BIGFOOT_LOG_WARN(UTILSTESTS_LOGGER, "Hello");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, LogError)
|
||||
{
|
||||
BIGFOOT_LOG_ERROR(UTILSTESTS_LOGGER, "Hello");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogFixture, LogFatal)
|
||||
{
|
||||
BIGFOOT_LOG_FATAL(UTILSTESTS_LOGGER, "Hello");
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
102
Bigfoot/Tests/Utils/Singleton.cpp
Normal file
102
Bigfoot/Tests/Utils/Singleton.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/*********************************************************************
|
||||
* \file Singleton.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <Utils/Singleton.hpp>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class SingletonMock
|
||||
{
|
||||
public:
|
||||
virtual ~SingletonMock() = default;
|
||||
virtual void Construct() = 0;
|
||||
virtual void Destruct() = 0;
|
||||
};
|
||||
|
||||
class SingletonTest
|
||||
{
|
||||
public:
|
||||
inline static SingletonMock* ms_mock = nullptr;
|
||||
|
||||
explicit SingletonTest(std::uint32_t p_data):
|
||||
m_data(p_data)
|
||||
{
|
||||
if (ms_mock)
|
||||
{
|
||||
ms_mock->Construct();
|
||||
}
|
||||
}
|
||||
|
||||
~SingletonTest()
|
||||
{
|
||||
if (ms_mock)
|
||||
{
|
||||
ms_mock->Destruct();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::uint32_t Data() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
private:
|
||||
std::uint32_t m_data;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
class SingletonFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
class SingletonMockImpl: public SingletonMock
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD(void, Construct, (), (override));
|
||||
MOCK_METHOD(void, Destruct, (), (override));
|
||||
};
|
||||
|
||||
std::unique_ptr<SingletonMockImpl> m_mock;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
m_mock = std::make_unique<::testing::NiceMock<SingletonMockImpl>>();
|
||||
SingletonTest::ms_mock = m_mock.get();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
SingletonTest::ms_mock = nullptr;
|
||||
m_mock.reset();
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(SingletonFixture, ConstructorAndDestructorShouldBeCalled)
|
||||
{
|
||||
::testing::InSequence seq;
|
||||
|
||||
EXPECT_CALL(*m_mock, Construct());
|
||||
EXPECT_CALL(*m_mock, Destruct());
|
||||
|
||||
Singleton<SingletonTest>::Lifetime singleton {42};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(SingletonFixture, Instance_ShouldReturnTheInstance)
|
||||
{
|
||||
Singleton<SingletonTest>::Lifetime singleton {42};
|
||||
|
||||
EXPECT_EQ(Singleton<SingletonTest>::Instance().Data(), 42);
|
||||
}
|
||||
|
||||
} // namespace Bigfoot
|
||||
26
Bigfoot/Tests/Utils/TargetMacros.cpp
Normal file
26
Bigfoot/Tests/Utils/TargetMacros.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
/*********************************************************************
|
||||
* \file TargetMacros.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <Utils/TargetMacros.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class TargetMacrosFixture: public ::testing::Test
|
||||
{
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(TargetMacrosFixture, OptimizedOrNot)
|
||||
{
|
||||
constexpr std::uint32_t value = BIGFOOT_OPTIMIZED_OR_NOT(1, 2);
|
||||
BIGFOOT_NOT_OPTIMIZED_ONLY(EXPECT_EQ(value, 2);)
|
||||
BIGFOOT_OPTIMIZED_ONLY(EXPECT_EQ(value, 1);)
|
||||
}
|
||||
|
||||
} // namespace Bigfoot
|
||||
0
Bigfoot/Tests/Utils/UtilsAssertHandler.cpp
Normal file
0
Bigfoot/Tests/Utils/UtilsAssertHandler.cpp
Normal file
73
Bigfoot/Tests/Utils/Version.cpp
Normal file
73
Bigfoot/Tests/Utils/Version.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*********************************************************************
|
||||
* \file Version.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date October 2025
|
||||
*********************************************************************/
|
||||
#include <Utils/Version.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class VersionFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
const Version m_detailed {1, 2, 3};
|
||||
const Version m_combined {(1 << 16) | (2 << 8) | 3};
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(VersionFixture, string)
|
||||
{
|
||||
EXPECT_STREQ(static_cast<std::string>(m_detailed).data(), "1.2.3");
|
||||
EXPECT_STREQ(static_cast<std::string>(m_combined).data(), "1.2.3");
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(VersionFixture, uint32_t)
|
||||
{
|
||||
EXPECT_EQ(static_cast<std::uint32_t>(m_detailed), (1 << 16) | (2 << 8) | 3);
|
||||
EXPECT_EQ(static_cast<std::uint32_t>(m_combined), (1 << 16) | (2 << 8) | 3);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(VersionFixture, Major_ShouldBeEqualToTheMajorPartOfTheVersion)
|
||||
{
|
||||
EXPECT_EQ(m_detailed.Major(), 1);
|
||||
EXPECT_EQ(m_combined.Major(), 1);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(VersionFixture, Minor_ShouldBeEqualToTheMinorPartOfTheVersion)
|
||||
{
|
||||
EXPECT_EQ(m_detailed.Minor(), 2);
|
||||
EXPECT_EQ(m_combined.Minor(), 2);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(VersionFixture, Patch_ShouldBeEqualToThePatchPartOfTheVersion)
|
||||
{
|
||||
EXPECT_EQ(m_detailed.Patch(), 3);
|
||||
EXPECT_EQ(m_combined.Patch(), 3);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(VersionFixture, Comparisons)
|
||||
{
|
||||
constexpr Version other {2, 6, 4};
|
||||
|
||||
EXPECT_GT(other, m_detailed);
|
||||
EXPECT_GE(other, other);
|
||||
EXPECT_LT(m_detailed, other);
|
||||
EXPECT_LE(other, other);
|
||||
EXPECT_EQ(other, other);
|
||||
EXPECT_NE(other, m_detailed);
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
Reference in New Issue
Block a user