diff --git a/.gitmodules b/.gitmodules index 56c8f91..4295068 100644 --- a/.gitmodules +++ b/.gitmodules @@ -26,3 +26,6 @@ [submodule "_ThirdParty/nfd"] path = _ThirdParty/nfd url = https://github.com/btzy/nativefiledialog-extended.git +[submodule "_ThirdParty/uuid"] + path = _ThirdParty/uuid + url = https://github.com/mariusbancila/stduuid.git diff --git a/CMakeLists.txt b/CMakeLists.txt index f9e716d..dc459c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ add_subdirectory(_ThirdParty/spdlog) set(JSON_BuildTests OFF CACHE INTERNAL "") add_subdirectory(_ThirdParty/json) +add_subdirectory(_ThirdParty/uuid) + add_subdirectory(_ThirdParty/nfd) set (ASSIMP_INSTALL OFF) @@ -59,7 +61,8 @@ add_custom_target(copy_resources COMMENT "Copying resources..." ) -target_link_libraries(${PROJECT_NAME} glfw spdlog assimp glm EnTT fmt nfd) +target_link_libraries(${PROJECT_NAME} glfw spdlog assimp glm EnTT fmt nfd uuid) target_include_directories(${PROJECT_NAME} PRIVATE ${ASSIMP_INCLUDE_INSTALL_DIR}) -target_include_directories(${PROJECT_NAME} PRIVATE src) target_include_directories(${PROJECT_NAME} PRIVATE _ThirdParty/json/single_include) +target_include_directories(${PROJECT_NAME} PRIVATE _ThirdParty/uuid/include) +target_include_directories(${PROJECT_NAME} PRIVATE src) diff --git a/_ThirdParty/uuid b/_ThirdParty/uuid new file mode 160000 index 0000000..3afe719 --- /dev/null +++ b/_ThirdParty/uuid @@ -0,0 +1 @@ +Subproject commit 3afe7193facd5d674de709fccc44d5055e144d7a diff --git a/src/AssetRecord.h b/src/AssetRecord.h new file mode 100644 index 0000000..3e74b1d --- /dev/null +++ b/src/AssetRecord.h @@ -0,0 +1,21 @@ +// +// Created by slinky on 5/14/26. +// + +#ifndef B_ENGINE_ASSETRECORD_H +#define B_ENGINE_ASSETRECORD_H + +#include +#include "uuid.h" + +#include "Types.h" + + +struct AssetRecord { + uuids::uuid uuid; + std::string sourcePath; + std::string cachePath; + AssetType assetType; +}; + +#endif //B_ENGINE_ASSETRECORD_H diff --git a/src/AssetRegistry.cpp b/src/AssetRegistry.cpp new file mode 100644 index 0000000..eba7beb --- /dev/null +++ b/src/AssetRegistry.cpp @@ -0,0 +1,80 @@ +// +// Created by slinky on 5/14/26. +// + +#include "AssetRegistry.h" + +#include +#include + +#include "uuid.h" + +std::unordered_map> AssetRegistry::_registry; + +uuids::uuid generate_uuid() +{ + thread_local auto gen = [] { + std::random_device rd; + + auto seed_data = + std::array{}; + + std::generate(seed_data.begin(), + seed_data.end(), + std::ref(rd)); + + std::seed_seq seq(seed_data.begin(), seed_data.end()); + + std::mt19937 engine(seq); + + return uuids::uuid_random_generator{engine}; + }(); + + return gen(); +} + +void AssetRegistry::read_source_folder(const std::string_view _folder) { + if (_folder.empty()) { + return; + } + + const Path path {_folder}; + Directory directory {path}; + for (const auto entry : directory) { + if (!entry.exists()) { + continue; + } + + if (entry.is_directory()) { + read_source_folder(entry.path().c_str()); + continue; + } + + uuid_t uuid; + generate_meta_file(entry.path()); + + + } +} + +bool AssetRegistry::does_meta_exist(const Path& path) { + Path meta = path; + meta += ".meta"; + return fs::exists(meta); +} + +void AssetRegistry::generate_meta_file(const Path &path) { + Path meta = path; + meta += ".meta"; + + if (fs::exists(meta)) { + return; + } + + AssetRecord record; + record.uuid = generate_uuid(); + record.sourcePath = path.c_str(); + + std::ofstream file {meta}; + file.close(); +} diff --git a/src/AssetRegistry.h b/src/AssetRegistry.h new file mode 100644 index 0000000..f5af95a --- /dev/null +++ b/src/AssetRegistry.h @@ -0,0 +1,38 @@ +// +// Created by slinky on 5/14/26. +// + +#ifndef B_ENGINE_ASSETREGISTRY_H +#define B_ENGINE_ASSETREGISTRY_H + +#include +#include +#include +#include +#include +#include + +#include "AssetRecord.h" + +#include "uuid.h" + +namespace fs = std::filesystem; + +using Directory = fs::recursive_directory_iterator; +using Path = fs::path; + +class AssetRegistry { +public: + static void read_source_folder(std::string_view _folder); + + static std::vector get_records(); + static AssetRegistry* get_record(uuid_t uuid); +private: + static std::unordered_map> _registry; + + static bool does_meta_exist(const Path& path); + static void generate_meta_file(const Path& path); +}; + + +#endif //B_ENGINE_ASSETREGISTRY_H diff --git a/src/Types.h b/src/Types.h new file mode 100644 index 0000000..b2f4663 --- /dev/null +++ b/src/Types.h @@ -0,0 +1,14 @@ +// +// Created by slinky on 5/14/26. +// + +#ifndef B_ENGINE_TYPES_H +#define B_ENGINE_TYPES_H + +enum class AssetType { + SHADER = 0, + TEXTURE = 1, + MODEL = 2 +}; + +#endif //B_ENGINE_TYPES_H