Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filetree definitions #4

Open
wants to merge 4 commits into
base: cpp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 40 additions & 31 deletions editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,63 @@ 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"
"${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"

"src/renderer/gui_imgui_renderer.cpp"

"src/window/window_glfw.cpp"
"src/window/input_manager.cpp"

"${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_wgpu.cpp"
"${CMAKE_SOURCE_DIR}/external/imgui/backends/imgui_impl_glfw.cpp")
"src/filesystem/filetree.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://[email protected]/6143604")
PUBLIC SENTRY_DSN="https://[email protected]/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)
1 change: 1 addition & 0 deletions editor/src/core/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../window/window.hpp"
#include "../renderer/render_context.hpp"
#include "../renderer/gui.hpp"
#include "../filesystem/filetree.hpp"

namespace TempehEditor::Core
{
Expand Down
54 changes: 54 additions & 0 deletions editor/src/filesystem/filetree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "filetree.hpp"

#include <memory>
#include <map>
#include <deque>
#include <filesystem>
#include <functional>
#include <tempeh/common/typedefs.hpp>
#include <cassert>
#include <system_error>
#include <list>

namespace TempehEditor::FileSystem {

namespace fs = std::filesystem;

FileTree::FileTree(const fs::path &path_str)
{
std::list<FileTreeMap::iterator> list;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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<FileTree> tree;

if (fs::path(p).filename() == ".git") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a std::vector of excluded directory name and compare using it, rather than just a string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably by putting the excluded directories inside the config file after config parser is done and then pushing the directories into an std::vector

continue;
}
if (fs::is_directory(p)) {
tree = std::make_shared<FileTree>(p);
}

auto [i, _] = hashmap.insert_or_assign(p.string(), tree);
list.push_back(i);
}
}
}

// TODO
void FileTree::traversal(std::function<void(FileMetaData)> f)
{

}

}
35 changes: 35 additions & 0 deletions editor/src/filesystem/filetree.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef _TEMPEH_FILE_FILETREE_HPP
#define _TEMPEH_FILE_FILETREE_HPP

#include <memory>
#include <map>
#include <deque>
#include <filesystem>
#include <functional>
#include <tempeh/common/typedefs.hpp>

namespace TempehEditor::FileSystem
{

struct FileMetaData
{
std::string name;
u32 size;
};

class FileTree
{
private:
using FileTreeMap = std::map<std::string, std::shared_ptr<FileTree>>;
FileTreeMap hashmap;
public:
FileTree(const std::filesystem::path &path_str);



// Implemented as BFS
void traversal(std::function<void(FileMetaData)> f);
};
}

#endif //_TEMPEH_FILE_FILETREE_HPP
1 change: 0 additions & 1 deletion editor/src/renderer/render_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <tempeh/logger.hpp>
#include <tempeh/common/util.hpp>
#include <boost/predef.h>
#include <BackendBinding.h>
//#include <utils/GLFWUtils.h>
#if defined(WIN32)
# define GLFW_EXPOSE_NATIVE_WIN32
Expand Down
5 changes: 3 additions & 2 deletions engine/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ 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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
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}"
)

Expand Down
26 changes: 24 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,33 @@
"tempeh_core_test"
"core/main.cpp"
)

target_link_libraries(
"tempeh_core_test"
PUBLIC "gtest_main"
"tempeh_core_test"
PUBLIC "gtest_main"
)

add_executable(
"tempeh_editor_test"
"editor/filesystem.cpp"
)

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"
PRIVATE "tempeh_engine_editor_lib"
PUBLIC "gtest_main"
)

include(GoogleTest)
gtest_discover_tests(tempeh_core_test)
gtest_discover_tests(tempeh_editor_test)

endif()
Empty file added test/dummy-dir/1.txt
Empty file.
Empty file added test/dummy-dir/2.txt
Empty file.
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions test/editor/filesystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <gtest/gtest.h>

#include <boost/predef.h>
#include <filesystem/filetree.hpp>

TEST(FileSystem, FileTree_ObjectCreation)
{
// For debugging purpose
TempehEditor::FileSystem::FileTree test_obj("/home/rahman/Projects/tempeh-engine/test/dummy-dir");

// 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

}