started working on asset registry
This commit is contained in:
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