Move classes Mesh and StaticMesh to UwURenderEngine project. Because they depended from UwURenderEngine

This commit is contained in:
Jiga228
2025-10-25 23:20:28 +07:00
parent 1f88e0f0b9
commit 740c80e8c7
13 changed files with 9 additions and 76 deletions
-2
View File
@@ -1,12 +1,10 @@
#include "ObjectFactory.hpp" #include "ObjectFactory.hpp"
#include "Actors/Mesh/StaticMesh.hpp"
#include "Game/Actors/Actor.hpp" #include "Game/Actors/Actor.hpp"
#include "Math/Vector.hpp" #include "Math/Vector.hpp"
std::vector<ObjectFactory> base_object_factories = { std::vector<ObjectFactory> base_object_factories = {
GENERATE_FACTORY_OBJECT(Actor) GENERATE_FACTORY_OBJECT(Actor)
GENERATE_FACTORY_OBJECT(StaticMesh)
GENERATE_FACTORY_OBJECT(Vector2D) GENERATE_FACTORY_OBJECT(Vector2D)
GENERATE_FACTORY_OBJECT(Vector3D) GENERATE_FACTORY_OBJECT(Vector3D)
}; };
+1 -44
View File
@@ -2,36 +2,6 @@
#include "Log/Log.hpp" #include "Log/Log.hpp"
ModelManager::StaticModel::StaticModel(const std::vector<Voxel>& voxels, std::string name):
name_(std::move(name)),
voxels_(voxels)
{
glm::ivec3 sum_moments{0, 0, 0};
int sum_masses = 0;
for (auto& i : voxels_)
{
sum_moments += glm::ivec3{i.loc.x * i.mass, i.loc.y * i.mass, i.loc.z * i.mass};
sum_masses += i.mass;
}
if(sum_masses != 0)
sum_moments /= sum_masses;
else if (!voxels_.empty())
{
sum_moments.x /= static_cast<int>(voxels_.size());
sum_moments.y /= static_cast<int>(voxels_.size());
sum_moments.z /= static_cast<int>(voxels_.size());
}
mass_center_ = sum_moments;
}
ModelManager::StaticModel::~StaticModel()
{
OnDestroy.Call(name_);
}
ModelManager::owner_counter::owner_counter(const owner_counter& other) : counter(other.counter.load()), model(other.model) ModelManager::owner_counter::owner_counter(const owner_counter& other) : counter(other.counter.load()), model(other.model)
{ {
} }
@@ -49,18 +19,8 @@ unsigned int ModelManager::FNV1aHash(const char* buf)
return h_val; return h_val;
} }
void ModelManager::OnDestroySometimeModelCaller(const std::string& name)
{
Loging::Log("Free model: " + name);
OnDestroySometimeModel.Call(name);
}
ModelManager::~ModelManager() ModelManager::~ModelManager()
{ {
for (const auto& [it, counter] : models)
{
counter.model->OnDestroy.unbind(this, &ModelManager::OnDestroySometimeModelCaller);
}
models.clear(); models.clear();
} }
@@ -78,14 +38,11 @@ ModelManager::StaticModel* ModelManager::LoadModel(const std::string& name)
Loging::Log("Load new model: " + name); Loging::Log("Load new model: " + name);
std::vector<Voxel> model_data;
// Load model_data // Load model_data
owner_counter new_counter; owner_counter new_counter;
new_counter.counter.store(1); new_counter.counter.store(1);
new_counter.model = new StaticModel(model_data, name); new_counter.model = new StaticModel();
new_counter.model->OnDestroy.bind(this, &ModelManager::OnDestroySometimeModelCaller);
models.try_emplace(hash, new_counter); models.try_emplace(hash, new_counter);
OnLoadSometimeModel.Call(new_counter.model);
return new_counter.model; return new_counter.model;
} }
+2 -25
View File
@@ -1,33 +1,15 @@
#pragma once #pragma once
#include <unordered_map> #include <unordered_map>
#include <vector>
#include <string> #include <string>
#include <Delegate/Delegate.h> #include <atomic>
#include <glm/glm.hpp>
class ModelManager class ModelManager
{ {
public: public:
struct Voxel
{
glm::vec3 loc, color;
int mass;
};
class StaticModel class StaticModel
{ {
std::string name_; //DATA
std::vector<Voxel> voxels_;
glm::vec3 mass_center_;
public:
Delegate<const std::string&> OnDestroy;
StaticModel(const std::vector<Voxel>& voxels, std::string name);
~StaticModel();
const std::vector<Voxel>& GetVoxels() const { return voxels_; }
glm::vec3 GetMassCenter() const { return mass_center_; }
const std::string& GetName() const { return name_; }
}; };
struct owner_counter struct owner_counter
@@ -45,12 +27,7 @@ private:
static unsigned int FNV1aHash (const char *buf); static unsigned int FNV1aHash (const char *buf);
void OnDestroySometimeModelCaller(const std::string& name);
public: public:
Delegate<std::string> OnDestroySometimeModel;
Delegate<StaticModel*> OnLoadSometimeModel;
~ModelManager(); ~ModelManager();
StaticModel* LoadModel(const std::string& name); StaticModel* LoadModel(const std::string& name);
-1
View File
@@ -7,7 +7,6 @@
#include "RTTI.h" #include "RTTI.h"
#include "Game/Actors/Actor.hpp" #include "Game/Actors/Actor.hpp"
#include "Game/Actors/Mesh/Mesh.hpp"
#include "Types/object_ptr.hpp" #include "Types/object_ptr.hpp"
class GameInstance; class GameInstance;
+1
View File
@@ -8,6 +8,7 @@ add_executable(${GAME_NAME} ${SRC})
target_link_libraries(${GAME_NAME} PRIVATE Core UwURenderEngine) target_link_libraries(${GAME_NAME} PRIVATE Core UwURenderEngine)
target_include_directories(${GAME_NAME} PRIVATE target_include_directories(${GAME_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/Core ${PROJECT_SOURCE_DIR}/Core
${PROJECT_SOURCE_DIR}/UwURenderEngine
) )
if(MSVC) if(MSVC)
+2
View File
@@ -1,7 +1,9 @@
#include "Game/ObjectFactory.hpp" #include "Game/ObjectFactory.hpp"
#include "../Actors/TestActor.h" #include "../Actors/TestActor.h"
#include "Game/Actors/Mesh/StaticMesh.hpp"
FACTORIES_LIST{ FACTORIES_LIST{
GENERATE_FACTORY_OBJECT(StaticMesh)
GENERATE_FACTORY_OBJECT(TestActor) GENERATE_FACTORY_OBJECT(TestActor)
}; };
+1
View File
@@ -3,6 +3,7 @@
#include "Game/GameInstance.hpp" #include "Game/GameInstance.hpp"
#include "Game/SaveMap/SaveMap.hpp" #include "Game/SaveMap/SaveMap.hpp"
#include "Log/Log.hpp" #include "Log/Log.hpp"
#include "Game/Actors/Mesh/Mesh.hpp"
TestWorld::TestWorld(GameInstance& game_instance) : World(game_instance) TestWorld::TestWorld(GameInstance& game_instance) : World(game_instance)
{} {}
@@ -2,7 +2,7 @@
#include <string> #include <string>
#include "../Actor.hpp" #include "Game/Actors/Actor.hpp"
GENERATE_META(Mesh) GENERATE_META(Mesh)
class Mesh : public Actor class Mesh : public Actor
@@ -12,9 +12,7 @@
#include "Game/GameInstance.hpp" #include "Game/GameInstance.hpp"
#include "Game/World/World.hpp" #include "Game/World/World.hpp"
#include "Game/Actors/Mesh/Mesh.hpp" #include "../Game/Actors/Mesh/Mesh.hpp"
#include "GLFW/glfw3.h"
const std::vector<const char*> UwURenderEngine::deviceExtensions = { const std::vector<const char*> UwURenderEngine::deviceExtensions = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME VK_KHR_SWAPCHAIN_EXTENSION_NAME