diff --git a/.gitmodules b/.gitmodules index d7b1293..74b1520 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,3 +11,6 @@ [submodule "Hazel/vendor/glm"] path = Hazel/vendor/glm url = https://github.com/g-truc/glm.git +[submodule "Hazel/vendor/yaml-cpp"] + path = Hazel/vendor/yaml-cpp + url = https://github.com/jbeder/yaml-cpp.git diff --git a/Hazel/CMakeLists.txt b/Hazel/CMakeLists.txt index 7dabd08..b4dba14 100644 --- a/Hazel/CMakeLists.txt +++ b/Hazel/CMakeLists.txt @@ -1,14 +1,13 @@ set(PROJECT_NAME Hazel) project(${PROJECT_NAME}) -add_subdirectory(vendor/SDL) -set(SDL3_SHARED ON CACHE BOOL "Build SDL as shared library" FORCE) add_subdirectory(vendor/spdlog) add_subdirectory(vendor/GLAD) add_subdirectory(vendor/glm) +add_subdirectory(vendor/yaml-cpp) -file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE SOURCES "src/**.cpp") # stb_image set(STB_INCLUDE_DIR vendor/stb) @@ -27,6 +26,10 @@ file(GLOB IMGUI ${IMGUI_INCLUDE_DIR}/*.cpp ${IMGUI_INCLUDE_DIR}/backends/imgui_impl_opengl3.cpp ${IMGUI_INCLUDE_DIR}/backends/imgui_impl_sdl3.cpp) +set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE) +add_subdirectory(vendor/SDL) +set(SDL3_SHARED ON CACHE BOOL "Build SDL as shared library" FORCE) + add_library(${PROJECT_NAME} SHARED ${SOURCES} ${STB} @@ -49,6 +52,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC glad opengl32 glm::glm + yaml-cpp::yaml-cpp ) target_compile_definitions(${PROJECT_NAME} PRIVATE HZ_BUILD_DLL STB_IMAGE_IMPLEMENTATION HZ_PROFILE)# 编译DLL时定义 diff --git a/Hazel/src/Hazel/Renderer/OrthographicCameraController.cpp b/Hazel/src/Hazel/Renderer/OrthographicCameraController.cpp index 9977e00..9c5a5d3 100644 --- a/Hazel/src/Hazel/Renderer/OrthographicCameraController.cpp +++ b/Hazel/src/Hazel/Renderer/OrthographicCameraController.cpp @@ -26,11 +26,11 @@ namespace Hazel void OrthographicCameraController::OnUpdate(TimeStep ts) { HZ_PROFILE_FUNCTION(); - static const bool* state = SDL_GetKeyboardState(NULL); + const bool* state = SDL_GetKeyboardState(nullptr); float time = ts; if (state[SDL_SCANCODE_A]) - m_CameraPosition.x -= m_CameraTranslationSpeed * time; + m_CameraPosition.x -= m_CameraTranslationSpeed * time; else if (state[SDL_SCANCODE_D]) m_CameraPosition.x += m_CameraTranslationSpeed * time; diff --git a/Hazel/src/Hazel/Scene/Scene.h b/Hazel/src/Hazel/Scene/Scene.h index d7128d4..1c8d1bb 100644 --- a/Hazel/src/Hazel/Scene/Scene.h +++ b/Hazel/src/Hazel/Scene/Scene.h @@ -34,14 +34,12 @@ namespace Hazel template void OnComponentAdded(Entity entity, T& component); - - private: entt::registry m_Registry; - uint32_t m_ViewportWidth = 0, m_ViewportHeight = 0; friend class Entity; + friend class SceneSerializer; friend class SceneHierachyPanel; }; } diff --git a/Hazel/src/Hazel/Scene/SceneSerializer.cpp b/Hazel/src/Hazel/Scene/SceneSerializer.cpp new file mode 100644 index 0000000..3fbab90 --- /dev/null +++ b/Hazel/src/Hazel/Scene/SceneSerializer.cpp @@ -0,0 +1,260 @@ +// +// Created by sfd on 25-5-31. +// + +#include "SceneSerializer.h" + +#include + +#include "Components.h" +#include "Entity.h" +#include "yaml-cpp/yaml.h" + +namespace YAML +{ + template<> + struct convert + { + static Node encode(const glm::vec3& out) + { + Node node; + node.push_back(out.x); + node.push_back(out.y); + node.push_back(out.z); + node.SetStyle(EmitterStyle::Flow); + return node; + } + + static bool decode(const Node& node, glm::vec3& out) + { + if (node.size() != 3 && !node.IsSequence()) + return false; + out.x = node[0].as(); + out.y = node[1].as(); + out.z = node[2].as(); + return true; + } + }; + + template<> + struct convert + { + static Node encode(const glm::vec4& out) + { + Node node; + node.push_back(out.x); + node.push_back(out.y); + node.push_back(out.z); + node.push_back(out.w); + node.SetStyle(EmitterStyle::Flow); + return node; + } + + static bool decode(const Node& node, glm::vec4& out) + { + if (node.size() != 4 && !node.IsSequence()) + return false; + out.x = node[0].as(); + out.y = node[1].as(); + out.z = node[2].as(); + out.w = node[3].as(); + return true; + } + }; + + Emitter& operator<<(Emitter& out, const glm::vec3& value) + { + out << Flow; + out << BeginSeq << value.x << value.y << value.z << EndSeq; + return out; + } + + Emitter& operator<<(Emitter& out, const glm::vec4& value) + { + out << Flow; + out << BeginSeq << value.x << value.y << value.z << value.w << EndSeq; + return out; + } +} + +namespace Hazel +{ + + + + SceneSerializer::SceneSerializer(const Ref scene) + : m_Scene(scene) + { + } + + static void SerializeEntity(YAML::Emitter& out, Entity entity) + { + out << YAML::BeginMap; // entity + out << YAML::Key << "Entity" << YAML::Value << "123479283"; // TODO: entity ID goes here + + if (entity.HasComponent()) + { + out << YAML::Key << "TagComponent"; + + out << YAML::BeginMap; // TagComponent + + const auto& tag = entity.GetComponent().Tag; + out << YAML::Key << "Tag" << YAML::Value << tag; + + out << YAML::EndMap; // TagComponent + } + + if (entity.HasComponent()) + { + out << YAML::Key << "TransformComponent"; + out << YAML::BeginMap; // TransformComponent + + auto& transform = entity.GetComponent(); + out << YAML::Key << "Translation" << YAML::Value << transform.Translation; + out << YAML::Key << "Rotation" << YAML::Value << transform.Rotation; + out << YAML::Key << "Scale" << YAML::Value << transform.Scale; + + out << YAML::EndMap; // TransformComponent + } + + if (entity.HasComponent()) + { + out << YAML::Key << "CameraComponent"; + + out << YAML::BeginMap; // CameraComponent + + auto& cameraComponent = entity.GetComponent(); + auto& camera = cameraComponent.Camera; + + out << YAML::Key << "Camera" << YAML::Value; // CameraComponent + out << YAML::BeginMap; // Camera + + out << YAML::Key << "ProjectionType" << YAML::Value << (int)camera.GetProjectionType(); + out << YAML::Key << "PerspectiveVerticalFOV" << YAML::Value << camera.GetPerspectiveVerticalFOV(); + out << YAML::Key << "PerspectiveNear" << YAML::Value << camera.GetPerspectiveNearCLip(); + out << YAML::Key << "PerspectiveFar" << YAML::Value << camera.GetPerspectiveFarCLip(); + out << YAML::Key << "OrthographicSize" << YAML::Value << camera.GetOrthographicSize(); + out << YAML::Key << "OrthographicNear" << YAML::Value << camera.GetOrthographicNearCLip(); + out << YAML::Key << "OrthographicFar" << YAML::Value << camera.GetOrthographicFarCLip(); + + out << YAML::Key << "Primary" << YAML::Value << cameraComponent.Primary; + out << YAML::Key << "FixedAspectRatio" << YAML::Value << cameraComponent.FixedAspectRatio; + + out << YAML::EndMap; // Camera + out << YAML::EndMap; // CameraComponent + } + + if (entity.HasComponent()) + { + out << YAML::Key << "SpriteRendererComponent"; + + out << YAML::BeginMap; // SpriteRendererComponent + auto& spriteRendererComponent = entity.GetComponent(); + out << YAML::Key << "Color" << YAML::Value << spriteRendererComponent.Color; + out << YAML::EndMap; // SpriteRendererComponent + } + + out << YAML::EndMap; // entity + } + + void SceneSerializer::Serialize(const std::string& filepath) const + { + YAML::Emitter out; + out << YAML::BeginMap; + out << YAML::Key << "Scene" << YAML::Value << "Untitled"; + out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq; + m_Scene->m_Registry.view().each([&](auto entityID) + { + const Entity entity = {entityID, m_Scene.get()}; + if (!entity) + return; + + SerializeEntity(out, entity); + }); + + std::ofstream fout(filepath); + fout << out.c_str(); + } + + void SceneSerializer::SerializeRuntime(const std::string& filepath) + { + } + + bool SceneSerializer::Deserialize(const std::string& filepath) + { + const std::ifstream stream(filepath); + std::stringstream strStream; + strStream << stream.rdbuf(); + + YAML::Node data = YAML::Load(strStream.str()); + if (!data["Scene"]) + return false; + + auto sceneName = data["Scene"].as(); + + HZ_CORE_TRACE("Deserializing Scene {}", strStream.str()); + + auto entities = data["Entities"]; + if (entities) + { + for (auto entity : entities) + { + uint64_t uuid = entity["Entity"].as(); // TODO + + std::string name; + auto TagComponent = entity["TagComponent"]; + if (TagComponent) + name = TagComponent["Tag"].as(); + + HZ_CORE_TRACE("Deserializing Entity: {0}:({1})", name, uuid); + + Entity deserializedEntity = m_Scene->CreateEntity(name); + + auto transformComponent = entity["TransformComponent"]; + if (transformComponent) + { + auto& transform = deserializedEntity.GetComponent(); + transform.Translation = transformComponent["Translation"].as(); + transform.Rotation = transformComponent["Rotation"].as(); + transform.Scale = transformComponent["Scale"].as(); + } + + auto cameraComponent = entity["CameraComponent"]; + if (cameraComponent) + { + auto& camera = deserializedEntity.AddComponent(); + + auto cameraProps = cameraComponent["Camera"]; + camera.Camera.SetProjectionType((ScenceCamera::ProjectionType)cameraProps["ProjectionType"].as()); + + camera.Camera.SetPerspectiveVerticalFOV(cameraProps["PerspectiveVerticalFOV"].as()); + camera.Camera.SetPerspectiveNearClip(cameraProps["PerspectiveNear"].as()); + camera.Camera.SetPerspectiveFarClip(cameraProps["PerspectiveFar"].as()); + + camera.Camera.SetOrthographicSize(cameraProps["OrthographicSize"].as()); + camera.Camera.SetOrthographicNearClip(cameraProps["OrthographicNear"].as()); + camera.Camera.SetOrthographicFarClip(cameraProps["OrthographicFar"].as()); + + camera.Primary = cameraProps["Primary"].as(); + camera.FixedAspectRatio = cameraProps["FixedAspectRatio"].as(); + } + + auto spriteRendererComponent = entity["SpriteRendererComponent"]; + if (spriteRendererComponent) + { + auto& sprite = deserializedEntity.AddComponent(); + sprite.Color = spriteRendererComponent["Color"].as(); + } + + } + } + + return true; + } + + bool SceneSerializer::DeserializeRuntime(const std::string& filepath) + { + return false; + } + +} diff --git a/Hazel/src/Hazel/Scene/SceneSerializer.h b/Hazel/src/Hazel/Scene/SceneSerializer.h new file mode 100644 index 0000000..10dc653 --- /dev/null +++ b/Hazel/src/Hazel/Scene/SceneSerializer.h @@ -0,0 +1,27 @@ +// +// Created by sfd on 25-5-31. +// + +#ifndef SCENESERIALIZER_H +#define SCENESERIALIZER_H +#include "Scene.h" + +namespace Hazel +{ + class HAZEL_API SceneSerializer + { + public: + SceneSerializer(const Ref scene); + + void Serialize(const std::string& filepath) const; + void SerializeRuntime(const std::string& filepath); + + bool Deserialize(const std::string& filepath); + bool DeserializeRuntime(const std::string& filepath); + private: + Ref m_Scene; + }; + +} + +#endif //SCENESERIALIZER_H diff --git a/Hazel/src/Hazel/Utils/PlatformUtils.cpp b/Hazel/src/Hazel/Utils/PlatformUtils.cpp new file mode 100644 index 0000000..9569e38 --- /dev/null +++ b/Hazel/src/Hazel/Utils/PlatformUtils.cpp @@ -0,0 +1,5 @@ +// +// Created by sfd on 25-5-31. +// + +#include "PlatformUtils.h" diff --git a/Hazel/src/Hazel/Utils/PlatformUtils.h b/Hazel/src/Hazel/Utils/PlatformUtils.h new file mode 100644 index 0000000..52e7406 --- /dev/null +++ b/Hazel/src/Hazel/Utils/PlatformUtils.h @@ -0,0 +1,23 @@ +// +// Created by sfd on 25-5-31. +// + +#ifndef PLATFORMUTILS_H +#define PLATFORMUTILS_H + +#include +#include "Hazel/Core/Core.h" + +namespace Hazel +{ + class HAZEL_API FileDiaglogs + { + public: + // return empty strings if cancelled + static std::string OpenFile(const char* filter); + static std::string SaveFile(const char* filter); + }; +} + + +#endif //PLATFORMUTILS_H diff --git a/Hazel/src/Platform/Windows/WindowsPlatformUtils.cpp b/Hazel/src/Platform/Windows/WindowsPlatformUtils.cpp new file mode 100644 index 0000000..b0fc7a9 --- /dev/null +++ b/Hazel/src/Platform/Windows/WindowsPlatformUtils.cpp @@ -0,0 +1,5 @@ +// +// Created by sfd on 25-5-31. +// + +#include "WindowsPlatformUtils.h" diff --git a/Hazel/src/Platform/Windows/WindowsPlatformUtils.h b/Hazel/src/Platform/Windows/WindowsPlatformUtils.h new file mode 100644 index 0000000..7352a0e --- /dev/null +++ b/Hazel/src/Platform/Windows/WindowsPlatformUtils.h @@ -0,0 +1,74 @@ +// +// Created by sfd on 25-5-31. +// + +#ifndef WINDOWSPLATFORMUTILS_H +#define WINDOWSPLATFORMUTILS_H + +#include +#include + +#include +#include + +namespace Hazel +{ + std::string FileDiaglogs::OpenFile(const char* filter) + { + OPENFILENAME ofn; // common diaglog box structure + CHAR szFile[260] = { 0 }; + + + SDL_PropertiesID props = SDL_GetWindowProperties((SDL_Window*)Application::Get().GetWindow().GetNativeWindow()); + void * hwnd_ptr = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr); + + // Init OPENFILENAME + ZeroMemory(&ofn, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = (HWND)hwnd_ptr; + ofn.lpstrFile = szFile; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; + if (GetOpenFileName(&ofn) == TRUE) + { + return ofn.lpstrFile; + } + + return std::string(); + + } + + std::string FileDiaglogs::SaveFile(const char* filter) + { + OPENFILENAME ofn; // common diaglog box structure + CHAR szFile[260] = { 0 }; + + + SDL_PropertiesID props = SDL_GetWindowProperties((SDL_Window*)Application::Get().GetWindow().GetNativeWindow()); + void * hwnd_ptr = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr); + + // Init OPENFILENAME + ZeroMemory(&ofn, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = (HWND)hwnd_ptr; + ofn.lpstrFile = szFile; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; + if (GetSaveFileName(&ofn) == TRUE) + { + return ofn.lpstrFile; + } + + return std::string(); + + + } + +} + + +#endif //WINDOWSPLATFORMUTILS_H diff --git a/Hazel/vendor/yaml-cpp b/Hazel/vendor/yaml-cpp new file mode 160000 index 0000000..2f86d13 --- /dev/null +++ b/Hazel/vendor/yaml-cpp @@ -0,0 +1 @@ +Subproject commit 2f86d13775d119edbb69af52e5f566fd65c6953b diff --git a/Sandbox/src/DemoBox/GameLayer.cpp b/Sandbox/src/DemoBox/GameLayer.cpp deleted file mode 100644 index dbf1d0c..0000000 --- a/Sandbox/src/DemoBox/GameLayer.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Created by sfd on 25-5-18. -// - -#include "GameLayer.h" - -#include -#include -#include - -GameLayer::GameLayer() : Layer("GameLayer") , m_cameraController((float)(Application::Get().GetWindow().GetWidth()) / (float)(Application::Get().GetWindow().GetHeight())) -{ -} - - -void GameLayer::OnAttach() -{ -} - -void GameLayer::OnDetech() -{ -} - -void GameLayer::OnUpdate(TimeStep& ts) -{ - auto mouseState = SDL_GetMouseState(NULL, NULL); - static Uint32 prevMouseState = 0; - m_cameraController.OnUpdate(ts); - - RendererCommand::SetClearColor({0.2f, 0.2f, 0.2f, 1.0f}); - RendererCommand::Clear(); - - Renderer2D::BeginScene(m_cameraController.GetCamera()); - - Hazel::Renderer2D::DrawQuad({0.0f, 0.0f}, {1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}); - - Renderer2D::EndScene(); - - if ((mouseState & SDL_BUTTON_LMASK) && !(prevMouseState & SDL_BUTTON_LMASK)) - { - HZ_CORE_INFO("LEFT Mouse Clicked!"); - } - prevMouseState = mouseState; -} - -void GameLayer::OnEvent(SDL_Event& e) -{ - m_cameraController.OnEvent(e); -} - -void GameLayer::OnImGuiRender() -{ -} \ No newline at end of file diff --git a/Sandbox/src/DemoBox/GameLayer.h b/Sandbox/src/DemoBox/GameLayer.h deleted file mode 100644 index 1c428b1..0000000 --- a/Sandbox/src/DemoBox/GameLayer.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// Created by sfd on 25-5-18. -// - -#ifndef GAMELAYER_H -#define GAMELAYER_H -#include -#include - - -using namespace Hazel; - -class GameLayer : public Layer{ -public: - GameLayer(); - ~GameLayer() = default; - - void OnAttach() override; - void OnDetech() override; - void OnUpdate(TimeStep& ts) override; - void OnEvent(SDL_Event& e) override; - void OnImGuiRender() override; - -private: - OrthographicCameraController m_cameraController; -}; - - - -#endif //GAMELAYER_H diff --git a/Sandbox/src/Editor/EditorLayer.cpp b/Sandbox/src/Editor/EditorLayer.cpp index 6d96bd7..2e5f70f 100644 --- a/Sandbox/src/Editor/EditorLayer.cpp +++ b/Sandbox/src/Editor/EditorLayer.cpp @@ -5,21 +5,20 @@ #include "EditorLayer.h" #include -#include #include - -#include "glm/ext/matrix_clip_space.hpp" +#include +#include namespace Hazel { EditorLayer::EditorLayer() : Layer("HazelEditor"), m_CameraController((float)Application::Get().GetWindow().GetWidth() / (float)Application::Get().GetWindow().GetHeight()) { + } void EditorLayer::OnAttach() { - FrameBufferSpecification spec; spec.Width = Application::Get().GetWindow().GetWidth(); spec.Height = Application::Get().GetWindow().GetHeight(); @@ -40,8 +39,6 @@ namespace Hazel redSquare.AddComponent(glm::vec4{1.0f, 0.0f, 0.0f, 1.0f}); - - m_CameraEntity = m_ActiveScene->CreateEntity("Camera A"); m_CameraEntity.AddComponent(); m_PrimaryCamera = true; @@ -55,10 +52,10 @@ namespace Hazel class CameraController : public ScriptableEntity { public: - void OnUpdate(const TimeStep ts) - { + void OnUpdate(const TimeStep ts) override + { auto& translation = GetComponent().Translation; - static const auto state = SDL_GetKeyboardState(nullptr); + const auto state = SDL_GetKeyboardState(nullptr); if (state[SDL_SCANCODE_A]) translation.x -= ts * speed; if (state[SDL_SCANCODE_D]) @@ -77,6 +74,8 @@ namespace Hazel m_SceneHierachyPanel.SetContext(m_ActiveScene); + + m_State = SDL_GetKeyboardState(nullptr); } void EditorLayer::OnDetech() @@ -110,7 +109,7 @@ namespace Hazel RendererCommand::Clear(); - // Renderer2D::BeginScene(m_cameraController.GetCamera()); + // Renderer2D::BeginScene(m_CameraController.GetCamera()); // update Scene m_ActiveScene->OnUpdate(ts); @@ -192,6 +191,22 @@ namespace Hazel // ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen); // ImGui::MenuItem("Padding", NULL, &opt_padding); // ImGui::Separator(); + if (ImGui::MenuItem("New", "Ctrl+N")) + { + NewScene(); + } + + if (ImGui::MenuItem("Open...", "Ctrl+O")) + { + OpenScene(); + } + + if (ImGui::MenuItem("Save As...", "Ctrl+Shift+S")) + { + SaveScene(); + } + + ImGui::Separator(); if (ImGui::MenuItem("Exit")) { Hazel::Application::Get().Close(); } @@ -256,5 +271,59 @@ namespace Hazel { m_CameraController.OnEvent(e); } + +#define SHORTCUT_NEW (SDL_KMOD_CTRL | SDLK_N) +#define SHORTCUT_OPEN (SDL_KMOD_CTRL | SDLK_O) +#define SHORTCUT_SAVE_ALL (SDL_KMOD_CTRL | SDL_KMOD_SHIFT | SDLK_S) + + const auto mod = SDL_GetModState(); + const auto ctrl = (mod & SDL_KMOD_CTRL) ? SDL_KMOD_CTRL : 0; + const auto shift = (mod & SDL_KMOD_SHIFT) ? SDL_KMOD_SHIFT : 0; + + switch (ctrl | shift | e.key.key) + { + case SHORTCUT_NEW: + NewScene(); + break; + case SHORTCUT_OPEN: + OpenScene(); + break; + case SHORTCUT_SAVE_ALL: + SaveScene(); + break; + default: + break; + } + } + + void EditorLayer::SaveScene() + { + std::string filepath = FileDiaglogs::SaveFile("Hazel Scene (*.scene)\0*.scene\0"); + if (!filepath.empty()) + { + SceneSerializer serializer(m_ActiveScene); + serializer.Serialize(filepath); + } + } + + void EditorLayer::OpenScene() + { + std::string filepath = FileDiaglogs::OpenFile("Hazel Scene (*.scene)\0*.scene\0"); + if (!filepath.empty()) + { + m_ActiveScene = CreateRef(); + m_ActiveScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y); + m_SceneHierachyPanel.SetContext(m_ActiveScene); + + SceneSerializer serializer(m_ActiveScene); + serializer.Deserialize(filepath); + } + } + + void EditorLayer::NewScene() + { + m_ActiveScene = CreateRef(); + m_ActiveScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y); + m_SceneHierachyPanel.SetContext(m_ActiveScene); } } diff --git a/Sandbox/src/Editor/EditorLayer.h b/Sandbox/src/Editor/EditorLayer.h index 2539708..290bf79 100644 --- a/Sandbox/src/Editor/EditorLayer.h +++ b/Sandbox/src/Editor/EditorLayer.h @@ -22,6 +22,10 @@ namespace Hazel virtual void OnUpdate(TimeStep& ts) override; virtual void OnImGuiRender() override; virtual void OnEvent(SDL_Event& e) override; + private: + void SaveScene(); + void OpenScene(); + void NewScene(); private: OrthographicCameraController m_CameraController; @@ -45,6 +49,7 @@ namespace Hazel Ref m_FrameBuffer; SceneHierachyPanel m_SceneHierachyPanel; + const bool* m_State = nullptr; }; } diff --git a/Sandbox/src/Editor/Panels/SceneHierachyPanel.cpp b/Sandbox/src/Editor/Panels/SceneHierachyPanel.cpp index 1116a9b..cbbf696 100644 --- a/Sandbox/src/Editor/Panels/SceneHierachyPanel.cpp +++ b/Sandbox/src/Editor/Panels/SceneHierachyPanel.cpp @@ -18,16 +18,17 @@ namespace Hazel void SceneHierachyPanel::SetContext(const Ref& context) { m_Context = context; + m_SelectionContext = {}; } void SceneHierachyPanel::OnImGuiRender() { ImGui::Begin("Scene Hierachy"); - for (const auto entityID : m_Context->m_Registry.view()) + m_Context->m_Registry.view().each([&](auto entityID) { DrawEntityNode({entityID, m_Context.get()}); - } + }); if (ImGui::IsMouseDown(0) && ImGui::IsWindowHovered()) { @@ -185,6 +186,7 @@ namespace Hazel if (entity.HasComponent()) { + ImGui::PushID(&entity); auto& component = entity.GetComponent(); ImVec2 contextReginAvail = ImGui::GetContentRegionAvail(); @@ -219,7 +221,8 @@ namespace Hazel } if (removeComponent) - entity.RemoveComponent(); + entity.RemoveComponent(); + ImGui::PopID(); } }