started working on asset registry
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
1
_ThirdParty/uuid
vendored
Submodule
1
_ThirdParty/uuid
vendored
Submodule
Submodule _ThirdParty/uuid added at 3afe7193fa
21
src/AssetRecord.h
Normal file
21
src/AssetRecord.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by slinky on 5/14/26.
|
||||
//
|
||||
|
||||
#ifndef B_ENGINE_ASSETRECORD_H
|
||||
#define B_ENGINE_ASSETRECORD_H
|
||||
|
||||
#include <string>
|
||||
#include "uuid.h"
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
|
||||
struct AssetRecord {
|
||||
uuids::uuid uuid;
|
||||
std::string sourcePath;
|
||||
std::string cachePath;
|
||||
AssetType assetType;
|
||||
};
|
||||
|
||||
#endif //B_ENGINE_ASSETRECORD_H
|
||||
80
src/AssetRegistry.cpp
Normal file
80
src/AssetRegistry.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// Created by slinky on 5/14/26.
|
||||
//
|
||||
|
||||
#include "AssetRegistry.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include "uuid.h"
|
||||
|
||||
std::unordered_map<uuids::uuid, std::unique_ptr<AssetRegistry>> AssetRegistry::_registry;
|
||||
|
||||
uuids::uuid generate_uuid()
|
||||
{
|
||||
thread_local auto gen = [] {
|
||||
std::random_device rd;
|
||||
|
||||
auto seed_data =
|
||||
std::array<int, std::mt19937::state_size>{};
|
||||
|
||||
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();
|
||||
}
|
||||
38
src/AssetRegistry.h
Normal file
38
src/AssetRegistry.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by slinky on 5/14/26.
|
||||
//
|
||||
|
||||
#ifndef B_ENGINE_ASSETREGISTRY_H
|
||||
#define B_ENGINE_ASSETREGISTRY_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <uuid/uuid.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
#include <filesystem>
|
||||
|
||||
#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<AssetRegistry*> get_records();
|
||||
static AssetRegistry* get_record(uuid_t uuid);
|
||||
private:
|
||||
static std::unordered_map<uuids::uuid, std::unique_ptr<AssetRegistry>> _registry;
|
||||
|
||||
static bool does_meta_exist(const Path& path);
|
||||
static void generate_meta_file(const Path& path);
|
||||
};
|
||||
|
||||
|
||||
#endif //B_ENGINE_ASSETREGISTRY_H
|
||||
14
src/Types.h
Normal file
14
src/Types.h
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user