diff --git a/include/NazaraEditor/Core.hpp b/include/NazaraEditor/Core.hpp index 6e4cc9f..6bee6a2 100644 --- a/include/NazaraEditor/Core.hpp +++ b/include/NazaraEditor/Core.hpp @@ -1,6 +1,9 @@ #pragma once #include +#include +#include +#include #include #include #include diff --git a/include/NazaraEditor/Core/Application/Action.hpp b/include/NazaraEditor/Core/Application/Action.hpp new file mode 100644 index 0000000..3e04fdf --- /dev/null +++ b/include/NazaraEditor/Core/Application/Action.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include + +#include + +#include + +#include + +namespace Nz +{ + class EditorAction + { + public: + struct Properties + { + std::string name; + std::string description; + Nz::Shortcut shortcut; + + Nz::Texture* icon; + }; + + EditorAction(const Properties& properties) + : m_properties(std::make_shared(properties)) + {} + ~EditorAction() = default; + + EditorAction(const EditorAction&) = delete; + EditorAction& operator=(const EditorAction&) = delete; + EditorAction(EditorAction&&) = delete; + EditorAction& operator=(EditorAction&&) = delete; + + virtual void Execute() = 0; + virtual void Revert() = 0; + virtual EditorAction* Clone() const = 0; + + protected: + EditorAction(const std::shared_ptr& properties) + : m_properties(properties) + {} + + std::shared_ptr m_properties; + }; +} \ No newline at end of file diff --git a/include/NazaraEditor/Core/Application/BaseApplication.hpp b/include/NazaraEditor/Core/Application/BaseApplication.hpp new file mode 100644 index 0000000..6719b6d --- /dev/null +++ b/include/NazaraEditor/Core/Application/BaseApplication.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace Nz +{ + class NAZARAEDITOR_CORE_API EditorBaseApplication + : public Nz::Application + { + public: + NazaraSignal(OnWorldChanged, Nz::EnttWorld*); + + // Entity lifetime events + NazaraSignal(OnEntityCreated, entt::handle); + NazaraSignal(OnEntityDestroyed, entt::handle); + NazaraSignal(OnEntityParentChanged, entt::handle); + + // Entity selection events + NazaraSignal(OnEntitySelected, entt::handle); + NazaraSignal(OnEntityDeselected, entt::handle); + + EditorBaseApplication(); + + void NewWorld(); + Nz::EnttWorld* GetCurrentWorld(); + + entt::handle CreateEntity(); + + template + void RegisterWindow() + { + static_assert(std::is_base_of::value, "Register Window should be called with a subclass of Nz::EditorWindow"); + m_windows.push_back(std::make_unique(this)); + } + + private: + std::unique_ptr m_windowSwapchain; + Nz::EnttWorld* m_world; + + std::vector> m_windows; + + std::vector> m_actions; + + static EditorBaseApplication* s_instance; + }; +} \ No newline at end of file diff --git a/include/NazaraEditor/Core/Application/Shortcut.hpp b/include/NazaraEditor/Core/Application/Shortcut.hpp new file mode 100644 index 0000000..77b1ffe --- /dev/null +++ b/include/NazaraEditor/Core/Application/Shortcut.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace Nz +{ + struct Shortcut + { + + }; +} \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/BaseApplication.cpp b/src/NazaraEditor/Core/Application/BaseApplication.cpp new file mode 100644 index 0000000..d657cbf --- /dev/null +++ b/src/NazaraEditor/Core/Application/BaseApplication.cpp @@ -0,0 +1,74 @@ +#include + +namespace Nz +{ + EditorBaseApplication* EditorBaseApplication::s_instance = nullptr; + + EditorBaseApplication::EditorBaseApplication() + : m_world(nullptr) + { + s_instance = this; + + auto& windowing = AddComponent(); + + std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); + + std::string windowTitle = "Nazara Editor"; + Nz::Window& window = windowing.CreateWindow(Nz::VideoMode(1280, 720, 32), windowTitle); + m_windowSwapchain = std::make_unique(device, window); + + // connect basic handler + window.GetEventHandler().OnQuit.Connect([&window](const auto* handler) { + NazaraUnused(handler); + window.Close(); + }); + + AddComponent(); + + Nz::Imgui::Instance()->Init(window); + ImGui::EnsureContextOnThisThread(); + + NewWorld(); + + AddUpdaterFunc(Interval{ Nz::Time::Milliseconds(16) }, [&](Nz::Time elapsed) { + if (!window.IsOpen()) + return; + + window.ProcessEvents(); + + Nz::RenderFrame frame = m_windowSwapchain->AcquireFrame(); + if (!frame) + return; + + Nz::Imgui::Instance()->Update(window, elapsed.AsSeconds()); + + Nz::Imgui::Instance()->Render(m_windowSwapchain.get(), frame); + + frame.Present(); + }); + } + + Nz::EnttWorld* EditorBaseApplication::GetCurrentWorld() + { + return m_world; + } + + entt::handle EditorBaseApplication::CreateEntity() + { + if (m_world == nullptr) + return {}; + + entt::handle entity = m_world->CreateEntity(); + entity.emplace(); + + OnEntityCreated(entity); + OnEntitySelected(entity); + return entity; + } + + void EditorBaseApplication::NewWorld() + { + auto& ecs = GetComponent(); + m_world = &ecs.AddWorld(); + } +} \ No newline at end of file