Skip to content

Commit

Permalink
Added Basic file watcher to make this process easier
Browse files Browse the repository at this point in the history
  • Loading branch information
tomheeleynz committed Jun 22, 2022
1 parent 450308a commit d585e31
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 9 deletions.
1 change: 1 addition & 0 deletions Arcane/src/Arcane.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
////////// Utils
/////////////////////////////////////////////////////
#include "Arcane/Utils/Utils.h"
#include "Arcane/Utils/FileWatcher.h"
2 changes: 1 addition & 1 deletion Arcane/src/Arcane/ECS/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Arcane
{
glm::vec3 pos = {0.0f, 0.0f, 0.0f};
glm::vec3 rot = {0.0f, 0.0f, 0.0f};
glm::vec3 scale = {0.1f, 0.1f, 0.1f };
glm::vec3 scale = {1.0f, 1.0f, 1.0f };
};

struct MeshComponent
Expand Down
2 changes: 1 addition & 1 deletion Arcane/src/Arcane/Renderer/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Arcane
{
Assimp::Importer import;
const aiScene* scene = import.ReadFile(
"C:\\Projects\\Arcane-Engine\\EnchantingTable\\src\\Assets\\Models\\Backpack.fbx",
"C:\\Projects\\Arcane-Engine\\EnchantingTable\\src\\Assets\\Models\\MyModel.fbx",
s_MeshImportFlags
);

Expand Down
4 changes: 3 additions & 1 deletion Arcane/src/Arcane/Renderer/SceneRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ namespace Arcane

// Create Model Matrix
Model currentTransform;
currentTransform.transform = glm::translate(glm::mat4(1), currentMeshComponent.pos) * glm::scale(glm::mat4(1), currentMeshComponent.scale);
currentTransform.transform = glm::translate(glm::mat4(1), currentMeshComponent.pos) *
glm::rotate(glm::mat4(1), glm::radians(0.0f), glm::vec3(0.0f, 0.0f, 1.0f)) *
glm::scale(glm::mat4(1), currentMeshComponent.scale);

// Write to uniform buffer
s_Data.ObjectUniformBuffer->WriteData((void*)&currentTransform, sizeof(Model));
Expand Down
45 changes: 45 additions & 0 deletions Arcane/src/Arcane/Utils/FileWatcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "FileWatcher.h"

namespace Arcane
{
FileWatcher::FileWatcher(std::string path_to_watch, std::chrono::duration<int, std::milli> delay)
{
m_Directory = path_to_watch;
for (auto& file : std::filesystem::recursive_directory_iterator(path_to_watch)) {
m_Paths[file.path().string()] = std::filesystem::last_write_time(file);
}
}

void FileWatcher::Start(const std::function<void(std::string, FileStatus)>& action)
{
auto it = m_Paths.begin();
while (it != m_Paths.end())
{
if (!std::filesystem::exists(it->first)) {
action(it->first, FileStatus::Deleted);
it = m_Paths.erase(it);
}
else {
it++;
}
}

for (auto& file : std::filesystem::recursive_directory_iterator(m_Directory)) {
auto current_file_last_write_time = std::filesystem::last_write_time(file);

if (!contains(file.path().string()))
{
m_Paths[file.path().string()] = current_file_last_write_time;
action(file.path().string(), FileStatus::Created);
}
else {
if (m_Paths[file.path().string()] != current_file_last_write_time) {
m_Paths[file.path().string()] = current_file_last_write_time;
action(file.path().string(), FileStatus::Modified);
}
}
}


}
}
35 changes: 35 additions & 0 deletions Arcane/src/Arcane/Utils/FileWatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <string>
#include <chrono>
#include <filesystem>
#include <map>
#include <unordered_map>
#include <functional>

enum class FileStatus
{
Created,
Deleted,
Modified
};

namespace Arcane
{
class FileWatcher
{
public:
FileWatcher(std::string path_to_watch, std::chrono::duration<int, std::milli> delay);
void Start(const std::function<void(std::string, FileStatus)>& action);

private:
std::chrono::duration<int, std::milli> m_Delay;
std::unordered_map<std::string, std::filesystem::file_time_type> m_Paths;
std::string m_Directory;

bool contains(const std::string & key) {
auto el = m_Paths.find(key);
return el != m_Paths.end();
}
};
}
Binary file added EnchantingTable/src/Assets/Models/MyModel.fbx
Binary file not shown.
9 changes: 3 additions & 6 deletions EnchantingTable/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void EditorLayer::OnAttach()
m_ScenePanel->SetContext(m_ActiveScene);

m_EntityPanel = new EntityPanel();
m_FileBrowserPanel = new FileBrowserPanel();

// Setup Camera
m_EditorCamera = new Arcane::PerspectiveCamera(512, 512, 45.0f);
Expand Down Expand Up @@ -139,13 +140,9 @@ void EditorLayer::OnImGuiRender()

m_EntityPanel->SetContext(m_ScenePanel->GetSelectedEntity());
m_EntityPanel->Update();

ImGui::Begin("File Browser");
{

}
ImGui::End();

m_FileBrowserPanel->OnUpdate();

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));

ImGui::Begin("Viewport");
Expand Down
2 changes: 2 additions & 0 deletions EnchantingTable/src/EditorLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Panels
#include "Panels/ScenePanel.h"
#include "Panels/EntityPanel.h"
#include "Panels/FileBrowser.h"
#include "Controllers/PerspectiveController.h"

class EditorLayer : public Arcane::Layer
Expand Down Expand Up @@ -35,6 +36,7 @@ class EditorLayer : public Arcane::Layer
// Panels
ScenePanel* m_ScenePanel;
EntityPanel* m_EntityPanel;
FileBrowserPanel* m_FileBrowserPanel;

// Editor Camera
Arcane::PerspectiveCamera* m_EditorCamera;
Expand Down
15 changes: 15 additions & 0 deletions EnchantingTable/src/Panels/FileBrowser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "FileBrowser.h"

FileBrowserPanel::FileBrowserPanel()
{
m_Watcher = new Arcane::FileWatcher("./", std::chrono::milliseconds(5000));
}

void FileBrowserPanel::OnUpdate()
{
ImGui::Begin("File Browser");
{

}
ImGui::End();
}
14 changes: 14 additions & 0 deletions EnchantingTable/src/Panels/FileBrowser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include <Arcane.h>
#include <imgui.h>

class FileBrowserPanel
{
public:
FileBrowserPanel();

void OnUpdate();
private:
Arcane::FileWatcher* m_Watcher;

};

0 comments on commit d585e31

Please sign in to comment.