Переместил менеджер моделей в UwURenderEngine, так как у него нет прямой зависимости от ядра и у ядра нет зависимости от него

This commit is contained in:
Jiga228
2025-10-27 23:15:02 +07:00
parent 740c80e8c7
commit 1ab74b8128
10 changed files with 8102 additions and 16 deletions
@@ -0,0 +1,65 @@
#include "ModelManager.hpp"
#include "Log/Log.hpp"
ModelManager::owner_counter::owner_counter(const owner_counter& other) : counter(other.counter.load()), model(other.model)
{
}
unsigned int ModelManager::FNV1aHash(const char* buf)
{
unsigned int h_val = 0x811c9dc5;
while (*buf)
{
h_val ^= static_cast<unsigned int>(*buf++);
h_val *= 0x01000193;
}
return h_val;
}
ModelManager::~ModelManager()
{
models.clear();
}
ModelManager::StaticModel* ModelManager::LoadModel(const std::string& name)
{
if (name.empty())
return nullptr;
unsigned int hash = FNV1aHash(name.c_str());
auto counter = models.find(hash);
if (counter != models.cend())
{
++counter->second.counter;
return counter->second.model;
}
Loging::Log("Load new model: " + name);
// Load model_data
owner_counter new_counter;
new_counter.counter.store(1);
new_counter.model = new StaticModel();
models.try_emplace(hash, new_counter);
return new_counter.model;
}
void ModelManager::FreeModel(const std::string& name)
{
if (name.empty())
return;
unsigned int hash = FNV1aHash(name.c_str());
auto counter = models.find(hash);
--counter->second.counter;
StaticModel* model = counter->second.model;
if (counter->second.counter.load() == 0)
{
Loging::Log("Free model: " + name);
models.erase(hash);
delete model;
}
}
@@ -0,0 +1,35 @@
#pragma once
#include <unordered_map>
#include <string>
#include <atomic>
class ModelManager
{
public:
class StaticModel
{
//DATA
};
struct owner_counter
{
std::atomic_ullong counter;
StaticModel* model;
owner_counter() = default;
owner_counter(const owner_counter& other);
};
private:
std::unordered_map<unsigned int, owner_counter> models;
static unsigned int FNV1aHash (const char *buf);
public:
~ModelManager();
StaticModel* LoadModel(const std::string& name);
void FreeModel(const std::string& name);
};
@@ -1,7 +1,6 @@
#include "UwURenderEngine.hpp"
#include <array>
#include <queue>
#include <set>
#include <stdexcept>
#include <fstream>
@@ -18,6 +17,8 @@ const std::vector<const char*> UwURenderEngine::deviceExtensions = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME
};
RENDER_ENGINE_FACTORY_GENERATE(UwURenderEngine)
#ifdef _DEBUG
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
@@ -1051,7 +1052,8 @@ void UwURenderEngine::create_surface()
}
UwURenderEngine::UwURenderEngine(CoreInstance& core):
core_(core)
core_(core),
model_manager_(new ModelManager)
#ifdef _DEBUG
,debug_messenger_(nullptr)
#endif
@@ -1,10 +1,12 @@
#pragma once
#include "RenderEngineBase.hpp"
#include "ModelManager.hpp"
#include <optional>
#include <vector>
#include <string>
#include <memory>
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
@@ -68,6 +70,7 @@ class UwURenderEngine : public RenderEngineBase
int current_frame_ = 0;
CoreInstance& core_;
std::unique_ptr<ModelManager> model_manager_;
VkInstance instance_ = VK_NULL_HANDLE;
VkSurfaceKHR surface_ = VK_NULL_HANDLE;
@@ -153,6 +156,5 @@ public:
void start() override;
void stop_render() const override;
ModelManager* GetModelManager() const { return model_manager_.get(); }
};
RENDER_ENGINE_FACTORY_GENERATE(UwURenderEngine)
File diff suppressed because it is too large Load Diff