-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: cpp
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) |
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; | ||
|
||
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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
{ | ||
|
||
} | ||
|
||
} |
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 |
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 | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use list.
https://dzone.com/articles/c-benchmark-%E2%80%93-stdvector-vs