mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Quake brushes are not deserialized correctly, meaning you can build navmesh without rebuilding the quake map first.
This commit is contained in:
@@ -86,7 +86,7 @@ public:
|
||||
{
|
||||
for (auto& mesh : component.m_Brushes)
|
||||
{
|
||||
if (mesh.HasComponent<ModelComponent>())\
|
||||
if (mesh.HasComponent<ModelComponent>())
|
||||
{
|
||||
TransformComponent& transformComponent = mesh.GetComponent<TransformComponent>();
|
||||
for (auto& mesh : mesh.GetComponent<ModelComponent>().ModelResource->GetMeshes())
|
||||
|
||||
@@ -66,6 +66,9 @@ p = j[#p]; \
|
||||
#define DESERIALIZE_COMPONENT(c) \
|
||||
if(j.contains(#c)) \
|
||||
AddComponent<c>().Deserialize(j[#c]);
|
||||
#define POSTDESERIALIZE_COMPONENT(c) \
|
||||
if(HasComponent<c>()) \
|
||||
GetComponent<c>().PostDeserialize(*m_Scene);
|
||||
|
||||
class ISerializable
|
||||
{
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace Nuake {
|
||||
public:
|
||||
std::vector<Ref<Mesh>> m_Meshes;
|
||||
std::vector<Entity> m_Brushes;
|
||||
std::vector<int> m_SerializedBrushIDs;
|
||||
|
||||
std::string Path;
|
||||
float ScaleFactor = 1.0f;
|
||||
bool HasCollisions = false;
|
||||
@@ -26,6 +28,7 @@ namespace Nuake {
|
||||
SERIALIZE_VAL(HasCollisions);
|
||||
SERIALIZE_VAL(Path);
|
||||
SERIALIZE_VAL(AutoRebuild);
|
||||
|
||||
for (uint32_t i = 0; i < std::size(m_Brushes); i++)
|
||||
{
|
||||
j["Brushes"][i] = m_Brushes[i].GetID();
|
||||
@@ -46,11 +49,13 @@ namespace Nuake {
|
||||
this->AutoRebuild = j["AutoRebuild"];
|
||||
}
|
||||
|
||||
m_Brushes.clear();
|
||||
|
||||
if (j.contains("Brushes"))
|
||||
{
|
||||
for (auto& b : j["Brushes"])
|
||||
{
|
||||
//m_Brushes.push_back(Engine::GetCurrentScene()->GetEntityByID(b));
|
||||
m_SerializedBrushIDs.push_back(b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,5 +63,17 @@ namespace Nuake {
|
||||
this->HasCollisions = j["HasCollisions"];
|
||||
return true;
|
||||
}
|
||||
|
||||
void PostDeserialize(Scene& scene)
|
||||
{
|
||||
m_Brushes.clear();
|
||||
|
||||
for (auto& b : m_SerializedBrushIDs)
|
||||
{
|
||||
m_Brushes.push_back(scene.GetEntityByID(b));
|
||||
}
|
||||
|
||||
m_SerializedBrushIDs.clear();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,6 +114,11 @@ namespace Nuake
|
||||
return true;
|
||||
}
|
||||
|
||||
void Entity::PostDeserialize()
|
||||
{
|
||||
POSTDESERIALIZE_COMPONENT(QuakeMapComponent);
|
||||
}
|
||||
|
||||
Entity::Entity(entt::entity handle, Scene* scene)
|
||||
{
|
||||
m_EntityHandle = handle;
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace Nuake
|
||||
|
||||
json Serialize() override;
|
||||
bool Deserialize(const json& str);
|
||||
void PostDeserialize();
|
||||
|
||||
Scene* GetScene() const
|
||||
{
|
||||
|
||||
@@ -557,6 +557,7 @@ namespace Nuake
|
||||
m_EditorCamera->Deserialize(j["m_EditorCamera"]);
|
||||
}
|
||||
|
||||
// TODO: Move this to post deserialize.
|
||||
auto view = m_Registry.view<ParentComponent>();
|
||||
for (auto e : view)
|
||||
{
|
||||
@@ -569,6 +570,14 @@ namespace Nuake
|
||||
parentEntity.AddChild(entity);
|
||||
}
|
||||
|
||||
// This will turn the deserialized entity ids into actual Entities.
|
||||
// This has to be done after the whole scene has been deserialized
|
||||
// to make sure we can fetch the id in the scene. Otherwise, we could
|
||||
m_Registry.each([this](auto e) {
|
||||
auto entity = Entity{ e, this };
|
||||
entity.PostDeserialize();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -382,6 +382,8 @@ namespace Nuake {
|
||||
ent.GetComponent<NameComponent>().IsPrefab = true;
|
||||
|
||||
QuakeMapComponent& quakeMapC = ent.GetComponent<QuakeMapComponent>();
|
||||
quakeMapC.m_Brushes.clear();
|
||||
|
||||
ScaleFactor = quakeMapC.ScaleFactor;
|
||||
Scene* m_Scene = ent.GetScene();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user