Skip to content

Commit

Permalink
Fixed not being able to create and save scenes apart from the one you…
Browse files Browse the repository at this point in the history
… start with
  • Loading branch information
nepp95 committed Dec 1, 2024
1 parent b0db253 commit e3e1688
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 102 deletions.
5 changes: 4 additions & 1 deletion EppoEditor/Projects/Test/Assets/AssetRegistry.epporeg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
Filepath: Scenes\Test.epscene
- AssetHandle: 17362452449132321929
Type: Mesh
Filepath: Meshes\Sponza.glb
Filepath: Meshes\Sponza.glb
- AssetHandle: 17791877549614086362
Type: Scene
Filepath: Scenes\Demo.epscene
3 changes: 3 additions & 0 deletions EppoEditor/Projects/Test/Assets/Scenes/Demo.epscene
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Scene: Demo
Entities:
[]
30 changes: 15 additions & 15 deletions EppoEditor/Projects/Test/Assets/Scenes/Test.epscene
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
Scene: Test
Entities:
- Entity: 8533309991787433210
- Entity: 4053877638510577070
TagComponent:
Tag: Point Light 4
Tag: Floor
TransformComponent:
Translation: [3.9000001, 1, -1.75]
Translation: [0, 0, 0]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
MeshComponent:
MeshHandle: 17362452449132321929
- Entity: 4545082005372352439
TagComponent:
Tag: Point Light 1
TransformComponent:
Translation: [-4.94999981, 1, 1.14999998]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
PointLightComponent:
Expand All @@ -18,24 +27,15 @@ Entities:
Scale: [1, 1, 1]
PointLightComponent:
Color: [1, 0.352941185, 0, 1]
- Entity: 4545082005372352439
- Entity: 8533309991787433210
TagComponent:
Tag: Point Light 1
Tag: Point Light 4
TransformComponent:
Translation: [-4.94999981, 1, 1.14999998]
Translation: [3.9000001, 1, -1.75]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
PointLightComponent:
Color: [1, 0.352941185, 0, 1]
- Entity: 4053877638510577070
TagComponent:
Tag: Floor
TransformComponent:
Translation: [0, 0, 0]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
MeshComponent:
MeshHandle: 17362452449132321929
- Entity: 10124499925899082567
TagComponent:
Tag: Camera
Expand Down
3 changes: 1 addition & 2 deletions EppoEditor/Source/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ namespace Eppo
{
EPPO_ASSERT(Project::GetActive());

Ref<Project> project = Project::GetActive();
project->GetSpecification().StartScene = m_ActiveScene->Handle;
SaveScene();

Project::SaveActive();
}
Expand Down
70 changes: 5 additions & 65 deletions EppoEditor/Source/Panel/ContentBrowserPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ namespace Eppo
ImGui::EndGroup();
ImGui::SameLine();

ImGui::BeginGroup();

Ref<AssetManagerEditor> assetManager = Project::GetActive()->GetAssetManagerEditor();
const auto& assetRegistry = assetManager->GetAssetRegistry();

const AssetType currentAssetType = Utils::AssetTypeFromString(items[currentItem]);

for (const auto& [handle, metadata] : assetRegistry)
Expand All @@ -60,79 +61,18 @@ namespace Eppo

ImGui::BeginGroup();

UI::ImageButton(thumbnail, ImVec2(128.0f, 128.0f), ImVec2(0, 1), ImVec2(1, 0));
UI::ImageButton(metadata.GetName(), thumbnail, ImVec2(128.0f, 128.0f), ImVec2(0, 1), ImVec2(1, 0));
if (ImGui::BeginDragDropSource())
{
ImGui::SetDragDropPayload(Utils::AssetTypeToImGuiPayloadType(currentAssetType), &handle, sizeof(AssetHandle));
ImGui::EndDragDropSource();
}

ImGui::TextDisabled(metadata.GetName().c_str());

ImGui::EndGroup();
ImGui::SameLine();
}
}

void ContentBrowserPanel::UpdateFileList()
{
const auto& assetDir = Filesystem::GetAssetsDirectory();

const ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody;

if (ImGui::BeginTable("Files", 4, flags))
{
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_NoHide);
ImGui::TableSetupColumn("Size", ImGuiTableColumnFlags_WidthFixed, 60.0f);
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed, 60.0f);
ImGui::TableHeadersRow();

TraverseDirectory(assetDir);

ImGui::EndTable();
}
}

void ContentBrowserPanel::TraverseDirectory(const std::filesystem::path& path, uint32_t depth)
{
for (const auto& entry : std::filesystem::directory_iterator(path))
{
if (entry.is_directory())
{
ImGui::TableNextRow();
ImGui::TableNextColumn();

bool open = ImGui::TreeNodeEx(entry.path().filename().string().c_str(), ImGuiTreeNodeFlags_OpenOnArrow);
ImGui::TableNextColumn();

ImGui::TableNextColumn();
ImGui::TableNextColumn();
ImGui::Text("Folder");

if (open)
{
TraverseDirectory(entry, depth + 1);
ImGui::TreePop();
}
}
else {
ImGui::TableNextRow();
ImGui::TableNextColumn();

ImGui::TreeNodeEx(entry.path().filename().string().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen);
if (ImGui::BeginDragDropSource())
{
auto relativePath = std::filesystem::relative(entry, Filesystem::GetAppRootDirectory());
const wchar_t* itemPath = relativePath.c_str();

ImGui::SetDragDropPayload(Utils::GetImGuiPayloadTypeFromExtension(relativePath.extension()), itemPath, (wcslen(itemPath) + 1) * sizeof(wchar_t));
ImGui::EndDragDropSource();
}

ImGui::TableNextColumn();
ImGui::Text("%.2f KB", std::filesystem::file_size(entry.path()) / 1024.0f);
ImGui::TableNextColumn();
ImGui::TextUnformatted("File");
}
}
ImGui::EndGroup();
}
}
5 changes: 0 additions & 5 deletions EppoEditor/Source/Panel/ContentBrowserPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ namespace Eppo

void RenderGui() override;

void UpdateFileList();

private:
void TraverseDirectory(const std::filesystem::path& path, uint32_t depth = 0);

private:
ThumbnailCache m_ThumbnailCache;

Expand Down
11 changes: 9 additions & 2 deletions EppoEngine/Source/Asset/AssetImporter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pch.h"
#include "AssetImporter.h"

#include "Asset/AssetManager.h"
#include "Scene/SceneSerializer.h"
#include "Project/Project.h"

Expand All @@ -9,7 +10,7 @@
namespace Eppo
{
using fn = std::function<Ref<Asset>(AssetHandle, const AssetMetadata&)>;
static std::map<AssetType, fn> s_AssetImportFunctions =
static const std::map<AssetType, fn> s_AssetImportFunctions =
{
{ AssetType::Mesh, AssetImporter::ImportMesh },
{ AssetType::Scene, AssetImporter::ImportScene },
Expand Down Expand Up @@ -51,6 +52,12 @@ namespace Eppo
EPPO_PROFILE_FUNCTION("AssetImporter::ExportScene");

SceneSerializer serializer(scene);
return serializer.Serialize(filepath);
if (!serializer.Serialize(filepath))
return false;

if (!AssetManager::IsAssetHandleValid(scene->Handle) && !AssetManager::IsAssetLoaded(scene->Handle))
return AssetManager::CreateAsset(scene, filepath);

return true;
}
}
2 changes: 1 addition & 1 deletion EppoEngine/Source/Asset/AssetImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Eppo
static Ref<Mesh> ImportMesh(AssetHandle handle, const AssetMetadata& metadata);
static Ref<Scene> ImportScene(AssetHandle handle, const AssetMetadata& metadata);

// Saving
// Exporting
static bool ExportScene(Ref<Scene> scene, const std::filesystem::path& filepath);
};
}
5 changes: 5 additions & 0 deletions EppoEngine/Source/Asset/AssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Eppo
class AssetManager
{
public:
static bool CreateAsset(Ref<Asset> asset, const std::filesystem::path& filepath)
{
return Project::GetActive()->GetAssetManager()->CreateAsset(asset, filepath);
}

template<typename T>
static Ref<T> GetAsset(AssetHandle handle)
{
Expand Down
1 change: 1 addition & 0 deletions EppoEngine/Source/Asset/AssetManagerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Eppo
class AssetManagerBase
{
public:
virtual bool CreateAsset(Ref<Asset> asset, const std::filesystem::path& filepath) = 0;
virtual Ref<Asset> GetAsset(AssetHandle handle) = 0;
virtual bool IsAssetHandleValid(AssetHandle handle) const = 0;
virtual bool IsAssetLoaded(AssetHandle handle) const = 0;
Expand Down
33 changes: 31 additions & 2 deletions EppoEngine/Source/Asset/AssetManagerEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,34 @@ namespace Eppo
}
}

static AssetMetadata s_NullMetadata;
static const AssetMetadata s_NullMetadata = AssetMetadata();

bool AssetManagerEditor::CreateAsset(Ref<Asset> asset, const std::filesystem::path& filepath)
{
EPPO_PROFILE_FUNCTION("AssetManagerEditor::CreateAsset");

AssetHandle handle = asset->Handle;
if (IsAssetHandleValid(handle))
return false;

if (IsAssetLoaded(handle))
return false;

AssetType type = Utils::GetAssetTypeFromFileExtension(filepath.extension());
EPPO_ASSERT(type != AssetType::None);

AssetMetadata metadata;
metadata.Filepath = Project::GetAssetRelativeFilepath(filepath);
metadata.Handle = handle;
metadata.Type = type;

m_AssetData[handle] = metadata;
m_Assets[handle] = asset;

SerializeAssetRegistry();

return true;
}

Ref<Asset> AssetManagerEditor::GetAsset(AssetHandle handle)
{
Expand Down Expand Up @@ -163,7 +190,7 @@ namespace Eppo
return GetMetadata(handle).Filepath;
}

void AssetManagerEditor::SerializeAssetRegistry()
void AssetManagerEditor::SerializeAssetRegistry() const
{
EPPO_PROFILE_FUNCTION("AssetManagerEditor::SerializeAssetRegistry");
EPPO_INFO("Serializing asset registry");
Expand Down Expand Up @@ -239,5 +266,7 @@ namespace Eppo

// Since the information can have changed if a asset did not exist, we serialize it again
SerializeAssetRegistry();

return true;
}
}
3 changes: 2 additions & 1 deletion EppoEngine/Source/Asset/AssetManagerEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Eppo
class AssetManagerEditor : public AssetManagerBase
{
public:
bool CreateAsset(Ref<Asset> asset, const std::filesystem::path& filepath) override;
Ref<Asset> GetAsset(AssetHandle handle) override;

bool IsAssetHandleValid(AssetHandle handle) const override;
Expand All @@ -23,7 +24,7 @@ namespace Eppo

const std::map<AssetHandle, AssetMetadata>& GetAssetRegistry() const { return m_AssetData; }

void SerializeAssetRegistry();
void SerializeAssetRegistry() const;
bool DeserializeAssetRegistry();

private:
Expand Down
2 changes: 1 addition & 1 deletion EppoEngine/Source/Asset/AssetMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Eppo
struct AssetMetadata
{
AssetHandle Handle = 0;
AssetType Type;
AssetType Type = AssetType::None;

std::filesystem::path Filepath;

Expand Down
3 changes: 0 additions & 3 deletions EppoEngine/Source/Core/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ namespace Eppo
EPPO_ASSERT(stream);

stream.write(buffer.As<char>(), buffer.Size);
stream.close();
}

void Filesystem::WriteBytes(const std::filesystem::path& filepath, const std::vector<uint32_t>& buffer, bool overwrite)
Expand All @@ -152,7 +151,6 @@ namespace Eppo
EPPO_ASSERT(stream);

stream.write((char*)buffer.data(), buffer.size() * sizeof(uint32_t));
stream.close();
}

void Filesystem::WriteText(const std::filesystem::path& filepath, const std::string& text, bool overwrite)
Expand All @@ -166,6 +164,5 @@ namespace Eppo
EPPO_ASSERT(stream);

stream.write(text.c_str(), text.size());
stream.close();
}
}
6 changes: 6 additions & 0 deletions EppoEngine/Source/Platform/Vulkan/VulkanSceneRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ namespace Eppo

void VulkanSceneRenderer::SubmitDrawCommand(EntityType type, Ref<DrawCommand> drawCommand)
{
if (type == EntityType::PointLight && m_DrawList[EntityType::PointLight].size() == 8)
{
EPPO_WARN("Trying to submit more point lights than we currently support!");
return;
}

m_DrawList[type].emplace_back(drawCommand);
}

Expand Down
10 changes: 6 additions & 4 deletions EppoEngine/Source/Scene/SceneSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,16 @@ namespace Eppo
out << YAML::Key << "Scene" << YAML::Value << sceneName;
out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq;

m_SceneContext->m_Registry.each([&](auto entityID)
m_SceneContext->m_Registry.sort<IDComponent>([](const auto& lhs, const auto& rhs) { return lhs.ID < rhs.ID; });
auto view = m_SceneContext->m_Registry.view<IDComponent>();
for (auto entity : view)
{
Entity entity(entityID, m_SceneContext.get());
Entity entity(entity, m_SceneContext.get());
if (!entity)
return;
continue;

SerializeEntity(out, entity);
});
}

out << YAML::EndSeq << YAML::EndMap;

Expand Down

0 comments on commit e3e1688

Please sign in to comment.