From 5fa8dda890f162f9b2837f5ec0f2cde2cac638df Mon Sep 17 00:00:00 2001 From: Huseyn Ismayilov Date: Fri, 22 Nov 2024 04:56:31 +0400 Subject: [PATCH 1/4] build: Add shell file support --- Makefile | 24 ------------------------ scripts/BuildProject.sh | 34 ++++++++++++++++++++++++++++++++++ scripts/Makefile | 24 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 24 deletions(-) delete mode 100644 Makefile create mode 100755 scripts/BuildProject.sh create mode 100644 scripts/Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index fd57751..0000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -BUILD_DIR = build -EDITOR_DIR = editor -NAME = ferx - -RM += -r - -all: debug run - -release: - cmake -S . -B $(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Release - cmake --build $(BUILD_DIR) -j8 - -debug: - cmake -S . -B $(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Debug - cmake --build $(BUILD_DIR) -j8 - -run: - cd $(BUILD_DIR)/${EDITOR_DIR} && ./${NAME} - -clean: - cmake --build $(BUILD_DIR) --target clean - -clean-all: - $(RM) $(BUILD_DIR) diff --git a/scripts/BuildProject.sh b/scripts/BuildProject.sh new file mode 100755 index 0000000..6055f71 --- /dev/null +++ b/scripts/BuildProject.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +BUILD_DIR="build" +EDITOR_DIR="editor" +NAME="ferx" + +case $1 in + release) + cmake -S .. -B ../"$BUILD_DIR" -G Ninja -DCMAKE_BUILD_TYPE=Release + cmake --build ../"$BUILD_DIR" -j8 + ;; + debug) + cmake -S .. -B ../"$BUILD_DIR" -G Ninja -DCMAKE_BUILD_TYPE=Debug + cmake --build ../"$BUILD_DIR" -j8 + ;; + run) + cd "../$BUILD_DIR/$EDITOR_DIR" && ./"$NAME" + ;; + clean) + cmake --build ../"$BUILD_DIR" --target clean + ;; + clean-all) + rm -r ../"$BUILD_DIR" + ;; + all) + bash $0 enter_dir + bash $0 debug + bash $0 run + ;; + *) + echo "Usage: $0 {release|debug|run|clean|clean-all|all}" + exit 1 + ;; +esac diff --git a/scripts/Makefile b/scripts/Makefile new file mode 100644 index 0000000..5bcf81e --- /dev/null +++ b/scripts/Makefile @@ -0,0 +1,24 @@ +BUILD_DIR = build +EDITOR_DIR = editor +NAME = ferx + +RM += -r + +all: debug run + +release: + cmake -S .. -B ../$(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Release + cmake --build ../$(BUILD_DIR) -j8 + +debug: + cmake -S .. -B ../$(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Debug + cmake --build ../$(BUILD_DIR) -j8 + +run: + cd ../$(BUILD_DIR)/${EDITOR_DIR} && ./${NAME} + +clean: + cmake --build ../$(BUILD_DIR) --target clean + +clean-all: + $(RM) ../$(BUILD_DIR) From bf88324170a75050d1c6714de55a02207b672953 Mon Sep 17 00:00:00 2001 From: Huseyn Ismayilov Date: Fri, 22 Nov 2024 05:03:10 +0400 Subject: [PATCH 2/4] feat: Add dynamic entity list --- editor/src/GUI.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/editor/src/GUI.cpp b/editor/src/GUI.cpp index 4094ea8..20e5699 100644 --- a/editor/src/GUI.cpp +++ b/editor/src/GUI.cpp @@ -3,6 +3,8 @@ #include #include "GUI.h" +#include + #include "FrameBuffer.h" #include "Window.h" @@ -146,7 +148,10 @@ void GUI::ShowEntities() { ImGui::Begin(ICON_FA_CUBE" Entities"); - ImGui::CollapsingHeader("Cube"); + for(const auto& cube : Renderer::GetData().m_Scene->GetCubes()) + { + ImGui::CollapsingHeader(cube->name.c_str()); + } ImGui::End(); } From 580ecd8dce83b80f2b12edfadecac2196f476a91 Mon Sep 17 00:00:00 2001 From: Huseyn Ismayilov Date: Fri, 22 Nov 2024 05:08:57 +0400 Subject: [PATCH 3/4] refactor: Change resources path --- engine/CMakeLists.txt | 2 +- {editor => engine}/resources/fonts/Ruda-Bold.ttf | Bin .../resources/fonts/fa-regular-400.ttf | Bin {editor => engine}/resources/fonts/fa-solid-900.ttf | Bin {editor => engine}/resources/imgui.ini | 0 {editor => engine}/resources/shaders/fragment.glsl | 0 {editor => engine}/resources/shaders/vertex.glsl | 0 7 files changed, 1 insertion(+), 1 deletion(-) rename {editor => engine}/resources/fonts/Ruda-Bold.ttf (100%) rename {editor => engine}/resources/fonts/fa-regular-400.ttf (100%) rename {editor => engine}/resources/fonts/fa-solid-900.ttf (100%) rename {editor => engine}/resources/imgui.ini (100%) rename {editor => engine}/resources/shaders/fragment.glsl (100%) rename {editor => engine}/resources/shaders/vertex.glsl (100%) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 389d57a..7ac7334 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -28,7 +28,7 @@ add_library(${PROJECT_NAME}) if(CMAKE_BUILD_TYPE STREQUAL "Release") target_compile_definitions(${PROJECT_NAME} PUBLIC RESOURCES_PATH="./resources/") else() - target_compile_definitions(${PROJECT_NAME} PUBLIC RESOURCES_PATH="${CMAKE_SOURCE_DIR}/editor/resources/") + target_compile_definitions(${PROJECT_NAME} PUBLIC RESOURCES_PATH="${CMAKE_SOURCE_DIR}/engine/resources/") endif() # Link sources, include directories, and third party libraries diff --git a/editor/resources/fonts/Ruda-Bold.ttf b/engine/resources/fonts/Ruda-Bold.ttf similarity index 100% rename from editor/resources/fonts/Ruda-Bold.ttf rename to engine/resources/fonts/Ruda-Bold.ttf diff --git a/editor/resources/fonts/fa-regular-400.ttf b/engine/resources/fonts/fa-regular-400.ttf similarity index 100% rename from editor/resources/fonts/fa-regular-400.ttf rename to engine/resources/fonts/fa-regular-400.ttf diff --git a/editor/resources/fonts/fa-solid-900.ttf b/engine/resources/fonts/fa-solid-900.ttf similarity index 100% rename from editor/resources/fonts/fa-solid-900.ttf rename to engine/resources/fonts/fa-solid-900.ttf diff --git a/editor/resources/imgui.ini b/engine/resources/imgui.ini similarity index 100% rename from editor/resources/imgui.ini rename to engine/resources/imgui.ini diff --git a/editor/resources/shaders/fragment.glsl b/engine/resources/shaders/fragment.glsl similarity index 100% rename from editor/resources/shaders/fragment.glsl rename to engine/resources/shaders/fragment.glsl diff --git a/editor/resources/shaders/vertex.glsl b/engine/resources/shaders/vertex.glsl similarity index 100% rename from editor/resources/shaders/vertex.glsl rename to engine/resources/shaders/vertex.glsl From 32774618584b817d04c5ce704984aefd94cf24e3 Mon Sep 17 00:00:00 2001 From: Huseyn Ismayilov Date: Fri, 22 Nov 2024 17:40:41 +0400 Subject: [PATCH 4/4] fix: Fix resources conflict and update scripts --- editor/CMakeLists.txt | 10 +++++-- editor/resources/imgui.ini | 49 +++++++++++++++++++++++++++++++++++ editor/src/GUI.cpp | 6 +++-- engine/CMakeLists.txt | 7 +++-- engine/rendering/Renderer.cpp | 2 +- engine/resources/imgui.ini | 49 ----------------------------------- scripts/BuildProject.sh | 43 ++++++++++++++++++------------ scripts/Makefile | 38 +++++++++++++++++---------- 8 files changed, 117 insertions(+), 87 deletions(-) create mode 100644 editor/resources/imgui.ini delete mode 100644 engine/resources/imgui.ini diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 6a079a0..5f10860 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -8,11 +8,17 @@ set(EDITOR_INCLUDE_DIR include) set(EDITOR_RESOURCES_DIR resources) file(GLOB_RECURSE EDITOR_SOURCES ${EDITOR_SOURCE_DIR}/*.cpp) -file(COPY ${EDITOR_RESOURCES_DIR}/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) add_executable(${NAME}) +# Add resources folder +if(CMAKE_BUILD_TYPE STREQUAL "Release") + file(COPY ${EDITOR_RESOURCES_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + target_compile_definitions(${NAME} PUBLIC EDITOR_RESOURCES_PATH="resources/") +else() + target_compile_definitions(${NAME} PUBLIC EDITOR_RESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/") +endif() + target_sources(${NAME} PRIVATE ${EDITOR_SOURCES}) target_include_directories(${NAME} PRIVATE ${EDITOR_INCLUDE_DIR}) - target_link_libraries(${NAME} engine) diff --git a/editor/resources/imgui.ini b/editor/resources/imgui.ini new file mode 100644 index 0000000..7377525 --- /dev/null +++ b/editor/resources/imgui.ini @@ -0,0 +1,49 @@ +[Window][DockSpaceViewport_11111111] +Pos=0,24 +Size=900,576 +Collapsed=0 + +[Window][ Properties] +Pos=706,24 +Size=194,576 +Collapsed=0 +DockId=0x00000002,0 + +[Window][Debug##Default] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Window][ Entities] +Pos=0,24 +Size=176,576 +Collapsed=0 +DockId=0x00000003,0 + +[Window][ Files] +Pos=178,442 +Size=526,158 +Collapsed=0 +DockId=0x00000006,0 + +[Window][ Scene] +Pos=178,24 +Size=526,416 +Collapsed=0 +DockId=0x00000005,0 + +[Window][ Console] +Pos=178,442 +Size=526,158 +Collapsed=0 +DockId=0x00000006,1 + +[Docking][Data] +DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,24 Size=900,576 Split=X + DockNode ID=0x00000003 Parent=0x8B93E3BD SizeRef=176,576 Selected=0xCCD86976 + DockNode ID=0x00000004 Parent=0x8B93E3BD SizeRef=722,576 Split=X + DockNode ID=0x00000001 Parent=0x00000004 SizeRef=526,576 Split=Y Selected=0xEE09B48D + DockNode ID=0x00000005 Parent=0x00000001 SizeRef=517,416 CentralNode=1 Selected=0xEE09B48D + DockNode ID=0x00000006 Parent=0x00000001 SizeRef=517,158 Selected=0x3CB89FC3 + DockNode ID=0x00000002 Parent=0x00000004 SizeRef=194,576 Selected=0x7B89DB48 + diff --git a/editor/src/GUI.cpp b/editor/src/GUI.cpp index 20e5699..c515a37 100644 --- a/editor/src/GUI.cpp +++ b/editor/src/GUI.cpp @@ -33,17 +33,19 @@ void GUI::LoadConfigs() io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + io.IniFilename = EDITOR_RESOURCES_PATH"imgui.ini"; + float baseFontSize = 14.0f; float iconFontSize = baseFontSize * 2.0f / 2.4f; // FontAwesome fonts need to have their sizes reduced by 2.0f/3.0f in order to align correctly - io.Fonts->AddFontFromFileTTF("fonts/Ruda-Bold.ttf", baseFontSize); + io.Fonts->AddFontFromFileTTF(ENGINE_RESOURCES_PATH"fonts/Ruda-Bold.ttf", baseFontSize); static const ImWchar iconsRanges[] = { ICON_MIN_FA, ICON_MAX_16_FA, 0 }; ImFontConfig iconsConfig; iconsConfig.MergeMode = true; iconsConfig.PixelSnapH = true; iconsConfig.GlyphMinAdvanceX = iconFontSize; - io.Fonts->AddFontFromFileTTF( "fonts/" FONT_ICON_FILE_NAME_FAS, iconFontSize, &iconsConfig, iconsRanges ); + io.Fonts->AddFontFromFileTTF(ENGINE_RESOURCES_PATH"fonts/" FONT_ICON_FILE_NAME_FAS, iconFontSize, &iconsConfig, iconsRanges ); ImGui::StyleColorsDark(); diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 7ac7334..79f5b10 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -21,14 +21,17 @@ file(GLOB COMPONENTS_SOURCES "${COMPONENTS_INCLUDES}/*.cpp") set(UI_INCLUDES ui) file(GLOB UI_SOURCES "${UI_INCLUDES}/*.cpp") +set(ENGINE_RESOURCES_DIR resources) + # Build engine as library add_library(${PROJECT_NAME}) # Add resources folder if(CMAKE_BUILD_TYPE STREQUAL "Release") - target_compile_definitions(${PROJECT_NAME} PUBLIC RESOURCES_PATH="./resources/") + file(COPY ${ENGINE_RESOURCES_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + target_compile_definitions(${PROJECT_NAME} PUBLIC ENGINE_RESOURCES_PATH="${CMAKE_CURRENT_BINARY_DIR}/resources/") else() - target_compile_definitions(${PROJECT_NAME} PUBLIC RESOURCES_PATH="${CMAKE_SOURCE_DIR}/engine/resources/") + target_compile_definitions(${PROJECT_NAME} PUBLIC ENGINE_RESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/") endif() # Link sources, include directories, and third party libraries diff --git a/engine/rendering/Renderer.cpp b/engine/rendering/Renderer.cpp index c11958a..e418b6b 100644 --- a/engine/rendering/Renderer.cpp +++ b/engine/rendering/Renderer.cpp @@ -47,7 +47,7 @@ RendererData& Renderer::GetData() void Renderer::LoadShaders() { - s_Data.m_Shader = new Shader(RESOURCES_PATH"shaders/vertex.glsl", RESOURCES_PATH"shaders/fragment.glsl"); + s_Data.m_Shader = new Shader(ENGINE_RESOURCES_PATH"shaders/vertex.glsl", ENGINE_RESOURCES_PATH"shaders/fragment.glsl"); } void Renderer::SetupBuffers() diff --git a/engine/resources/imgui.ini b/engine/resources/imgui.ini deleted file mode 100644 index 2bf75d3..0000000 --- a/engine/resources/imgui.ini +++ /dev/null @@ -1,49 +0,0 @@ -[Window][DockSpaceViewport_11111111] -Pos=0,19 -Size=900,581 -Collapsed=0 - -[Window][Debug##Default] -Pos=60,60 -Size=400,400 -Collapsed=0 - -[Window][Hierarchy] -Pos=0,19 -Size=189,581 -Collapsed=0 -DockId=0x00000005,0 - -[Window][Scene] -Pos=191,19 -Size=510,420 -Collapsed=0 -DockId=0x00000003,0 - -[Window][Project] -Pos=191,441 -Size=510,159 -Collapsed=0 -DockId=0x00000004,0 - -[Window][Console] -Pos=191,441 -Size=510,159 -Collapsed=0 -DockId=0x00000004,1 - -[Window][Inspector] -Pos=703,19 -Size=197,581 -Collapsed=0 -DockId=0x00000002,0 - -[Docking][Data] -DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,19 Size=900,581 Split=X - DockNode ID=0x00000005 Parent=0x8B93E3BD SizeRef=189,581 Selected=0x29EABFBD - DockNode ID=0x00000006 Parent=0x8B93E3BD SizeRef=709,581 Split=X - DockNode ID=0x00000001 Parent=0x00000006 SizeRef=701,581 Split=Y - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=608,420 CentralNode=1 Selected=0xE192E354 - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=608,159 Selected=0xD04A4B96 - DockNode ID=0x00000002 Parent=0x00000006 SizeRef=197,581 Selected=0xE7039252 - diff --git a/scripts/BuildProject.sh b/scripts/BuildProject.sh index 6055f71..4323d49 100755 --- a/scripts/BuildProject.sh +++ b/scripts/BuildProject.sh @@ -1,34 +1,43 @@ #!/bin/bash -BUILD_DIR="build" +RELEASE_BUILD_DIR="build-release" +DEBUG_BUILD_DIR="build-debug" EDITOR_DIR="editor" NAME="ferx" case $1 in - release) - cmake -S .. -B ../"$BUILD_DIR" -G Ninja -DCMAKE_BUILD_TYPE=Release - cmake --build ../"$BUILD_DIR" -j8 + build-release) + cmake -S .. -B ../"$RELEASE_BUILD_DIR" -G Ninja -DCMAKE_BUILD_TYPE=Release + cmake --build ../"$RELEASE_BUILD_DIR" -j8 ;; - debug) - cmake -S .. -B ../"$BUILD_DIR" -G Ninja -DCMAKE_BUILD_TYPE=Debug - cmake --build ../"$BUILD_DIR" -j8 + build-debug) + cmake -S .. -B ../"$DEBUG_BUILD_DIR" -G Ninja -DCMAKE_BUILD_TYPE=Debug + cmake --build ../"$DEBUG_BUILD_DIR" -j8 ;; - run) - cd "../$BUILD_DIR/$EDITOR_DIR" && ./"$NAME" + run-release) + cd "../$RELEASE_BUILD_DIR/$EDITOR_DIR" && ./"$NAME" ;; - clean) - cmake --build ../"$BUILD_DIR" --target clean + run-debug) + cd "../$DEBUG_BUILD_DIR/$EDITOR_DIR" && ./"$NAME" ;; - clean-all) - rm -r ../"$BUILD_DIR" + clean-release) + cmake --build ../"$RELEASE_BUILD_DIR" --target clean + ;; + clean-debug) + cmake --build ../"$DEBUG_BUILD_DIR" --target clean + ;; + clean-release-all) + rm -r ../"$RELEASE_BUILD_DIR" + ;; + clean-debug-all) + rm -r ../"$DEBUG_BUILD_DIR" ;; all) - bash $0 enter_dir - bash $0 debug - bash $0 run + bash $0 build-debug + bash $0 run-debug ;; *) - echo "Usage: $0 {release|debug|run|clean|clean-all|all}" + echo "Usage: $0 {all|build-release|build-debug|run-release|run-debug|clean-release|clean-debug|clean-release-all|clean-debug-all}" exit 1 ;; esac diff --git a/scripts/Makefile b/scripts/Makefile index 5bcf81e..7975e90 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,24 +1,34 @@ -BUILD_DIR = build +DEBUG_BUILD_DIR = build-debug +RELEASE_BUILD_DIR = build-release EDITOR_DIR = editor NAME = ferx RM += -r -all: debug run +all: build-debug run-debug -release: - cmake -S .. -B ../$(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Release - cmake --build ../$(BUILD_DIR) -j8 +build-release: + cmake -S .. -B ../$(RELEASE_BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Release + cmake --build ../$(RELEASE_BUILD_DIR) -j8 -debug: - cmake -S .. -B ../$(BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Debug - cmake --build ../$(BUILD_DIR) -j8 +build-debug: + cmake -S .. -B ../$(DEBUG_BUILD_DIR) -G Ninja -DCMAKE_BUILD_TYPE=Debug + cmake --build ../$(DEBUG_BUILD_DIR) -j8 -run: - cd ../$(BUILD_DIR)/${EDITOR_DIR} && ./${NAME} +run-release: + cd ../$(RELEASE_BUILD_DIR)/${EDITOR_DIR} && ./${NAME} -clean: - cmake --build ../$(BUILD_DIR) --target clean +run-debug: + cd ../$(DEBUG_BUILD_DIR)/${EDITOR_DIR} && ./${NAME} + +clean-release: + cmake --build ../$(RELEASE_BUILD_DIR) --target clean -clean-all: - $(RM) ../$(BUILD_DIR) +clean-debug: + cmake --build ../$(DEBUG_BUILD_DIR) --target clean + +clean-release-all: + $(RM) ../$(RELEASE_BUILD_DIR) + +clean-debug-all: + $(RM) ../$(DEBUG_BUILD_DIR)