From ba1362048081f754f796ee14370bf93abe665cee Mon Sep 17 00:00:00 2001 From: Rahman Hakim Date: Thu, 27 Jan 2022 18:34:12 +0700 Subject: [PATCH 1/4] Add filetree --- editor/CMakeLists.txt | 7 +++--- editor/src/core/application.hpp | 1 + editor/src/filesystem/filetree.cpp | 19 ++++++++++++++++ editor/src/filesystem/filetree.hpp | 36 ++++++++++++++++++++++++++++++ engine/core/CMakeLists.txt | 2 +- test/CMakeLists.txt | 31 +++++++++++++++++++++++++ test/editor/filesystem.cpp | 9 ++++++++ 7 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 editor/src/filesystem/filetree.cpp create mode 100644 editor/src/filesystem/filetree.hpp create mode 100644 test/editor/filesystem.cpp diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 551d8e7..ed75fcd 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -11,7 +11,7 @@ set(TEMPEH_ENGINE_EDITOR_HEADERS "src/renderer/gui_renderer.hpp" "src/renderer/editor_camera.hpp" "src/window/keycode_glfw.hpp" - "src/renderer/gui_imgui_renderer.cpp") + "src/filesystem/filetree.hpp") set(TEMPEH_ENGINE_EDITOR_SOURCES "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_wgpu.cpp" @@ -23,10 +23,11 @@ set(TEMPEH_ENGINE_EDITOR_SOURCES "src/core/application.cpp" "src/renderer/render_context.cpp" - + "src/renderer/gui_imgui_renderer.cpp" + "src/window/window_glfw.cpp" "src/window/input_manager.cpp" - + "src/filesystem/filetree.cpp" "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_wgpu.cpp" "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_glfw.cpp") diff --git a/editor/src/core/application.hpp b/editor/src/core/application.hpp index 327e523..6580199 100644 --- a/editor/src/core/application.hpp +++ b/editor/src/core/application.hpp @@ -7,6 +7,7 @@ #include "../window/window.hpp" #include "../renderer/render_context.hpp" #include "../renderer/gui.hpp" +#include "../filesystem/filetree.hpp" namespace TempehEditor::Core { diff --git a/editor/src/filesystem/filetree.cpp b/editor/src/filesystem/filetree.cpp new file mode 100644 index 0000000..2b830cd --- /dev/null +++ b/editor/src/filesystem/filetree.cpp @@ -0,0 +1,19 @@ +#include "filetree.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Tempeh::File { + + FileTree::FileTree(std::string x) { + std::error_code err; + std::filesystem::path y(x); + assert(std::filesystem::exists(y, err)); + }; +} \ No newline at end of file diff --git a/editor/src/filesystem/filetree.hpp b/editor/src/filesystem/filetree.hpp new file mode 100644 index 0000000..636e095 --- /dev/null +++ b/editor/src/filesystem/filetree.hpp @@ -0,0 +1,36 @@ +// +// Created by rahman on 1/27/22. +// + +#ifndef TEMPEH_ENGINE_FILETREE_HPP +#define TEMPEH_ENGINE_FILETREE_HPP + +#include +#include +#include +#include +#include +#include + +namespace Tempeh::File { + + struct FileMetaData { + std::string name; + u32 size; + }; + + class FileTree { + private: + class FileTreeInternal { + std::map> hashmap; + }; + std::unique_ptr root; + public: + FileTree(std::string path); + + // TODO + void tree_traversal(std::function); + }; +} + +#endif //TEMPEH_ENGINE_FILETREE_HPP diff --git a/engine/core/CMakeLists.txt b/engine/core/CMakeLists.txt index 0f3e6ef..cf2a87f 100644 --- a/engine/core/CMakeLists.txt +++ b/engine/core/CMakeLists.txt @@ -29,7 +29,7 @@ target_include_directories("tempeh_core" PUBLIC "$ENV{MONO_INCLUDE_DIR}" PUBLIC "${CMAKE_SOURCE_DIR}/external/glad/include" PUBLIC "${CMAKE_SOURCE_DIR}/engine/core/include" - PUBLIC "${CMAKE_SOURCE_DIR}/engine/common" + PUBLIC "${CMAKE_SOURCE_DIR}/engine/common/include" PUBLIC "${Vulkan_INCLUDE_DIRS}" ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7e3b21b..e2441b7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,11 +5,42 @@ "tempeh_core_test" "core/main.cpp" ) + + add_executable( + "tempeh_editor_test" + "editor/filesystem.cpp" + "${TEMPEH_ENGINE_EDITOR_SOURCES}" + "${TEMPEH_ENGINE_EDITOR_HEADERS}" + ) + target_link_libraries( "tempeh_core_test" PUBLIC "gtest_main" ) + target_link_libraries( + "tempeh_editor_test" + PUBLIC "gtest_main" + # Private, because anyone ain't gonna touch the editor + PRIVATE "glfw" + PRIVATE "boost_predef" + PRIVATE "tempeh_common" + PRIVATE "tempeh_core" + PRIVATE "tempeh_log" + PRIVATE "tempeh_math" + PRIVATE "spdlog::spdlog" + #PUBLIC "sentry::sentry" + PRIVATE "webgpu_dawn" + PRIVATE "dawn_native" + PRIVATE "dawn_utils" + PRIVATE "dawn_proc" + PRIVATE "dawncpp" + PRIVATE "dawncpp_headers" + PRIVATE "imgui" + ) + include(GoogleTest) gtest_discover_tests(tempeh_core_test) + gtest_discover_tests(tempeh_editor_test) + endif() diff --git a/test/editor/filesystem.cpp b/test/editor/filesystem.cpp new file mode 100644 index 0000000..0f23ca8 --- /dev/null +++ b/test/editor/filesystem.cpp @@ -0,0 +1,9 @@ +#include + +#include "/home/rahman/Projects/tempeh-engine/editor/src/filesystem/filetree.hpp" + +TEST(HelloTest, BasicAssertions) { + ASSERT_NO_FATAL_FAILURE({ + Tempeh::File::FileTree test_obj("/home/rahman/Projects/tempeh-engine"); + }); +} From 6afbaf8af7e739ff6ac83118717ca783470f8089 Mon Sep 17 00:00:00 2001 From: Andra Antariksa Date: Thu, 27 Jan 2022 23:13:10 +0700 Subject: [PATCH 2/4] Fix dependencies, cleanup, and add a file test --- editor/CMakeLists.txt | 66 +++++++++++++++----------- editor/src/filesystem/filetree.cpp | 18 +++++-- editor/src/filesystem/filetree.hpp | 28 +++++------ editor/src/renderer/render_context.cpp | 1 - engine/core/CMakeLists.txt | 3 +- test/CMakeLists.txt | 37 ++++++--------- test/editor/filesystem.cpp | 18 +++++-- 7 files changed, 95 insertions(+), 76 deletions(-) diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index ed75fcd..4969887 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -11,15 +11,10 @@ set(TEMPEH_ENGINE_EDITOR_HEADERS "src/renderer/gui_renderer.hpp" "src/renderer/editor_camera.hpp" "src/window/keycode_glfw.hpp" - "src/filesystem/filetree.hpp") + "src/filesystem/filetree.hpp" + ) set(TEMPEH_ENGINE_EDITOR_SOURCES - "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_wgpu.cpp" - "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_glfw.cpp" - - "src/main.cpp" - "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_wgpu.cpp" - "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_glfw.cpp" "src/core/application.cpp" "src/renderer/render_context.cpp" @@ -28,38 +23,51 @@ set(TEMPEH_ENGINE_EDITOR_SOURCES "src/window/window_glfw.cpp" "src/window/input_manager.cpp" "src/filesystem/filetree.cpp" - "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_wgpu.cpp" - "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_glfw.cpp") + ) + +add_library( + "tempeh_engine_editor_lib" + "${TEMPEH_ENGINE_EDITOR_HEADERS}" + "${TEMPEH_ENGINE_EDITOR_SOURCES}") + +target_link_libraries("tempeh_engine_editor_lib" + PUBLIC "glfw" + PUBLIC "boost_predef" + PUBLIC "tempeh_common" + PUBLIC "tempeh_core" + PUBLIC "tempeh_log" + PUBLIC "tempeh_math" + PUBLIC "spdlog::spdlog" + #PUBLIC "sentry::sentry" + PUBLIC "webgpu_dawn" + PUBLIC "dawn_native" + PUBLIC "dawn_utils" + PUBLIC "dawn_proc" + PUBLIC "dawncpp" + PUBLIC "dawncpp_headers" + PUBLIC "imgui" + ) add_executable("tempeh_engine_editor" - ${TEMPEH_ENGINE_EDITOR_SOURCES} - ${TEMPEH_ENGINE_EDITOR_HEADERS}) + "src/main.cpp" + "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_wgpu.cpp" + "${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_glfw.cpp" + ) target_compile_definitions("tempeh_engine_editor" - PUBLIC SENTRY_DSN="https://8e07fe63b9c94200a0926d0d28b54ad2@o1113293.ingest.sentry.io/6143604") + PUBLIC SENTRY_DSN="https://8e07fe63b9c94200a0926d0d28b54ad2@o1113293.ingest.sentry.io/6143604" + ) target_include_directories("tempeh_engine_editor" #PUBLIC "../common" PUBLIC "${CMAKE_SOURCE_DIR}/external/dawn/src/utils" PUBLIC "$ENV{MONO_INCLUDE_DIR}" - PUBLIC ${TEMPEH_COMMON_INCLUDE}) - + PUBLIC ${TEMPEH_COMMON_INCLUDE} + ) + target_link_libraries("tempeh_engine_editor" # Private, because anyone ain't gonna touch the editor - PRIVATE "glfw" - PRIVATE "boost_predef" - PRIVATE "tempeh_common" - PRIVATE "tempeh_core" - PRIVATE "tempeh_log" - PRIVATE "tempeh_math" - PRIVATE "spdlog::spdlog" - #PUBLIC "sentry::sentry" - PRIVATE "webgpu_dawn" - PRIVATE "dawn_native" - PRIVATE "dawn_utils" - PRIVATE "dawn_proc" - PRIVATE "dawncpp" - PRIVATE "dawncpp_headers" - PRIVATE "imgui") + PRIVATE "tempeh_engine_editor_lib" + ) add_dependencies(tempeh_engine_editor webgpu_headers_gen) \ No newline at end of file diff --git a/editor/src/filesystem/filetree.cpp b/editor/src/filesystem/filetree.cpp index 2b830cd..fc0d60e 100644 --- a/editor/src/filesystem/filetree.cpp +++ b/editor/src/filesystem/filetree.cpp @@ -9,11 +9,19 @@ #include #include -namespace Tempeh::File { +namespace TempehEditor::FileSystem { - FileTree::FileTree(std::string x) { + FileTree::FileTree(std::string& path_str) + { + std::filesystem::path path(path_str); std::error_code err; - std::filesystem::path y(x); - assert(std::filesystem::exists(y, err)); - }; + assert(std::filesystem::exists(path, err) && "Path did not exists"); + } + + // TODO + void FileTree::traversal(std::function f) + { + + } + } \ No newline at end of file diff --git a/editor/src/filesystem/filetree.hpp b/editor/src/filesystem/filetree.hpp index 636e095..ab73293 100644 --- a/editor/src/filesystem/filetree.hpp +++ b/editor/src/filesystem/filetree.hpp @@ -1,9 +1,5 @@ -// -// Created by rahman on 1/27/22. -// - -#ifndef TEMPEH_ENGINE_FILETREE_HPP -#define TEMPEH_ENGINE_FILETREE_HPP +#ifndef _TEMPEH_FILE_FILETREE_HPP +#define _TEMPEH_FILE_FILETREE_HPP #include #include @@ -12,25 +8,29 @@ #include #include -namespace Tempeh::File { +namespace TempehEditor::FileSystem +{ - struct FileMetaData { + struct FileMetaData + { std::string name; u32 size; }; - class FileTree { + class FileTree + { private: - class FileTreeInternal { + class FileTreeInternal + { std::map> hashmap; }; std::unique_ptr root; public: - FileTree(std::string path); + FileTree(std::string& path); - // TODO - void tree_traversal(std::function); + // Implemented as BFS + void traversal(std::function f); }; } -#endif //TEMPEH_ENGINE_FILETREE_HPP +#endif //_TEMPEH_FILE_FILETREE_HPP diff --git a/editor/src/renderer/render_context.cpp b/editor/src/renderer/render_context.cpp index 700da50..9f5c15b 100644 --- a/editor/src/renderer/render_context.cpp +++ b/editor/src/renderer/render_context.cpp @@ -5,7 +5,6 @@ #include #include #include -#include //#include #if defined(WIN32) # define GLFW_EXPOSE_NATIVE_WIN32 diff --git a/engine/core/CMakeLists.txt b/engine/core/CMakeLists.txt index cf2a87f..14d6771 100644 --- a/engine/core/CMakeLists.txt +++ b/engine/core/CMakeLists.txt @@ -22,7 +22,8 @@ add_library("tempeh_core" STATIC "include/tempeh/renderer/orthogonal_camera.hpp" "include/tempeh/renderer/perspective_camera.hpp" "src/renderer/orthogonal_camera.cpp" - "src/renderer/perspective_camera.cpp") + "src/renderer/perspective_camera.cpp" + ) target_include_directories("tempeh_core" PUBLIC $ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e2441b7..a2d8354 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,37 +6,28 @@ "core/main.cpp" ) + target_link_libraries( + "tempeh_core_test" + PUBLIC "gtest_main" + ) + add_executable( "tempeh_editor_test" "editor/filesystem.cpp" - "${TEMPEH_ENGINE_EDITOR_SOURCES}" - "${TEMPEH_ENGINE_EDITOR_HEADERS}" ) - target_link_libraries( - "tempeh_core_test" - PUBLIC "gtest_main" + target_include_directories("tempeh_editor_test" + PUBLIC "${CMAKE_SOURCE_DIR}/editor/src" + PUBLIC "${CMAKE_SOURCE_DIR}/external/dawn/src/utils" + PUBLIC "${CMAKE_SOURCE_DIR}/external/predef/include" + PUBLIC "$ENV{MONO_INCLUDE_DIR}" + PUBLIC ${TEMPEH_COMMON_INCLUDE} ) target_link_libraries( - "tempeh_editor_test" - PUBLIC "gtest_main" - # Private, because anyone ain't gonna touch the editor - PRIVATE "glfw" - PRIVATE "boost_predef" - PRIVATE "tempeh_common" - PRIVATE "tempeh_core" - PRIVATE "tempeh_log" - PRIVATE "tempeh_math" - PRIVATE "spdlog::spdlog" - #PUBLIC "sentry::sentry" - PRIVATE "webgpu_dawn" - PRIVATE "dawn_native" - PRIVATE "dawn_utils" - PRIVATE "dawn_proc" - PRIVATE "dawncpp" - PRIVATE "dawncpp_headers" - PRIVATE "imgui" + "tempeh_editor_test" + PRIVATE "tempeh_engine_editor_lib" + PUBLIC "gtest_main" ) include(GoogleTest) diff --git a/test/editor/filesystem.cpp b/test/editor/filesystem.cpp index 0f23ca8..ae3e2d1 100644 --- a/test/editor/filesystem.cpp +++ b/test/editor/filesystem.cpp @@ -1,9 +1,21 @@ #include -#include "/home/rahman/Projects/tempeh-engine/editor/src/filesystem/filetree.hpp" +#include +#include -TEST(HelloTest, BasicAssertions) { +TEST(FileSystem, FileTree_ObjectCreation) +{ + ASSERT_DEATH({ + TempehEditor::FileSystem::FileTree test_obj(std::string("/blah")); + }, "Path did not exists"); + +#ifdef BOOST_OS_WINDOWS ASSERT_NO_FATAL_FAILURE({ - Tempeh::File::FileTree test_obj("/home/rahman/Projects/tempeh-engine"); + // Uhhh... is C:\\ is not a `standard`? + TempehEditor::FileSystem::FileTree test_obj(std::string("C:\\Windows")); }); +#elif BOOST_OS_LINUX + // TODO linux +#endif + } From 4b518246bb39223ccd6f1f71d9c0d1a39d9fe769 Mon Sep 17 00:00:00 2001 From: Rahman Hakim Date: Fri, 28 Jan 2022 18:37:29 +0700 Subject: [PATCH 3/4] Some changes to filetree and implement the FileTree constructor --- editor/src/filesystem/filetree.cpp | 35 ++++++++++++++++++++++++++---- editor/src/filesystem/filetree.hpp | 11 +++++----- test/dummy-dir/1.txt | 0 test/dummy-dir/2.txt | 0 test/dummy-dir/dummy-dir-2/3.txt | 0 test/dummy-dir/dummy-dir-2/4.txt | 0 test/editor/filesystem.cpp | 25 +++++++++++---------- 7 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 test/dummy-dir/1.txt create mode 100644 test/dummy-dir/2.txt create mode 100644 test/dummy-dir/dummy-dir-2/3.txt create mode 100644 test/dummy-dir/dummy-dir-2/4.txt diff --git a/editor/src/filesystem/filetree.cpp b/editor/src/filesystem/filetree.cpp index fc0d60e..db46358 100644 --- a/editor/src/filesystem/filetree.cpp +++ b/editor/src/filesystem/filetree.cpp @@ -8,14 +8,41 @@ #include #include #include +#include namespace TempehEditor::FileSystem { - FileTree::FileTree(std::string& path_str) + namespace fs = std::filesystem; + + FileTree::FileTree(const fs::path &path_str) { - std::filesystem::path path(path_str); - std::error_code err; - assert(std::filesystem::exists(path, err) && "Path did not exists"); + std::list list; + + auto [iter, _] = hashmap.insert_or_assign(path_str.string(), + nullptr); + + list.push_back(iter); + + while (!list.empty()) { + auto current_entry = list.front(); + list.pop_front(); + for (const auto & entry : fs::directory_iterator(current_entry->first)) { + + fs::path p = entry.path(); + + std::shared_ptr tree; + + if (fs::path(p).filename() == ".git") { + continue; + } + if (fs::is_directory(p)) { + tree = std::make_shared(p); + } + + auto [i, _] = hashmap.insert_or_assign(p.string(), tree); + list.push_back(i); + } + } } // TODO diff --git a/editor/src/filesystem/filetree.hpp b/editor/src/filesystem/filetree.hpp index ab73293..7bf4195 100644 --- a/editor/src/filesystem/filetree.hpp +++ b/editor/src/filesystem/filetree.hpp @@ -20,13 +20,12 @@ namespace TempehEditor::FileSystem class FileTree { private: - class FileTreeInternal - { - std::map> hashmap; - }; - std::unique_ptr root; + using FileTreeMap = std::map>; + FileTreeMap hashmap; public: - FileTree(std::string& path); + FileTree(const std::filesystem::path &path_str); + + // Implemented as BFS void traversal(std::function f); diff --git a/test/dummy-dir/1.txt b/test/dummy-dir/1.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy-dir/2.txt b/test/dummy-dir/2.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy-dir/dummy-dir-2/3.txt b/test/dummy-dir/dummy-dir-2/3.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy-dir/dummy-dir-2/4.txt b/test/dummy-dir/dummy-dir-2/4.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/editor/filesystem.cpp b/test/editor/filesystem.cpp index ae3e2d1..b53466f 100644 --- a/test/editor/filesystem.cpp +++ b/test/editor/filesystem.cpp @@ -5,17 +5,20 @@ TEST(FileSystem, FileTree_ObjectCreation) { - ASSERT_DEATH({ - TempehEditor::FileSystem::FileTree test_obj(std::string("/blah")); - }, "Path did not exists"); + // For debugging purpose + TempehEditor::FileSystem::FileTree test_obj("/home/rahman/Projects/tempeh-engine/test/dummy-dir"); -#ifdef BOOST_OS_WINDOWS - ASSERT_NO_FATAL_FAILURE({ - // Uhhh... is C:\\ is not a `standard`? - TempehEditor::FileSystem::FileTree test_obj(std::string("C:\\Windows")); - }); -#elif BOOST_OS_LINUX - // TODO linux -#endif +// ASSERT_DEATH({ +// TempehEditor::FileSystem::FileTree test_obj(std::string("/blah")); +// }, "Path did not exists"); +// +//#ifdef BOOST_OS_WINDOWS +// ASSERT_NO_FATAL_FAILURE({ +// // Uhhh... is C:\\ is not a `standard`? +// TempehEditor::FileSystem::FileTree test_obj(std::string("C:\\Windows")); +// }); +//#elif BOOST_OS_LINUX +// // TODO linux +//#endif } From 21caf9aed840483d5de54b35f087a0ca10e90a17 Mon Sep 17 00:00:00 2001 From: Muhammad Gusti Nurfathin Date: Sat, 29 Jan 2022 03:31:03 +0700 Subject: [PATCH 4/4] Implement FileTree constructor --- editor/src/filesystem/filetree.cpp | 41 ++++++++----------- editor/src/filesystem/filetree.hpp | 13 +++--- test/editor/filesystem.cpp | 3 +- test/{ => testfile}/dummy-dir/1.txt | 0 test/{ => testfile}/dummy-dir/2.txt | 0 .../dummy-dir/dummy-dir-2/3.txt | 0 .../dummy-dir/dummy-dir-2/4.txt | 0 7 files changed, 27 insertions(+), 30 deletions(-) rename test/{ => testfile}/dummy-dir/1.txt (100%) rename test/{ => testfile}/dummy-dir/2.txt (100%) rename test/{ => testfile}/dummy-dir/dummy-dir-2/3.txt (100%) rename test/{ => testfile}/dummy-dir/dummy-dir-2/4.txt (100%) diff --git a/editor/src/filesystem/filetree.cpp b/editor/src/filesystem/filetree.cpp index db46358..5df5539 100644 --- a/editor/src/filesystem/filetree.cpp +++ b/editor/src/filesystem/filetree.cpp @@ -8,39 +8,34 @@ #include #include #include -#include namespace TempehEditor::FileSystem { - - namespace fs = std::filesystem; - - FileTree::FileTree(const fs::path &path_str) + + FileTree::FileTree() { - std::list list; - - auto [iter, _] = hashmap.insert_or_assign(path_str.string(), - nullptr); + } - list.push_back(iter); + FileTree::FileTree(const std::filesystem::path& path) : + m_path(path) + { + std::deque> queue; - while (!list.empty()) { - auto current_entry = list.front(); - list.pop_front(); - for (const auto & entry : fs::directory_iterator(current_entry->first)) { + queue.emplace_back(m_path, m_path); - fs::path p = entry.path(); + while (!queue.empty()) { + auto [current, current_map] = queue.back(); + queue.pop_back(); - std::shared_ptr tree; + for (const auto& entry : std::filesystem::directory_iterator{ current }) { + std::filesystem::path p = entry.path(); + std::shared_ptr dir; - if (fs::path(p).filename() == ".git") { - continue; - } - if (fs::is_directory(p)) { - tree = std::make_shared(p); + if (std::filesystem::is_directory(p)) { + dir = std::make_shared(); + queue.emplace_back(p, dir->m_path); } - auto [i, _] = hashmap.insert_or_assign(p.string(), tree); - list.push_back(i); + current_map.insert_or_assign(p, dir); } } } diff --git a/editor/src/filesystem/filetree.hpp b/editor/src/filesystem/filetree.hpp index 7bf4195..acfa50b 100644 --- a/editor/src/filesystem/filetree.hpp +++ b/editor/src/filesystem/filetree.hpp @@ -10,22 +10,23 @@ namespace TempehEditor::FileSystem { - struct FileMetaData { - std::string name; + std::filesystem::path name; u32 size; }; class FileTree { private: - using FileTreeMap = std::map>; - FileTreeMap hashmap; - public: - FileTree(const std::filesystem::path &path_str); + using FileTreeMap = std::map>; + std::filesystem::path m_path; + FileTreeMap m_file_map; + public: + FileTree(); + FileTree(const std::filesystem::path& path); // Implemented as BFS void traversal(std::function f); diff --git a/test/editor/filesystem.cpp b/test/editor/filesystem.cpp index b53466f..9175bfe 100644 --- a/test/editor/filesystem.cpp +++ b/test/editor/filesystem.cpp @@ -6,7 +6,8 @@ TEST(FileSystem, FileTree_ObjectCreation) { // For debugging purpose - TempehEditor::FileSystem::FileTree test_obj("/home/rahman/Projects/tempeh-engine/test/dummy-dir"); + std::filesystem::path p = std::filesystem::current_path() / "../../../../test/testfile/dummy-dir"; + TempehEditor::FileSystem::FileTree test_obj(p.generic_string()); // ASSERT_DEATH({ // TempehEditor::FileSystem::FileTree test_obj(std::string("/blah")); diff --git a/test/dummy-dir/1.txt b/test/testfile/dummy-dir/1.txt similarity index 100% rename from test/dummy-dir/1.txt rename to test/testfile/dummy-dir/1.txt diff --git a/test/dummy-dir/2.txt b/test/testfile/dummy-dir/2.txt similarity index 100% rename from test/dummy-dir/2.txt rename to test/testfile/dummy-dir/2.txt diff --git a/test/dummy-dir/dummy-dir-2/3.txt b/test/testfile/dummy-dir/dummy-dir-2/3.txt similarity index 100% rename from test/dummy-dir/dummy-dir-2/3.txt rename to test/testfile/dummy-dir/dummy-dir-2/3.txt diff --git a/test/dummy-dir/dummy-dir-2/4.txt b/test/testfile/dummy-dir/dummy-dir-2/4.txt similarity index 100% rename from test/dummy-dir/dummy-dir-2/4.txt rename to test/testfile/dummy-dir/dummy-dir-2/4.txt