mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Fixed some prefab stuff and memory leak for assimp
This commit is contained in:
@@ -58,12 +58,15 @@ namespace Nuake
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto& m : j["Meshes"])
|
||||
if (j.contains("Meshes"))
|
||||
{
|
||||
Ref<Mesh> mesh = CreateRef<Mesh>();
|
||||
mesh->Deserialize(m);
|
||||
for (auto& m : j["Meshes"])
|
||||
{
|
||||
Ref<Mesh> mesh = CreateRef<Mesh>();
|
||||
mesh->Deserialize(m);
|
||||
|
||||
m_Meshes.push_back(mesh);
|
||||
m_Meshes.push_back(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace Nuake
|
||||
model->AddMesh(mesh);
|
||||
}
|
||||
|
||||
importer.FreeScene();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,11 @@ namespace Nuake
|
||||
{
|
||||
Ref<Prefab> Prefab::CreatePrefabFromEntity(Entity entity)
|
||||
{
|
||||
auto& parentC = entity.GetComponent<ParentComponent>();
|
||||
auto& nameComponent = entity.GetComponent<NameComponent>();
|
||||
|
||||
Ref<Prefab> prefab = CreateRef<Prefab>();
|
||||
ParentComponent parentC = entity.GetComponent<ParentComponent>();
|
||||
prefab->DisplayName = nameComponent.Name;
|
||||
prefab->EntityWalker(entity);
|
||||
prefab->Root = entity;
|
||||
return prefab;
|
||||
|
||||
@@ -6,16 +6,20 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
class Prefab : ISerializable
|
||||
{
|
||||
public:
|
||||
std::string DisplayName;
|
||||
std::string Description;
|
||||
std::string Path;
|
||||
std::vector<Entity> Entities;
|
||||
Entity Root;
|
||||
|
||||
static Ref<Prefab> CreatePrefabFromEntity(Entity entity);
|
||||
|
||||
static Ref<Prefab> New(const std::string& path);
|
||||
|
||||
Prefab()
|
||||
@@ -42,10 +46,14 @@ namespace Nuake {
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(Path);
|
||||
SERIALIZE_VAL(DisplayName);
|
||||
SERIALIZE_VAL(Description);
|
||||
|
||||
std::vector<json> entities = std::vector<json>();
|
||||
auto entities = std::vector<json>();
|
||||
for (Entity e : Entities)
|
||||
{
|
||||
entities.push_back(e.Serialize());
|
||||
}
|
||||
|
||||
j["Root"] = Root.GetComponent<NameComponent>().ID;
|
||||
SERIALIZE_VAL_LBL("Entities", entities);
|
||||
@@ -67,10 +75,23 @@ namespace Nuake {
|
||||
return false;
|
||||
|
||||
Path = j["Path"];
|
||||
|
||||
if (j.contains("DisplayName"))
|
||||
{
|
||||
DisplayName = j["DisplayName"];
|
||||
}
|
||||
|
||||
if (j.contains("Description"))
|
||||
{
|
||||
Description = j["Description"];
|
||||
}
|
||||
|
||||
if (j.contains("Entities"))
|
||||
{
|
||||
const auto& scene = Engine::GetCurrentScene();
|
||||
|
||||
std::map<uint32_t, uint32_t> newIdsLut;
|
||||
|
||||
for (json e : j["Entities"])
|
||||
{
|
||||
Entity entity = { scene->m_Registry.create(), scene.get() };
|
||||
@@ -81,27 +102,36 @@ namespace Nuake {
|
||||
if (nameComponent.ID == j["Root"])
|
||||
{
|
||||
isRoot = true; // We found the root entity of the prefab.
|
||||
auto& parentComponent = entity.GetComponent<ParentComponent>();
|
||||
parentComponent.HasParent = false;
|
||||
parentComponent.ParentID = 0;
|
||||
}
|
||||
|
||||
uint32_t oldId = nameComponent.ID;
|
||||
uint32_t newId = OS::GetTime();
|
||||
nameComponent.Name = scene->GetUniqueEntityName(nameComponent.Name);
|
||||
nameComponent.ID = OS::GetTime();
|
||||
nameComponent.ID = newId;
|
||||
|
||||
newIdsLut[oldId] = newId;
|
||||
|
||||
if (isRoot)
|
||||
{
|
||||
Root = entity;
|
||||
}
|
||||
|
||||
this->AddEntity(entity);
|
||||
AddEntity(entity);
|
||||
}
|
||||
|
||||
// Set reference to the parent entity to children
|
||||
for (auto& e : Entities)
|
||||
{
|
||||
auto parentC = e.GetComponent<ParentComponent>();
|
||||
if (!parentC.HasParent)
|
||||
if (e.GetID() == Root.GetID())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto parent = Engine::GetCurrentScene()->GetEntityByID(parentC.ParentID);
|
||||
auto& parentC = e.GetComponent<ParentComponent>();
|
||||
auto parent = Engine::GetCurrentScene()->GetEntityByID(newIdsLut[parentC.ParentID]);
|
||||
parent.AddChild(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user