From d53f9cf2355995b6c21cce5493c89d76c00296a3 Mon Sep 17 00:00:00 2001 From: Duckie Date: Mon, 2 Oct 2023 16:09:59 +0530 Subject: [PATCH] feat: add editor --- CMake/FindDucktape.cmake | 1 + CMakeLists.txt | 31 +++- Editor/CMakeLists.txt | 28 +++ Editor/Editor.cpp | 255 +++++++++++++++++++++++++++ Editor/Editor.h | 98 ++++++++++ Editor/Panels/GameView.h | 42 +++++ Editor/Panels/Panel.h | 39 ++++ Editor/Panels/WorldOutliner.h | 62 +++++++ Engine/CMakeLists.txt | 41 ++--- Engine/Components/Camera.cpp | 2 +- Engine/Components/Camera.h | 17 +- Engine/Components/SpriteRenderer.cpp | 2 +- Engine/Components/SpriteRenderer.h | 15 +- Engine/Components/Tag.h | 2 +- Engine/Components/Transform.cpp | 2 +- Engine/Components/Transform.h | 2 +- Engine/Core/Context.h | 2 +- Engine/Core/Error.cpp | 72 ++++++++ Engine/Core/Error.h | 91 +++------- Engine/Core/InputManager.cpp | 10 +- Engine/Core/InputManager.h | 42 ++--- Engine/Core/Window.cpp | 99 ++++++++++- Engine/Core/Window.h | 128 +++----------- Engine/ECS/Component.h | 2 +- Engine/ECS/Entity.h | 2 +- Engine/ECS/Scene.cpp | 42 +++++ Engine/ECS/Scene.h | 30 ++-- Engine/ECS/SceneManager.cpp | 24 ++- Engine/ECS/SceneManager.h | 24 +-- Engine/Renderer/Material.h | 2 +- Engine/Renderer/Mesh.cpp | 2 +- Engine/Renderer/Mesh.h | 2 +- Engine/Renderer/Renderer.cpp | 22 +-- Engine/Renderer/Renderer.h | 43 +++-- Engine/Renderer/Shader.cpp | 2 +- Engine/Renderer/Shader.h | 15 +- Engine/Renderer/Texture.cpp | 4 +- Engine/Renderer/Texture.h | 2 +- Engine/Renderer/Vertex.h | 2 +- Engine/Utils/math.h | 2 +- Engine/dtpch.cpp | 2 +- Engine/dtpch.h | 13 +- Runtime/CMakeLists.txt | 42 ++--- Runtime/Main.cpp | 37 +++- 44 files changed, 1039 insertions(+), 360 deletions(-) create mode 100644 Editor/CMakeLists.txt create mode 100644 Editor/Editor.cpp create mode 100644 Editor/Editor.h create mode 100644 Editor/Panels/GameView.h create mode 100644 Editor/Panels/Panel.h create mode 100644 Editor/Panels/WorldOutliner.h create mode 100644 Engine/Core/Error.cpp create mode 100644 Engine/ECS/Scene.cpp diff --git a/CMake/FindDucktape.cmake b/CMake/FindDucktape.cmake index b1cf9172..9ec82628 100644 --- a/CMake/FindDucktape.cmake +++ b/CMake/FindDucktape.cmake @@ -10,6 +10,7 @@ endif () set (Ducktape_INCLUDE_DIR ${Ducktape_ROOT_DIR}/Engine; + ${Ducktape_ROOT_DIR}/Editor; ${Ducktape_ROOT_DIR}/Runtime; ${Ducktape_ROOT_DIR}/Extern/; ${Ducktape_ROOT_DIR}/Extern/glm/; diff --git a/CMakeLists.txt b/CMakeLists.txt index cb23bbeb..dd87ff13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,25 @@ +# MIT License + +# Copyright (c) 2021 - 2023 Aryan Baburajan + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + cmake_minimum_required (VERSION 3.20) project ("Ducktape" VERSION 1.0.0) @@ -13,10 +35,12 @@ set (GLFW_BUILD_DOCS OFF) set (GLFW_BUILD_TESTS OFF) set (GLFW_BUILD_EXAMPLES OFF) +option (DT_EXPORT "Build the project for export." OFFz) -# if DT_BUILD_EDITOR -set (BUILD_SHARED_LIBS ON CACHE BOOL "") -# end if +if (NOT DT_EXPORT) + set (BUILD_SHARED_LIBS ON CACHE BOOL "") + add_compile_definitions(DT_EXPORT) +endif () set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/Extern/assimp/cmake-modules;${CMAKE_MODULE_PATH}") @@ -47,5 +71,6 @@ link_directories (${Ducktape_LIBRARY_DIR}) link_libraries (${Ducktape_LIBRARY}) add_subdirectory ("${PROJECT_SOURCE_DIR}/Engine") +add_subdirectory ("${PROJECT_SOURCE_DIR}/Editor") add_subdirectory ("${PROJECT_SOURCE_DIR}/Runtime") add_subdirectory ("${PROJECT_SOURCE_DIR}/Sandbox/") \ No newline at end of file diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt new file mode 100644 index 00000000..552355e1 --- /dev/null +++ b/Editor/CMakeLists.txt @@ -0,0 +1,28 @@ +# MIT License + +# Copyright (c) 2021 - 2023 Aryan Baburajan + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +cmake_minimum_required (VERSION 3.20) + +file (GLOB_RECURSE dt_source_list "${PROJECT_SOURCE_DIR}/Editor/**/*.cpp" "${PROJECT_SOURCE_DIR}/Editor/*.cpp") +add_library (DucktapeEditor SHARED ${dt_source_list}) +set_target_properties (DucktapeEditor PROPERTIES PREFIX "") +target_precompile_headers(DucktapeEditor PUBLIC "${PROJECT_SOURCE_DIR}/Engine/dtpch.h") \ No newline at end of file diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp new file mode 100644 index 00000000..0e973f5d --- /dev/null +++ b/Editor/Editor.cpp @@ -0,0 +1,255 @@ +/* +MIT License + +Copyright (c) 2021 - 2023 Aryan Baburajan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include +#include + +#include +#include +#include +#include +#include + +namespace DT +{ + Editor::Editor(Context &ctx) + { + window = ctx.GetService().Fatal("Editor::Editor()"); + renderer = ctx.GetService().Fatal("Editor::Editor()"); + + ImGui::CreateContext(); + ImGui_ImplGlfw_InitForOpenGL(window->GetRawWindowPointer(), true); + ImGui_ImplOpenGL3_Init("#version 440"); + + ImGuiIO &io = ImGui::GetIO(); + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + io.ConfigDragClickToInputText = true; + + // io.Fonts->AddFontFromFileTTF((DUCKTAPE_ROOT_DIR / "Resources" / "Editor" / "Fonts" / "Roboto" / "Roboto-Regular.ttf").string().c_str(), 15.f); + SetDarkTheme(); + MaximizeWindow(); + } + + Editor::~Editor() + { + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + } + + void Editor::Init(Context &ctx) + { + for (std::pair &panel : panels) + if (panel.second->isOpen) + panel.second->Init(ctx); + } + + void Editor::NewFrame() + { + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); + } + + void Editor::Tick(Context &ctx, const float &dt) + { + dockspaceId = ImGui::DockSpaceOverViewport(); + + for (std::pair &panel : panels) + if (panel.second->isOpen) + panel.second->Tick(ctx, dt); + } + + void Editor::EndFrame() + { + ImGui::EndFrame(); + ImGui::Render(); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + renderer->BindFrameBuffer(renderer->GetRenderFBO()); + } + + + void Editor::Close() + { + glfwSetWindowShouldClose(window->GetRawWindowPointer(), true); + } + + void Editor::SetTitle(const std::string &title) + { + glfwSetWindowTitle(window->GetRawWindowPointer(), title.c_str()); + } + + glm::vec2 Editor::GetWindowPos() + { + int x, y; + glfwGetWindowPos(window->GetRawWindowPointer(), &x, &y); + return glm::vec2(x, y); + } + + void Editor::SetWindowPos(const glm::vec2 &pos) + { + glfwSetWindowPos(window->GetRawWindowPointer(), pos.x, pos.y); + } + + glm::vec2 Editor::GetWindowSize() + { + int width, height; + glfwGetWindowSize(window->GetRawWindowPointer(), &width, &height); + return glm::vec2(width, height); + } + + void Editor::SetWindowSizeLimits(const glm::vec2 &minSize, const glm::vec2 &maxSize) + { + glfwSetWindowSizeLimits(window->GetRawWindowPointer(), minSize.x, minSize.y, maxSize.x, maxSize.y); + } + + void Editor::SetWindowAspectRatio(const int &numerator, const int &denominator) + { + glfwSetWindowAspectRatio(window->GetRawWindowPointer(), numerator, denominator); + } + + void Editor::SetWindowSize(const glm::vec2 &size) + { + glfwSetWindowSize(window->GetRawWindowPointer(), size.x, size.y); + } + + glm::vec2 Editor::GetWindowContentScale() + { + float x, y; + glfwGetWindowContentScale(window->GetRawWindowPointer(), &x, &y); + return glm::vec2(x, y); + } + + float Editor::GetWindowOpacity() + { + return glfwGetWindowOpacity(window->GetRawWindowPointer()); + } + + void Editor::SetWindowOpacity(const float &opacity) + { + glfwSetWindowOpacity(window->GetRawWindowPointer(), opacity); + } + + void Editor::IconifyWindow() + { + glfwIconifyWindow(window->GetRawWindowPointer()); + } + + void Editor::RestoreWindow() + { + glfwRestoreWindow(window->GetRawWindowPointer()); + } + + void Editor::MaximizeWindow() + { + glfwMaximizeWindow(window->GetRawWindowPointer()); + } + + void Editor::ShowWindow() + { + glfwShowWindow(window->GetRawWindowPointer()); + } + + void Editor::HideWindow() + { + glfwHideWindow(window->GetRawWindowPointer()); + } + + void Editor::FocusWindow() + { + glfwFocusWindow(window->GetRawWindowPointer()); + } + + void Editor::RequestWindowAttention() + { + glfwRequestWindowAttention(window->GetRawWindowPointer()); + } + + void Editor::SetVSync(const bool &vsync) + { + if (vsync) + glfwSwapInterval(1); + else + glfwSwapInterval(0); + } + +#define rgb(r, g, b) ImVec4(r / 255.0f, g / 255.0f, b / 255.0f, 1.00f) + + void Editor::SetDarkTheme() + { + ImGui::StyleColorsDark(); + + // ImGuiStyle &style = ImGui::GetStyle(); + // style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + // style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + // style.Colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f); + // style.Colors[ImGuiCol_ChildBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f); + // style.Colors[ImGuiCol_PopupBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f); + // style.Colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); + // style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + // style.Colors[ImGuiCol_FrameBg] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); + // style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f); + // style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f); + // style.Colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f); + // style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f); + // style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); + // style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); + // style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); + // style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); + // style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); + // style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f); + // style.Colors[ImGuiCol_CheckMark] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f); + // style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f); + // style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.08f, 0.50f, 0.72f, 1.00f); + // style.Colors[ImGuiCol_Button] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); + // style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f); + // style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f); + // style.Colors[ImGuiCol_Header] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f); + // style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); + // style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f); + // style.Colors[ImGuiCol_Separator] = style.Colors[ImGuiCol_Border]; + // style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.41f, 0.42f, 0.44f, 1.00f); + // style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); + // style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + // style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.29f, 0.30f, 0.31f, 0.67f); + // style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); + // style.Colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.08f, 0.09f, 0.83f); + // style.Colors[ImGuiCol_TabHovered] = ImVec4(0.33f, 0.34f, 0.36f, 0.83f); + // style.Colors[ImGuiCol_TabActive] = ImVec4(0.23f, 0.23f, 0.24f, 1.00f); + // style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f); + // style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f); + // style.Colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); + // style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); + // style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + // style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + // style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); + // style.Colors[ImGuiCol_DragDropTarget] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f); + // style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + // style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); + // style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); + // style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); + // style.GrabRounding = style.FrameRounding = 2.3f; + } +} \ No newline at end of file diff --git a/Editor/Editor.h b/Editor/Editor.h new file mode 100644 index 00000000..72dbad96 --- /dev/null +++ b/Editor/Editor.h @@ -0,0 +1,98 @@ +/* +MIT License + +Copyright (c) 2021 - 2023 Aryan Baburajan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +namespace DT +{ + class Window; + class Renderer; + class Panel; + + class Editor + { + public: + Editor(Context &ctx); + ~Editor(); + + void Init(Context &ctx); + void NewFrame(); + void Tick(Context &ctx, const float &dt); + void EndFrame(); + + void Close(); + void SetTitle(const std::string &title); + glm::vec2 GetWindowPos(); + void SetWindowPos(const glm::vec2 &pos); + glm::vec2 GetWindowSize(); + void SetWindowSizeLimits(const glm::vec2 &minSize, const glm::vec2 &maxSize); + void SetWindowAspectRatio(const int &numerator, const int &denominator); + void SetWindowSize(const glm::vec2 &size); + glm::vec2 GetWindowContentScale(); + float GetWindowOpacity(); + void SetWindowOpacity(const float &opacity); + void IconifyWindow(); + void RestoreWindow(); + void MaximizeWindow(); + void ShowWindow(); + void HideWindow(); + void FocusWindow(); + void RequestWindowAttention(); + void SetVSync(const bool &vsync); + void SetDarkTheme(); + + template + Error AttachPanel(T *panel) + { + if (panels.find(std::type_index(typeid(T))) != panels.end()) + return Error("Panel " + std::string(typeid(T).name()) + " already attached.\n"); + panels[std::type_index(typeid(T))] = panel; + return Error(); + } + + template + Error AttachPanel(T *panel, Args... args) + { + Error error = AttachPanel(panel); + if (error.HasError()) + return error; + return AttachPanel(args...); + } + + template + ErrorOr GetPanel() + { + if (panels.find(std::type_index(typeid(T))) == panels.end()) + return ErrorOr("Panel " + std::string(typeid(T).name()) + " not attached.\n"); + return (T *)panels[std::type_index(typeid(T))]; + } + + private: + Window *window; + Renderer *renderer; + + ImGuiID dockspaceId; + std::unordered_map panels; + }; +} \ No newline at end of file diff --git a/Editor/Panels/GameView.h b/Editor/Panels/GameView.h new file mode 100644 index 00000000..1190b9d5 --- /dev/null +++ b/Editor/Panels/GameView.h @@ -0,0 +1,42 @@ +/* +MIT License + +Copyright (c) 2021 - 2023 Aryan Baburajan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include +#include + +namespace DT +{ + class GameView : public Panel + { + public: + void Tick(Context &ctx, const float &dt) override + { + ImGui::Begin("Game View", &isOpen); + + ImGui::End(); + } + }; +} \ No newline at end of file diff --git a/Editor/Panels/Panel.h b/Editor/Panels/Panel.h new file mode 100644 index 00000000..81b63b14 --- /dev/null +++ b/Editor/Panels/Panel.h @@ -0,0 +1,39 @@ +/* +MIT License + +Copyright (c) 2021 - 2023 Aryan Baburajan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include + +namespace DT +{ + class Panel + { + public: + bool isOpen = true; + + virtual void Init(Context &ctx) {} + virtual void Tick(Context &ctx, const float &dt) {} + }; +} \ No newline at end of file diff --git a/Editor/Panels/WorldOutliner.h b/Editor/Panels/WorldOutliner.h new file mode 100644 index 00000000..8cc5798e --- /dev/null +++ b/Editor/Panels/WorldOutliner.h @@ -0,0 +1,62 @@ +/* +MIT License + +Copyright (c) 2021 - 2023 Aryan Baburajan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include + +namespace DT +{ + class WorldOutliner : public Panel + { + public: + void Init(Context &ctx) override + { + sceneManager = ctx.GetService().Fatal(); + } + + void Tick(Context &ctx, const float &dt) override + { + ImGui::Begin("World Outliner", &isOpen); + + for (Entity entity : sceneManager->activeScene.GetEntities()) + { + std::string label; + if (sceneManager->activeScene.Has(entity)) + label = sceneManager->activeScene.Get(entity).Fatal("GameView::Tick()")->name; + else + label = "Entity " + std::to_string(entity); + + if (ImGui::Selectable((label + "##" + std::to_string(entity)).c_str(), selectedEntity == entity)) + selectedEntity = entity; + } + + ImGui::End(); + } + + private: + SceneManager *sceneManager; + Entity selectedEntity; + }; +} \ No newline at end of file diff --git a/Engine/CMakeLists.txt b/Engine/CMakeLists.txt index 743e83f6..edb46bbd 100644 --- a/Engine/CMakeLists.txt +++ b/Engine/CMakeLists.txt @@ -1,27 +1,28 @@ -# Ducktape | An open source C++ 2D & 3D game Engine that focuses on being fast, and powerful. -# Copyright (C) 2023 Aryan Baburajan -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# In case of any further questions feel free to contact me at -# the following email address: -# aryanbaburajan2007@gmail.com +# MIT License + +# Copyright (c) 2021 - 2023 Aryan Baburajan + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. cmake_minimum_required (VERSION 3.20) file (GLOB_RECURSE dt_source_list "${PROJECT_SOURCE_DIR}/Engine/**/*.cpp" "${PROJECT_SOURCE_DIR}/Engine/*.cpp") add_library (Ducktape SHARED ${dt_source_list}) set_target_properties (Ducktape PROPERTIES PREFIX "") -add_definitions(-DDLL_EXPORT) target_precompile_headers(Ducktape PUBLIC "${PROJECT_SOURCE_DIR}/Engine/dtpch.h") \ No newline at end of file diff --git a/Engine/Components/Camera.cpp b/Engine/Components/Camera.cpp index cae0f684..049d5453 100644 --- a/Engine/Components/Camera.cpp +++ b/Engine/Components/Camera.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Components/Camera.h b/Engine/Components/Camera.h index 83676da8..1e163ad1 100644 --- a/Engine/Components/Camera.h +++ b/Engine/Components/Camera.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,19 +30,17 @@ SOFTWARE. #include #include -#define DEG2RAD 11/630 - namespace DT { class Camera : public Component - { - std::shared_ptr transform; - Window *window; - + { public: float fieldOfView = 75.f, nearPlane = 0.1f, farPlane = 100.f; glm::mat4 projection, view; bool isOrthographic = false; + + void Init(Context &ctx) override; + void Tick(Context &ctx, const float &dt) override; inline glm::vec3 GetPosition() { @@ -54,7 +52,8 @@ namespace DT return transform->rotation; } - void Init(Context &ctx) override; - void Tick(Context &ctx, const float &dt) override; + private: + std::shared_ptr transform; + Window *window; }; } \ No newline at end of file diff --git a/Engine/Components/SpriteRenderer.cpp b/Engine/Components/SpriteRenderer.cpp index f76f0d0d..12306088 100644 --- a/Engine/Components/SpriteRenderer.cpp +++ b/Engine/Components/SpriteRenderer.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Components/SpriteRenderer.h b/Engine/Components/SpriteRenderer.h index 0c1dd5fa..b7821963 100644 --- a/Engine/Components/SpriteRenderer.h +++ b/Engine/Components/SpriteRenderer.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -36,15 +36,16 @@ namespace DT class SpriteRenderer : public Component { public: - Mesh &mesh = Mesh::Quad(); - Material material; - std::shared_ptr transform; - - Renderer *renderer; - SpriteRenderer(Context *ctx, const std::filesystem::path &texturePath); void Init(Context &ctx); void Tick(Context &ctx, const float &dt) override; + + private: + Mesh &mesh = Mesh::Quad(); + std::shared_ptr transform; + Material material; + + Renderer *renderer; }; } \ No newline at end of file diff --git a/Engine/Components/Tag.h b/Engine/Components/Tag.h index 02b142e0..5e7a3859 100644 --- a/Engine/Components/Tag.h +++ b/Engine/Components/Tag.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Components/Transform.cpp b/Engine/Components/Transform.cpp index 2af45e9a..c079fb22 100644 --- a/Engine/Components/Transform.cpp +++ b/Engine/Components/Transform.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Components/Transform.h b/Engine/Components/Transform.h index 76561f69..95dc42ce 100644 --- a/Engine/Components/Transform.h +++ b/Engine/Components/Transform.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Core/Context.h b/Engine/Core/Context.h index 54c026e5..a85bdf91 100644 --- a/Engine/Core/Context.h +++ b/Engine/Core/Context.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Core/Error.cpp b/Engine/Core/Error.cpp new file mode 100644 index 00000000..48136042 --- /dev/null +++ b/Engine/Core/Error.cpp @@ -0,0 +1,72 @@ +/* +MIT License + +Copyright (c) 2021 - 2023 Aryan Baburajan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include + +namespace DT +{ + Error::Error(const std::string &_error) : error(_error) { handled = false; } + + Error::~Error() + { + if (handled) return; + + std::cout << "[FATAL] Unhandled error: " + error.value() << ".\n"; + abort(); + } + + bool Error::HasError() + { + return error.has_value(); + } + + std::string &Error::GetError() + { + handled = true; + assert(HasError()); + return error.value(); + } + + void Error::Log(const std::string &errorContext) + { + handled = true; + if (!HasError()) return; + std::cout << "[LOG] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); + } + + void Error::Err(const std::string &errorContext) + { + handled = true; + if (!HasError()) return; + std::cout << "[ERR] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); + } + + void Error::Fatal(const std::string &errorContext) + { + handled = true; + if (!HasError()) return; + std::cout << "[FATAL] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); + abort(); + } +} \ No newline at end of file diff --git a/Engine/Core/Error.h b/Engine/Core/Error.h index fcf7e12b..e79e2db4 100644 --- a/Engine/Core/Error.h +++ b/Engine/Core/Error.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -24,75 +24,31 @@ SOFTWARE. #pragma once +#include + namespace DT { class [[nodiscard]] Error { - protected: - std::optional error; - bool handled = true; - public: Error() = default; - Error(const std::string &_error) : error(_error) { handled = false; } - - ~Error() - { - if (handled) return; + Error(const std::string &_error); + ~Error(); - std::cout << "[FATAL] Unhandled error: " + error.value() << ".\n"; - abort(); - } - - inline bool HasError() - { - return error.has_value(); - } - - inline std::string &GetError() - { - handled = true; - assert(HasError()); - return error.value(); - } - - inline void Log(const std::string &errorContext = "") - { - handled = true; - if (!HasError()) return; - std::cout << "[LOG] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); - } - - inline void Err(const std::string &errorContext = "") - { - handled = true; - if (!HasError()) return; - std::cout << "[ERR] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); - } + bool HasError(); + std::string &GetError(); + void Log(const std::string &errorContext = ""); + void Err(const std::string &errorContext = ""); + void Fatal(const std::string &errorContext = ""); - inline void Fatal(const std::string &errorContext = "") - { - handled = true; - if (!HasError()) return; - std::cout << "[FATAL] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); - abort(); - } + private: + std::optional error; + bool handled = true; }; template class [[nodiscard]] ErrorOr { - protected: - std::optional error; - std::optional value; - bool handled = true; - - inline T Value() - { - handled = true; - return value.value(); - } - public: ErrorOr(T _value) : value(_value) {} ErrorOr(const std::string &_error) : error(_error) { handled = false; } @@ -105,39 +61,50 @@ namespace DT abort(); } - inline bool HasError() + bool HasError() { handled = true; return error.has_value(); } - inline std::string &GetError() + std::string &GetError() { handled = true; assert(HasError()); return error.value(); } - inline T Log(const std::string &errorContext = "") + T Log(const std::string &errorContext = "") { handled = true; if (!HasError()) return Value(); std::cout << "[LOG] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); } - inline T Err(const std::string &errorContext = "") + T Err(const std::string &errorContext = "") { handled = true; if (!HasError()) return Value(); std::cout << "[ERR] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); } - inline T Fatal(const std::string &errorContext = "") + T Fatal(const std::string &errorContext = "") { handled = true; if (!HasError()) return Value(); std::cout << "[FATAL] " << (errorContext != "" ? errorContext + "\n " : "") << error.value(); abort(); } + + private: + std::optional error; + std::optional value; + bool handled = true; + + T Value() + { + handled = true; + return value.value(); + } }; } \ No newline at end of file diff --git a/Engine/Core/InputManager.cpp b/Engine/Core/InputManager.cpp index fa8c1427..64f9d3fb 100644 --- a/Engine/Core/InputManager.cpp +++ b/Engine/Core/InputManager.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,11 +30,11 @@ namespace DT { window = ctx.GetService().Fatal("InputManager::InputManager()"); - glfwSetKeyCallback(window->window, KeyCallback); - glfwSetMouseButtonCallback(window->window, MouseButtonCallback); + glfwSetKeyCallback(window->GetRawWindowPointer(), KeyCallback); + glfwSetMouseButtonCallback(window->GetRawWindowPointer(), MouseButtonCallback); double curPosX, curPosY; - glfwGetCursorPos(window->window, &curPosX, &curPosY); + glfwGetCursorPos(window->GetRawWindowPointer(), &curPosX, &curPosY); mousePosition = glm::vec2(curPosX, curPosY); std::cout << "[LOG] InputManager Constructed\n"; @@ -43,7 +43,7 @@ namespace DT void InputManager::Process() { double curPosX, curPosY; - glfwGetCursorPos(window->window, &curPosX, &curPosY); + glfwGetCursorPos(window->GetRawWindowPointer(), &curPosX, &curPosY); mouseDelta = glm::vec2(curPosX - mousePosition.x, curPosY - mousePosition.y); mousePosition = glm::vec2(curPosX, curPosY); diff --git a/Engine/Core/InputManager.h b/Engine/Core/InputManager.h index 14d0647d..ff9eb1bb 100644 --- a/Engine/Core/InputManager.h +++ b/Engine/Core/InputManager.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -223,30 +223,15 @@ SOFTWARE. #define GAMEPAD_AXIS_RIGHT_TRIGGER 5 #define GAMEPAD_AXIS_LAST GAMEPAD_AXIS_RIGHT_TRIGGER -#include +#include +#include #include namespace DT { class InputManager { - struct FunctionComparator - { - using T = std::function; - bool operator()(const T &lhs, const T &rhs) const - { - return &lhs < &rhs; - } - }; - - std::unordered_map, FunctionComparator>> keyEvents; - std::unordered_map, FunctionComparator>> mouseEvents; - - Window *window; - - glm::vec2 mousePosition, mouseDelta; - public: InputManager(Context &ctx, const json &data); @@ -264,12 +249,12 @@ namespace DT inline bool IsKeyHeld(int key) { - return glfwGetKey(window->window, key) == GLFW_PRESS; + return glfwGetKey(window->GetRawWindowPointer(), key) == GLFW_PRESS; } inline bool IsMouseButtonHeld(int button) { - return glfwGetMouseButton(window->window, button) == GLFW_PRESS; + return glfwGetMouseButton(window->GetRawWindowPointer(), button) == GLFW_PRESS; } inline void OnKeyEvent(int key, std::function event) @@ -284,5 +269,22 @@ namespace DT static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); + + private: + struct FunctionComparator + { + using T = std::function; + bool operator()(const T &lhs, const T &rhs) const + { + return &lhs < &rhs; + } + }; + + std::unordered_map, FunctionComparator>> keyEvents; + std::unordered_map, FunctionComparator>> mouseEvents; + + Window *window; + + glm::vec2 mousePosition, mouseDelta; }; } \ No newline at end of file diff --git a/Engine/Core/Window.cpp b/Engine/Core/Window.cpp index 66309276..14f8e6c0 100644 --- a/Engine/Core/Window.cpp +++ b/Engine/Core/Window.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -98,6 +98,103 @@ namespace DT glfwTerminate(); } + void Window::Close() + { + glfwSetWindowShouldClose(window, true); + } + + void Window::SetTitle(const std::string &title) + { + glfwSetWindowTitle(window, title.c_str()); + } + + glm::vec2 Window::GetWindowPos() + { + int x, y; + glfwGetWindowPos(window, &x, &y); + return glm::vec2(x, y); + } + + void Window::SetWindowPos(const glm::vec2 &pos) + { + glfwSetWindowPos(window, pos.x, pos.y); + } + + glm::vec2 Window::GetWindowSize() + { + int width, height; + glfwGetWindowSize(window, &width, &height); + return glm::vec2(width, height); + } + + void Window::SetWindowSize(const glm::vec2 &size) + { + glfwSetWindowSize(window, size.x, size.y); + glViewport(0, 0, size.x, size.y); + } + + glm::vec2 Window::GetWindowContentScale() + { + float x, y; + glfwGetWindowContentScale(window, &x, &y); + return glm::vec2(x, y); + } + + float Window::GetWindowOpacity() + { + return glfwGetWindowOpacity(window); + } + + void Window::SetWindowOpacity(const float &opacity) + { + glfwSetWindowOpacity(window, opacity); + } + + void Window::IconifyWindow() + { + glfwIconifyWindow(window); + } + + void Window::RestoreWindow() + { + glfwRestoreWindow(window); + } + + void Window::MaximizeWindow() + { + glfwMaximizeWindow(window); + } + + void Window::ShowWindow() + { + glfwShowWindow(window); + } + + void Window::HideWindow() + { + glfwHideWindow(window); + } + + void Window::FocusWindow() + { + glfwFocusWindow(window); + } + + void Window::RequestWindowAttention() + { + glfwRequestWindowAttention(window); + } + + void Window::SetVSync(const bool &vsync) + { + glfwSwapInterval(vsync); + } + + bool Window::IsFocused() + { + return glfwGetWindowAttrib(window, GLFW_FOCUSED); + } + void Window::ErrorCallback(int code, const char *description) { std::cout << "[ERR] [OPENGL] [" << code << "] " << description << std::endl; diff --git a/Engine/Core/Window.h b/Engine/Core/Window.h index b0230e65..1f389230 100644 --- a/Engine/Core/Window.h +++ b/Engine/Core/Window.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -34,11 +34,14 @@ namespace DT class Window { public: - GLFWwindow *window = nullptr; - Window(Context &ctx, const json &windowData, Error *err); ~Window(); + inline GLFWwindow *GetRawWindowPointer() + { + return window; + } + inline bool IsOpen() { return !glfwWindowShouldClose(window); @@ -56,104 +59,29 @@ namespace DT glfwSwapBuffers(window); } - inline void Close() - { - glfwSetWindowShouldClose(window, true); - } - - inline void SetTitle(const std::string &title) - { - glfwSetWindowTitle(window, title.c_str()); - } - - inline glm::vec2 GetWindowPos() - { - int x, y; - glfwGetWindowPos(window, &x, &y); - return glm::vec2(x, y); - } - - inline void SetWindowPos(const glm::vec2 &pos) - { - glfwSetWindowPos(window, pos.x, pos.y); - } - - inline glm::vec2 GetWindowSize() - { - int width, height; - glfwGetWindowSize(window, &width, &height); - return glm::vec2(width, height); - } - - inline void SetWindowSize(const glm::vec2 &size) - { - glfwSetWindowSize(window, size.x, size.y); - glViewport(0, 0, size.x, size.y); - } - - inline glm::vec2 GetWindowContentScale() - { - float x, y; - glfwGetWindowContentScale(window, &x, &y); - return glm::vec2(x, y); - } - - inline float GetWindowOpacity() - { - return glfwGetWindowOpacity(window); - } - - inline void SetWindowOpacity(const float &opacity) - { - glfwSetWindowOpacity(window, opacity); - } - - inline void IconifyWindow() - { - glfwIconifyWindow(window); - } - - inline void RestoreWindow() - { - glfwRestoreWindow(window); - } - - inline void MaximizeWindow() - { - glfwMaximizeWindow(window); - } - - inline void ShowWindow() - { - glfwShowWindow(window); - } - - inline void HideWindow() - { - glfwHideWindow(window); - } - - inline void FocusWindow() - { - glfwFocusWindow(window); - } - - inline void RequestWindowAttention() - { - glfwRequestWindowAttention(window); - } - - inline void SetVSync(const bool &vsync) - { - glfwSwapInterval(vsync); - } - - inline bool IsFocused() - { - return glfwGetWindowAttrib(window, GLFW_FOCUSED); - } - + void Close(); + void SetTitle(const std::string &title); + glm::vec2 GetWindowPos(); + void SetWindowPos(const glm::vec2 &pos); + glm::vec2 GetWindowSize(); + void SetWindowSize(const glm::vec2 &size); + glm::vec2 GetWindowContentScale(); + float GetWindowOpacity(); + void SetWindowOpacity(const float &opacity); + void IconifyWindow(); + void RestoreWindow(); + void MaximizeWindow(); + void ShowWindow(); + void HideWindow(); + void FocusWindow(); + void RequestWindowAttention(); + void SetVSync(const bool &vsync); + bool IsFocused(); + static void ErrorCallback(int code, const char *description); static void APIENTRY GlDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char *message, const void *userParam); + + private: + GLFWwindow *window = nullptr; }; } \ No newline at end of file diff --git a/Engine/ECS/Component.h b/Engine/ECS/Component.h index 73139dce..406fff18 100644 --- a/Engine/ECS/Component.h +++ b/Engine/ECS/Component.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/ECS/Entity.h b/Engine/ECS/Entity.h index 784c0e9a..f7d0f979 100644 --- a/Engine/ECS/Entity.h +++ b/Engine/ECS/Entity.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/ECS/Scene.cpp b/Engine/ECS/Scene.cpp new file mode 100644 index 00000000..3f539c2a --- /dev/null +++ b/Engine/ECS/Scene.cpp @@ -0,0 +1,42 @@ +/* +MIT License + +Copyright (c) 2021 - 2023 Aryan Baburajan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include + +namespace DT +{ + std::unordered_set Scene::GetEntities() + { + std::unordered_set entities; + for (std::pair>> &entity : components) { + entities.insert(entity.first); + } + return entities; + } + + std::unordered_map> Scene::View(Entity entity) + { + return components.at(entity); + } +} \ No newline at end of file diff --git a/Engine/ECS/Scene.h b/Engine/ECS/Scene.h index 4a22706f..77385dc7 100644 --- a/Engine/ECS/Scene.h +++ b/Engine/ECS/Scene.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -32,11 +32,10 @@ namespace DT { class Scene { - Entity entityCounter = 0; - std::unordered_set tombStones; - std::unordered_map>> components; - public: + std::unordered_set GetEntities(); + std::unordered_map> View(Entity entity); + inline bool IsValid(Entity entity) { return tombStones.find(entity) == tombStones.end(); @@ -56,7 +55,7 @@ namespace DT } template - inline bool Has(Entity entity) + bool Has(Entity entity) { if (!IsValid(entity)) return false; @@ -72,7 +71,7 @@ namespace DT } template - inline ErrorOr> Require(Entity entity, Args &&...args) + ErrorOr> Require(Entity entity, Args &&...args) { if (Has(entity)) return Get(entity); @@ -126,18 +125,9 @@ namespace DT return Error(); } - inline std::unordered_set GetEntities() - { - std::unordered_set entities; - for (std::pair>> &entity : components) { - entities.insert(entity.first); - } - return entities; - } - - inline std::unordered_map> View(Entity entity) - { - return components.at(entity); - } + private: + Entity entityCounter = 0; + std::unordered_set tombStones; + std::unordered_map>> components; }; } diff --git a/Engine/ECS/SceneManager.cpp b/Engine/ECS/SceneManager.cpp index e549ab9e..40551a1a 100644 --- a/Engine/ECS/SceneManager.cpp +++ b/Engine/ECS/SceneManager.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -28,13 +28,7 @@ namespace DT { SceneManager::SceneManager(const json &sceneManagerData) { - // AID entryScene = sceneManagerData.value("entryScene", 0); - // if (!entryScene) - // { - LoadDemoScene(); - // return; - // } - // LoadScene(AssetManager:GetPath(UID)); + LoadDemoScene(); std::cout << "[LOG] SceneManager Constructed.\n"; } @@ -48,4 +42,18 @@ namespace DT { } + + void SceneManager::Init(Context &ctx) + { + for (Entity entity : activeScene.GetEntities()) + for (std::pair> &component : activeScene.View(entity)) + component.second->Init(ctx); + } + + void SceneManager::Tick(Context &ctx, const float &deltaTime) + { + for (Entity entity : activeScene.GetEntities()) + for (std::pair> &component : activeScene.View(entity)) + component.second->Tick(ctx, deltaTime); + } } \ No newline at end of file diff --git a/Engine/ECS/SceneManager.h b/Engine/ECS/SceneManager.h index d32cf755..07cd9cff 100644 --- a/Engine/ECS/SceneManager.h +++ b/Engine/ECS/SceneManager.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -38,26 +38,10 @@ namespace DT SceneManager(const json &sceneManagerData); - inline void Init(Context &ctx) - { - for (Entity entity : activeScene.GetEntities()) - for (std::pair> &component : activeScene.View(entity)) - component.second->Init(ctx); - } - - inline void Tick(Context &ctx, const float &deltaTime) - { - for (Entity entity : activeScene.GetEntities()) - for (std::pair> &component : activeScene.View(entity)) - { - if (component.second == nullptr) - std::cout << component.first.name() << std::endl; - assert(component.second != nullptr); - component.second->Tick(ctx, deltaTime); - } - } - void LoadDemoScene(); void LoadScene(); + + void Init(Context &ctx); + void Tick(Context &ctx, const float &deltaTime); }; } \ No newline at end of file diff --git a/Engine/Renderer/Material.h b/Engine/Renderer/Material.h index 8862636d..2d0f8a24 100644 --- a/Engine/Renderer/Material.h +++ b/Engine/Renderer/Material.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Renderer/Mesh.cpp b/Engine/Renderer/Mesh.cpp index 79f6288f..85797f72 100644 --- a/Engine/Renderer/Mesh.cpp +++ b/Engine/Renderer/Mesh.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Renderer/Mesh.h b/Engine/Renderer/Mesh.h index 71bd3067..0b6847d4 100644 --- a/Engine/Renderer/Mesh.h +++ b/Engine/Renderer/Mesh.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Renderer/Renderer.cpp b/Engine/Renderer/Renderer.cpp index 6542311b..a8fea63d 100644 --- a/Engine/Renderer/Renderer.cpp +++ b/Engine/Renderer/Renderer.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -61,17 +61,17 @@ namespace DT Renderer::Renderer(Context &ctx, const json &rendererData) : screenShader(Shader::Load(ctx.projectPath / "Engine" / "Screen.frag", ctx.projectPath / "Engine" / "Screen.vert").Fatal("Renderer::Renderer()")) { - renderFramebuffer = rendererData.value("renderFramebuffer", true); + renderFrameBuffer = rendererData.value("renderFrameBuffer", true); glEnable(GL_DEPTH_TEST); window = ctx.GetService().Fatal("Renderer::Renderer()"); - glfwSetFramebufferSizeCallback(window->window, FramebufferSizeCallback); + glfwSetFramebufferSizeCallback(window->GetRawWindowPointer(), FramebufferSizeCallback); // FBO glGenFramebuffers(1, &FBO); - glBindFramebuffer(GL_FRAMEBUFFER, FBO); + BindFrameBuffer(FBO); // Texture glGenTextures(1, &renderTexture); @@ -113,8 +113,6 @@ namespace DT glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void *)0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void *)(2 * sizeof(float))); - - glBindFramebuffer(GL_FRAMEBUFFER, 0); std::cout << "[LOG] Renderer Constructed\n"; } @@ -134,10 +132,7 @@ namespace DT void Renderer::BeginScene() { - if (!window->IsFocused()) - return; - - glBindFramebuffer(GL_FRAMEBUFFER, FBO); + BindFrameBuffer(FBO); glEnable(GL_DEPTH_TEST); glClearColor(0.15f, 0.15f, 0.15f, 1.0f); @@ -146,16 +141,13 @@ namespace DT void Renderer::EndScene() { - if (!window->IsFocused()) - return; - - glBindFramebuffer(GL_FRAMEBUFFER, 0); + BindFrameBuffer(0); glDisable(GL_DEPTH_TEST); glClearColor(1.f, 1.f, 1.f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - if (renderFramebuffer) + if (renderFrameBuffer) { screenShader.Use().Fatal("Renderer::Renderer()"); glBindVertexArray(quadVAO); diff --git a/Engine/Renderer/Renderer.h b/Engine/Renderer/Renderer.h index d1fce5b4..c9b57dd0 100644 --- a/Engine/Renderer/Renderer.h +++ b/Engine/Renderer/Renderer.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -39,17 +39,7 @@ namespace DT { class Renderer { - bool renderFramebuffer = true; - public: - unsigned int FBO, RBO, renderTexture, quadVAO, quadVBO; - std::shared_ptr camera; - std::array occupiedDirectionalLights = {false}; - std::array occupiedPointLights = {false}; - Window *window; - - Shader screenShader; - Renderer(Context &ctx, const json &rendererData); void Init(Context &ctx); @@ -63,6 +53,37 @@ namespace DT bool GetFreePointLightSpot(unsigned int *spot); void UnoccupyPointLightSpot(unsigned int spot); + inline unsigned int GetRenderFBO() + { + return FBO; + } + + inline void SetRenderFrameBuffer(bool flag) + { + renderFrameBuffer = flag; + } + + void BindFrameBuffer(unsigned int fbo) + { + if (bindedFBO == fbo) + return; + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + bindedFBO = fbo; + } + static void FramebufferSizeCallback(GLFWwindow *window, int width, int height); + + private: + unsigned int bindedFBO = 0; + + bool renderFrameBuffer = true; + unsigned int FBO, RBO, renderTexture, quadVAO, quadVBO; + + std::shared_ptr camera; + std::array occupiedDirectionalLights = {false}; + std::array occupiedPointLights = {false}; + Window *window; + + Shader screenShader; }; } \ No newline at end of file diff --git a/Engine/Renderer/Shader.cpp b/Engine/Renderer/Shader.cpp index ebeb8edc..52759eb5 100644 --- a/Engine/Renderer/Shader.cpp +++ b/Engine/Renderer/Shader.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Renderer/Shader.h b/Engine/Renderer/Shader.h index 55da18ff..91c9a8b3 100644 --- a/Engine/Renderer/Shader.h +++ b/Engine/Renderer/Shader.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -40,12 +40,6 @@ namespace DT Error Use(); void Delete(); - static ErrorOr Load(const std::filesystem::path &fragPath, const std::filesystem::path &vertPath); - static Shader Default(Context &ctx); - - static void CheckCompileErrors(unsigned int shader, const std::string &shaderCode, Error *error); - static void CheckLinkErrors(unsigned int program, Error *error); - static void ClearCache(Context &ctx); inline void SetBool(const std::string &name, bool value) { @@ -106,5 +100,12 @@ namespace DT { glUniformMatrix4fv(glGetUniformLocation(id, name.c_str()), 1, GL_FALSE, glm::value_ptr(mat)); } + + static ErrorOr Load(const std::filesystem::path &fragPath, const std::filesystem::path &vertPath); + static Shader Default(Context &ctx); + + static void CheckCompileErrors(unsigned int shader, const std::string &shaderCode, Error *error); + static void CheckLinkErrors(unsigned int program, Error *error); + static void ClearCache(Context &ctx); }; } \ No newline at end of file diff --git a/Engine/Renderer/Texture.cpp b/Engine/Renderer/Texture.cpp index 2b02c7a7..25638edf 100644 --- a/Engine/Renderer/Texture.cpp +++ b/Engine/Renderer/Texture.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,6 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include + #include namespace DT diff --git a/Engine/Renderer/Texture.h b/Engine/Renderer/Texture.h index 676b46e0..72068b37 100644 --- a/Engine/Renderer/Texture.h +++ b/Engine/Renderer/Texture.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Renderer/Vertex.h b/Engine/Renderer/Vertex.h index 8b968bc2..8fb15300 100644 --- a/Engine/Renderer/Vertex.h +++ b/Engine/Renderer/Vertex.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/Utils/math.h b/Engine/Utils/math.h index b3d6e042..ef6c1cab 100644 --- a/Engine/Utils/math.h +++ b/Engine/Utils/math.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/dtpch.cpp b/Engine/dtpch.cpp index 8d055325..2307efc0 100644 --- a/Engine/dtpch.cpp +++ b/Engine/dtpch.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Engine/dtpch.h b/Engine/dtpch.h index 8e6d4dec..590482ff 100644 --- a/Engine/dtpch.h +++ b/Engine/dtpch.h @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -44,9 +44,7 @@ SOFTWARE. #include #include #include -#include #include -#include #define GLM_FORCE_RADIANS #include @@ -55,6 +53,10 @@ SOFTWARE. #include #include +#include +#include +#include + #define JSON_DIAGNOSTICS 1 #include using json = nlohmann::json; @@ -62,7 +64,4 @@ using json = nlohmann::json; #define IN_SERIALIZE NLOHMANN_DEFINE_TYPE_INTRUSIVE #include -#include - -#include -#include \ No newline at end of file +#include \ No newline at end of file diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index e13346a7..ff43662c 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -1,26 +1,28 @@ -# Ducktape | An open source C++ 2D & 3D game Engine that focuses on being fast, and powerful. -# Copyright (C) 2023 Aryan Baburajan -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# In case of any further questions feel free to contact me at -# the following email address: -# aryanbaburajan2007@gmail.com +# MIT License + +# Copyright (c) 2021 - 2023 Aryan Baburajan + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. cmake_minimum_required(VERSION 3.20) # Ducktape file(GLOB_RECURSE dtr_source_list "${PROJECT_SOURCE_DIR}/Runtime/**/*.cpp" "${PROJECT_SOURCE_DIR}/Runtime/*.cpp") add_executable(DucktapeRuntime ${dtr_source_list}) -target_link_libraries(DucktapeRuntime PRIVATE Ducktape) \ No newline at end of file +target_link_libraries(DucktapeRuntime PRIVATE Ducktape DucktapeEditor) \ No newline at end of file diff --git a/Runtime/Main.cpp b/Runtime/Main.cpp index 48b0dc41..cbd47b6d 100644 --- a/Runtime/Main.cpp +++ b/Runtime/Main.cpp @@ -1,7 +1,7 @@ /* MIT License -Copyright (c) 2023 Aryan Baburajan +Copyright (c) 2021 - 2023 Aryan Baburajan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,7 @@ SOFTWARE. */ #include - +#include #include #include #include @@ -33,8 +33,8 @@ SOFTWARE. #include #include -#define GLM_ENABLE_EXPERIMENTAL -#include +#include +#include using namespace DT; @@ -55,7 +55,7 @@ class FreeLookCamera : public Component window = ctx.GetService().Fatal("FreeLookCamera::Init()"); input = ctx.GetService().Fatal("FreeLookCamera::Init()"); - glfwSetInputMode(window->window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + glfwSetInputMode(window->GetRawWindowPointer(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); } void Tick(Context &ctx, const float &dt) override @@ -140,6 +140,9 @@ int main(int argc, char* argv[]) // Renderer Renderer renderer(context, projectData.value("renderer", json::object())); context.AttachService(&renderer).Fatal("main()"); +#ifndef DT_EXPORT + renderer.SetRenderFrameBuffer(true); +#endif // Renderer InputManager input(context, projectData.value("input", json::object())); @@ -157,24 +160,42 @@ int main(int argc, char* argv[]) Entity camera = sceneManager.activeScene.CreateEntity(); sceneManager.activeScene.Require(camera, "Camera").Fatal("main()"); - sceneManager.activeScene.Require(camera).Fatal("main()")->isOrthographic = true; - sceneManager.activeScene.Require(camera).Fatal("main()"); + sceneManager.activeScene.Require(camera).Fatal("main()"); + // sceneManager.activeScene.Require(camera).Fatal("main()"); sceneManager.Init(context); renderer.Init(context); + // Editor + Editor editor(context); + WorldOutliner worldOutliner; + editor.AttachPanel(&worldOutliner).Fatal("main()"); + + editor.Init(context); + // Game Loop float lastTime = 0.0f; while (window.IsOpen()) { + window.PollEvents(); + if (!window.IsFocused()) + continue; + float deltaTime = glfwGetTime() - lastTime; lastTime = glfwGetTime(); - window.PollEvents(); + if (!window.IsOpen()) + break; + if (!window.IsFocused()) + continue; + input.Process(); + editor.NewFrame(); + editor.Tick(context, deltaTime); renderer.BeginScene(); sceneManager.Tick(context, deltaTime); renderer.EndScene(); + editor.EndFrame(); window.SwapBuffers(); }