Adding Level to handle entt world
This commit is contained in:
parent
30fcb71332
commit
5b4ae459ad
|
|
@ -3,7 +3,7 @@
|
|||
#include <NazaraEditor/Core/Core.hpp>
|
||||
#include <NazaraEditor/Core/Application/Action.hpp>
|
||||
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||
#include <NazaraEditor/Core/Application/World.hpp>
|
||||
#include <NazaraEditor/Core/Application/Level.hpp>
|
||||
#include <NazaraEditor/Core/UI/Window.hpp>
|
||||
#include <NazaraEditor/Core/Reflection/Math.hpp>
|
||||
#include <NazaraEditor/Core/Reflection/Core.hpp>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <NazaraEditor/Core/Core.hpp>
|
||||
#include <NazaraEditor/Core/Application/Action.hpp>
|
||||
#include <NazaraEditor/Core/Application/Level.hpp>
|
||||
#include <NazaraEditor/Core/UI/Window.hpp>
|
||||
#include <NazaraImgui/NazaraImgui.hpp>
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ namespace Nz
|
|||
: public Nz::Application<Nz::Graphics, Nz::Imgui, Nz::EditorCore>
|
||||
{
|
||||
public:
|
||||
NazaraSignal(OnWorldChanged, Nz::EnttWorld*);
|
||||
NazaraSignal(OnWorldChanged, Nz::Level&);
|
||||
|
||||
// Entity lifetime events
|
||||
NazaraSignal(OnEntityCreated, entt::handle);
|
||||
|
|
@ -30,8 +31,10 @@ namespace Nz
|
|||
|
||||
EditorBaseApplication();
|
||||
|
||||
void NewWorld();
|
||||
Nz::EnttWorld* GetCurrentWorld();
|
||||
Nz::Level& GetLevel();
|
||||
bool NewLevel();
|
||||
bool CloseLevel();
|
||||
bool OpenLevel(const std::filesystem::path& path);
|
||||
|
||||
entt::handle CreateEntity();
|
||||
|
||||
|
|
@ -44,12 +47,10 @@ namespace Nz
|
|||
|
||||
private:
|
||||
std::unique_ptr<Nz::WindowSwapchain> m_windowSwapchain;
|
||||
Nz::EnttWorld* m_world;
|
||||
|
||||
std::vector<std::unique_ptr<Nz::EditorWindow>> m_windows;
|
||||
|
||||
std::vector<std::unique_ptr<EditorAction>> m_actions;
|
||||
|
||||
static EditorBaseApplication* s_instance;
|
||||
Nz::Level m_level;
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <NazaraEditor/Core/Config.hpp>
|
||||
|
||||
#include <Nazara/Core/EnttWorld.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class EditorBaseApplication;
|
||||
|
||||
class NAZARAEDITOR_CORE_API Level final
|
||||
{
|
||||
public:
|
||||
Level(EditorBaseApplication* app);
|
||||
|
||||
inline bool IsValid() const { return m_world != nullptr; }
|
||||
|
||||
inline Nz::EnttWorld* GetEnttWorld() { return m_world; }
|
||||
inline const Nz::EnttWorld* GetEnttWorld() const { return m_world; }
|
||||
|
||||
entt::handle CreateEntity();
|
||||
bool CreateNewLevel();
|
||||
|
||||
protected:
|
||||
EditorBaseApplication* m_application;
|
||||
|
||||
Nz::EnttWorld* m_world;
|
||||
|
||||
std::filesystem::path m_path;
|
||||
std::string m_name;
|
||||
};
|
||||
}
|
||||
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
EditorBaseApplication* EditorBaseApplication::s_instance = nullptr;
|
||||
|
||||
EditorBaseApplication::EditorBaseApplication()
|
||||
: m_world(nullptr)
|
||||
: m_level(this)
|
||||
{
|
||||
s_instance = this;
|
||||
|
||||
|
|
@ -28,7 +26,7 @@ namespace Nz
|
|||
Nz::Imgui::Instance()->Init(window);
|
||||
ImGui::EnsureContextOnThisThread();
|
||||
|
||||
NewWorld();
|
||||
NewLevel();
|
||||
|
||||
AddUpdaterFunc(Interval{ Nz::Time::Milliseconds(16) }, [&](Nz::Time elapsed) {
|
||||
if (!window.IsOpen())
|
||||
|
|
@ -48,17 +46,14 @@ namespace Nz
|
|||
});
|
||||
}
|
||||
|
||||
Nz::EnttWorld* EditorBaseApplication::GetCurrentWorld()
|
||||
Nz::Level& EditorBaseApplication::GetLevel()
|
||||
{
|
||||
return m_world;
|
||||
return m_level;
|
||||
}
|
||||
|
||||
entt::handle EditorBaseApplication::CreateEntity()
|
||||
{
|
||||
if (m_world == nullptr)
|
||||
return {};
|
||||
|
||||
entt::handle entity = m_world->CreateEntity();
|
||||
entt::handle entity = m_level.CreateEntity();
|
||||
entity.emplace<Nz::NodeComponent>();
|
||||
|
||||
OnEntityCreated(entity);
|
||||
|
|
@ -66,9 +61,8 @@ namespace Nz
|
|||
return entity;
|
||||
}
|
||||
|
||||
void EditorBaseApplication::NewWorld()
|
||||
bool EditorBaseApplication::NewLevel()
|
||||
{
|
||||
auto& ecs = GetComponent<Nz::AppEntitySystemComponent>();
|
||||
m_world = &ecs.AddWorld<Nz::EnttWorld>();
|
||||
return m_level.CreateNewLevel();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#include <NazaraEditor/Core/Application/Level.hpp>
|
||||
|
||||
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Level::Level(EditorBaseApplication* app)
|
||||
: m_application(app)
|
||||
, m_world(nullptr)
|
||||
{}
|
||||
|
||||
entt::handle Level::CreateEntity()
|
||||
{
|
||||
return m_world->CreateEntity();
|
||||
}
|
||||
|
||||
bool Level::CreateNewLevel()
|
||||
{
|
||||
auto& ecs = m_application->GetComponent<Nz::AppEntitySystemComponent>();
|
||||
m_world = &ecs.AddWorld<Nz::EnttWorld>();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,10 +6,10 @@ namespace NzEditor
|
|||
{
|
||||
LevelWindow::LevelWindow(Nz::EditorBaseApplication* app)
|
||||
: Nz::EditorWindow(app, "Level")
|
||||
, m_currentWorld(app->GetCurrentWorld())
|
||||
, m_currentLevel(app->GetLevel())
|
||||
, m_dirty(true)
|
||||
{
|
||||
app->OnWorldChanged.Connect([this](Nz::EnttWorld* world) { m_currentWorld = world; m_dirty = true; });
|
||||
app->OnWorldChanged.Connect([this](Nz::Level&) { m_dirty = true; });
|
||||
app->OnEntityCreated.Connect([this](entt::handle) { m_dirty = true; });
|
||||
app->OnEntityDestroyed.Connect([this](entt::handle) { m_dirty = true; });
|
||||
app->OnEntityParentChanged.Connect([this](entt::handle) { m_dirty = true; });
|
||||
|
|
@ -41,7 +41,7 @@ namespace NzEditor
|
|||
m_rootNodes.clear();
|
||||
m_nodeToEntity.clear();
|
||||
|
||||
if (m_currentWorld == nullptr)
|
||||
if (!m_currentLevel.IsValid())
|
||||
return;
|
||||
|
||||
m_currentWorld->GetRegistry().each([&](const entt::entity entity) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue