Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 14 additions & 5 deletions core/Xen/Xen.premake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project "Xen"

kind "ConsoleApp"
language "C++"
staticruntime "on"
staticruntime "off"

targetdir ("%{wks.location}/bin/" .. bin_folder .. "/bin/%{prj.name}")
objdir ("%{wks.location}/bin/" .. bin_folder .. "/obj/%{prj.name}")
Expand Down Expand Up @@ -41,7 +41,8 @@ project "Xen"
}

defines {
"EDITOR_RESOURCES=\"%{EDITOR_RESOURCES_PATH}\""
"EDITOR_RESOURCES=\"%{EDITOR_RESOURCES_PATH}\"",
"PROJECTS=\"%{PROJECTS_PATH}\""
}

filter "files:deps/ImGuizmo/*.cpp"
Expand Down Expand Up @@ -72,10 +73,12 @@ project "Xen"
filter "configurations:Debug"
defines {"XEN_DEBUG", "XEN_LOG_ON"}
symbols "On"
-- buildoptions "/MTd"

filter "configurations:Release_Debug"
defines {"XEN_RELEASE", "XEN_LOG_ON"}
optimize "On"
-- buildoptions "/MT"

filter "configurations:Production"
kind "WindowedApp"
Expand Down Expand Up @@ -107,14 +110,20 @@ project "Xen"

filter { "system:windows", "configurations:Debug" }
links {
"%{Library.ShaderC_Debug}"
"%{Library.ShaderC_Debug}",
"%{Library.SpirVCrossCore_Debug}",
"%{Library.SpirVCrossGLSL_Debug}"
}
filter { "system:windows", "configurations:Release_Debug" }
links {
"%{Library.ShaderC_Release}"
"%{Library.ShaderC_Release}",
"%{Library.SpirVCrossCore_Release}",
"%{Library.SpirVCrossGLSL_Release}"
}
filter { "system:windows", "configurations:Production" }
links {
"%{Library.ShaderC_Release}"
"%{Library.ShaderC_Release}",
"%{Library.SpirVCrossCore_Release}",
"%{Library.SpirVCrossGLSL_Release}",
}

55 changes: 55 additions & 0 deletions core/Xen/src/AssetResourceManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "AssetResourceManager.h"

#include <project/ProjectManager.h>
#include <core/asset/AssetManagerUtil.h>

struct AssetResourceManagerData
{
std::filesystem::path assetPath;
Xen::Ref<Xen::EditorAssetManager> assetManager;

} assetDiscoveryManagerState;

// Implementation: ------------------------------------------------------------------------------------
void AssetResourceManager::Init()
{
Xen::Ref<Xen::Project> currentProject = Xen::ProjectManager::GetCurrentProject();
std::filesystem::path currentProjectPath = Xen::ProjectManager::GetCurrentProjectPath();

assetDiscoveryManagerState.assetPath = currentProjectPath / currentProject->GetProjectSettings().relAssetDirectory;

// This class is supposed to be used only in the editor.(not on the runtime)
assetDiscoveryManagerState.assetManager = Xen::AssetManagerUtil::GetEditorAssetManager();
}

void AssetResourceManager::Load()
{
// This function needs to be run in a different thread.
AssetResourceManager::LoadDirectory(std::filesystem::directory_entry(assetDiscoveryManagerState.assetPath));
}

void AssetResourceManager::StartFileWatcher()
{

}

// Private functions: ----------------------------------------------------------------------------------

// This function will run in a different thread.
void AssetResourceManager::LoadDirectory(const std::filesystem::directory_entry& directory)
{
std::filesystem::recursive_directory_iterator iterator(directory);

for (auto& directoryEntry : iterator)
{
if (directoryEntry.is_regular_file())
{
// Calculate the relative path from the project's asset directory.
std::filesystem::path relativePath = std::filesystem::relative(directoryEntry.path(), assetDiscoveryManagerState.assetPath);

bool loaded = assetDiscoveryManagerState.assetManager->ImportAssetFromFile(relativePath);

// TODO: Dispatch a AssetLoad Event or something.
}
}
}
27 changes: 27 additions & 0 deletions core/Xen/src/AssetResourceManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <Xenode.h>

// TODO: Include this in Xenode.h
#include <core/asset/EditorAssetManager.h>

// This class discovers assets in the assets directory, loads them, builds cache and loads from cache
// If needed.
// The Assets are imported through AssetManager(EditorAssetManager to be precise), and
// reimports(by some notification) them if the assets are changed.
class AssetResourceManager
{
public:
// Sets the current asset path and asset manager instance.
static void Init();

// Loads all the assets in the assetPath to the asset manager.
// This will load from cache if needed.
// This will happen in an different thread.
static void Load();

// Starts the file watcher thread. When any changes are done to the
// asset file, an event is dispatched that the asset has changed.
static void StartFileWatcher();
private:
static void LoadDirectory(const std::filesystem::directory_entry& directory);
};
11 changes: 8 additions & 3 deletions core/Xen/src/LevelEditorLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "LevelEditorLayer.h"
#include "core/scene/ScriptableEntity.h"
#include "AssetResourceManager.h"

#include <core/app/Timer.h>
#include <core/app/Utils.h>
Expand All @@ -23,6 +24,8 @@
#include <core/scene/SceneRuntime.h>
#include <core/scene/Components.h>

#include <core/asset/AssetManagerUtil.h>

Xen::Vec2 mouseInitialPos;

bool operator&(const KeyTransformOperation& o1, const KeyTransformOperation& o2) { return static_cast<uint16_t>(o1) & static_cast<uint16_t>(o2); }
Expand All @@ -40,9 +43,6 @@ void LevelEditorLayer::OnAttach()
{
m_GameMode = Xen::GetApplicationInstance()->GetGameType();

// input = Xen::Input::GetInputInterface();
// input->SetWindow(Xen::DesktopApplication::GetWindow());

m_EditorCamera = std::make_shared<Xen::Camera>(
m_EditorCameraType == Xen::EditorCameraType::_2D ? Xen::CameraType::Orthographic : Xen::CameraType::Perspective,
m_ViewportFrameBufferWidth,
Expand Down Expand Up @@ -147,6 +147,11 @@ void LevelEditorLayer::OnAttach()
Xen::SceneRuntime::SetAdditionalCamera(m_EditorCamera);

m_SceneSettings.renderSource = Xen::RenderSource::AdditionalCamera;

AssetResourceManager::Init();
AssetResourceManager::Load();

Xen::AssetManagerUtil::GetEditorAssetManager()->SerializeRegistry();
}

void LevelEditorLayer::OnDetach()
Expand Down
24 changes: 0 additions & 24 deletions core/Xen/src/Main.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion core/Xen/src/ProjectManagerLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ProjectManagerLayer : Xen::Layer

virtual void OnAttach() override;
virtual void OnDetach() override;
virtual void OnUpdate(double timestep) override;
virtual void OnUpdate(float timestep) override;
virtual void OnFixedUpdate() override;
virtual void OnRender() override;
};
7 changes: 5 additions & 2 deletions core/Xen/src/XenEditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ class XenEditorApp : public Xen::DesktopGameApplication
Xen::DesktopGameApplication::OnStart();

#ifndef XEN_PRODUCTION
// Load the default project in case of debug and release_debug builds:
Xen::Ref<Xen::Project> p = Xen::ProjectManager::LoadProject("../../resources/projects/default_project/default_project.xenproject");
// Load the default project in case of debug and release_debug builds:
std::filesystem::path defaultProjectPath(PROJECTS);
defaultProjectPath = defaultProjectPath / "default_project" / "default_project.xenproject";
// In future, this has to be an ABSOLUTE PATH.
Xen::Ref<Xen::Project> p = Xen::ProjectManager::LoadProject(defaultProjectPath);
#else
// TEMP: Implement project creation UI:
XEN_ENGINE_LOG_ERROR("Project Creation UI Not implemented!");
Expand Down
29 changes: 25 additions & 4 deletions core/Xen/src/panel/ContentBrowserPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <core/renderer/Texture.h>
#include <core/app/GameApplication.h>

#include <core/asset/AssetManagerUtil.h>

#include "StringValues.h"

class ContentBrowserPanel
Expand All @@ -23,7 +25,6 @@ class ContentBrowserPanel

void OnImGuiRender()
{

// Load Textures of the icons here:
if (!m_LoadedTextures)
{
Expand Down Expand Up @@ -74,6 +75,25 @@ class ContentBrowserPanel

ImGui::Columns(column_count, "##FileColumns", false);

Xen::AssetPtrRegistry assetRegistry = Xen::AssetManagerUtil::GetEditorAssetManager()->GetLoadedAssetRegistry();

for (auto&& assetPair : assetRegistry)
{
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));

Xen::Ref<Xen::Texture2D> texture = Xen::AssetManagerUtil::GetAsset<Xen::Texture2D>(assetPair.first);

ImGui::PushID(assetPair.first);
ImGui::ImageButton((ImTextureID)(texture->GetNativeTextureID()), { (float)m_IconSize, (float)m_IconSize });

ImGui::PopID();

ImGui::TextWrapped("%u", assetPair.first);
ImGui::PopStyleColor();
ImGui::NextColumn();
}

#if 0
for (auto& p : std::filesystem::directory_iterator{ m_CurrentPath })
{
const auto& path = p.path();
Expand Down Expand Up @@ -117,6 +137,7 @@ class ContentBrowserPanel
ImGui::NextColumn();

}
#endif
ImGui::Columns(1);
ImGui::End();
}
Expand All @@ -136,9 +157,9 @@ class ContentBrowserPanel
std::filesystem::path m_CurrentPath;

// Drag drop types:
std::string m_SceneLoadDropType = "XEN_CONTENT_BROWSER_SCENE_LOAD";
std::string m_TextureLoadDropType = "XEN_CONTENT_BROWSER_TEXTURE_LOAD";
std::string m_ScriptLoadDropType = "XEN_CONTENT_BROWSER_SCRIPT_LOAD";
std::string m_SceneLoadDropType = "XEN_CONTENT_BROWSER_SCENE_LOAD";
std::string m_TextureLoadDropType = "XEN_CONTENT_BROWSER_TEXTURE_LOAD";
std::string m_ScriptLoadDropType = "XEN_CONTENT_BROWSER_SCRIPT_LOAD";

Xen::Ref<Xen::Texture2D> m_FolderTexture;
Xen::Ref<Xen::Texture2D> m_FileTexture;
Expand Down
Loading