Skip to content

Commit

Permalink
RenderComponent / Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Daethalus committed May 5, 2024
1 parent a150342 commit 623b382
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 86 deletions.
26 changes: 13 additions & 13 deletions Editor/Source/Fyrion/Editor/Scene/SceneEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ namespace Fyrion
u64 count{};

ResourceObject object = Repository::Read(rid);
if (object.Has(SceneObjectAsset::Children))
if (object.Has(SceneObjectAsset::children))
{
Array<RID> children = object.GetSubObjectSetAsArray(SceneObjectAsset::Children);
Array<RID> children = object.GetSubObjectSetAsArray(SceneObjectAsset::children);
count = children.Size();

for (RID child : children)
Expand Down Expand Up @@ -63,16 +63,16 @@ namespace Fyrion
ResourceObject root = Repository::Write(m_rootObject);

ResourceObject write = Repository::Write(object);
write[SceneObjectAsset::Name] = "Object " + ToString(m_count++);
write[SceneObjectAsset::name] = "Object " + ToString(m_count++);
write.Commit();

Repository::SetUUID(object, UUID::RandomUUID());

Array<RID> children = root[SceneObjectAsset::ChildrenSort].Value<Array<RID>>();
Array<RID> children = root[SceneObjectAsset::childrenSort].Value<Array<RID>>();
children.EmplaceBack(object);
root[SceneObjectAsset::ChildrenSort] = children;
root[SceneObjectAsset::childrenSort] = children;

root.AddToSubObjectSet(SceneObjectAsset::Children, object);
root.AddToSubObjectSet(SceneObjectAsset::children, object);
root.Commit();
}
else
Expand All @@ -89,15 +89,15 @@ namespace Fyrion
m_lastSelectedRid = object;

ResourceObject write = Repository::Write(object);
write[SceneObjectAsset::Name] = "Object " + ToString(m_count++);
write[SceneObjectAsset::name] = "Object " + ToString(m_count++);
write.Commit();

Repository::SetUUID(object, UUID::RandomUUID());

Array<RID> children = writeParent[SceneObjectAsset::ChildrenSort].Value<Array<RID>>();
Array<RID> children = writeParent[SceneObjectAsset::childrenSort].Value<Array<RID>>();
children.EmplaceBack(object);
writeParent[SceneObjectAsset::ChildrenSort] = children;
writeParent.AddToSubObjectSet(SceneObjectAsset::Children, object);
writeParent[SceneObjectAsset::childrenSort] = children;
writeParent.AddToSubObjectSet(SceneObjectAsset::children, object);
writeParent.Commit();
}
}
Expand All @@ -115,13 +115,13 @@ namespace Fyrion
if (RID parent = Repository::GetParent(it.first))
{
ResourceObject writeParent = Repository::Write(parent);
Array<RID> children = writeParent[SceneObjectAsset::ChildrenSort].Value<Array<RID>>();
Array<RID> children = writeParent[SceneObjectAsset::childrenSort].Value<Array<RID>>();
auto itArr = FindFirst(children.begin(), children.end(), it.first);
if (itArr)
{
children.Erase(itArr, itArr + 1);
}
writeParent[SceneObjectAsset::ChildrenSort] = children;
writeParent[SceneObjectAsset::childrenSort] = children;
writeParent.Commit();
}
Repository::DestroyResource(it.first);
Expand Down Expand Up @@ -185,7 +185,7 @@ namespace Fyrion
typeHandler->Destroy(instance);

ResourceObject write = Repository::Write(object);
write.AddToSubObjectSet(SceneObjectAsset::Components, component);
write.AddToSubObjectSet(SceneObjectAsset::components, component);
write.Commit();

Editor::GetAssetTree().MarkDirty();
Expand Down
11 changes: 7 additions & 4 deletions Editor/Source/Fyrion/Editor/Window/PropertiesWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "PropertiesWindow.hpp"

#include "Fyrion/Core/StringUtils.hpp"
#include "Fyrion/Editor/Editor.hpp"
#include "Fyrion/Editor/Scene/SceneEditor.hpp"
#include "Fyrion/ImGui/IconsFontAwesome6.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ namespace Fyrion
nameFlags |= ImGuiInputTextFlags_ReadOnly;
}

StringView objectName = root ? m_sceneEditor.GetRootName() : read[SceneObjectAsset::Name].Value<StringView>();
StringView objectName = root ? m_sceneEditor.GetRootName() : read[SceneObjectAsset::name].Value<StringView>();
m_stringCache = objectName;
u32 hash = HashValue(rid);

Expand Down Expand Up @@ -132,7 +133,7 @@ namespace Fyrion

ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5 * style.ScaleFactor);

Array<RID> components = read.GetSubObjectSetAsArray(SceneObjectAsset::Components);
Array<RID> components = read.GetSubObjectSetAsArray(SceneObjectAsset::components);

bool openComponentSettings = false;

Expand All @@ -145,7 +146,8 @@ namespace Fyrion

ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_AllowItemOverlap;
ImGui::SetNextItemOpen(true, ImGuiCond_Appearing);
bool open = ImGui::CollapsingHeader(typeHandler->GetSimpleName().CStr(), flags);
String name = FormatName(typeHandler->GetSimpleName());
bool open = ImGui::CollapsingHeader(name.CStr(), flags);
bool rightClicked = ImGui::IsItemClicked(ImGuiMouseButton_Right);
bool hovered = ImGui::IsItemHovered();
ImVec2 size = ImGui::GetItemRectSize();
Expand Down Expand Up @@ -208,7 +210,8 @@ namespace Fyrion
TypeHandler* typeHandler = Registry::FindTypeById(derivedType.typeId);
if (typeHandler)
{
if (ImGui::Selectable(typeHandler->GetSimpleName().CStr()))
String name = FormatName(typeHandler->GetSimpleName());
if (ImGui::Selectable(name.CStr()))
{
m_sceneEditor.AddComponent(rid, typeHandler);
}
Expand Down
4 changes: 2 additions & 2 deletions Editor/Source/Fyrion/Editor/Window/SceneTreeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Fyrion
void SceneTreeWindow::DrawSceneObject(RID object)
{
ResourceObject read = Repository::Read(object);
Span<RID> children = read[SceneObjectAsset::ChildrenSort].Value<Span<RID>>();
Span<RID> children = read[SceneObjectAsset::childrenSort].Value<Span<RID>>();


ImGui::TableNextRow();
Expand All @@ -28,7 +28,7 @@ namespace Fyrion
m_nameCache.Clear();
m_nameCache += root ? ICON_FA_CUBES : ICON_FA_CUBE;
m_nameCache += " ";
m_nameCache += root ? m_sceneEditor.GetRootName() : read[SceneObjectAsset::Name].Value<StringView>();
m_nameCache += root ? m_sceneEditor.GetRootName() : read[SceneObjectAsset::name].Value<StringView>();

bool isSelected = m_sceneEditor.IsSelected(object);
auto treeFlags = isSelected ? ImGuiTreeNodeFlags_Selected | ImGuiTreeNodeFlags_SpanAllColumns : ImGuiTreeNodeFlags_SpanAllColumns;
Expand Down
12 changes: 6 additions & 6 deletions Engine/Source/Fyrion/Assets/AssetTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ namespace Fyrion
{
struct UIFont
{
constexpr static u32 FontBytes = 0;
constexpr static u32 fontBytes = 0;
};

struct TextureAsset
{
constexpr static u32 Extent = 0;
constexpr static u32 Channels = 1;
constexpr static u32 extent = 0;
constexpr static u32 channels = 1;
constexpr static u32 Data = 2;
};

struct ShaderAsset
{
constexpr static u32 Bytes = 0;
constexpr static u32 Info = 1;
constexpr static u32 Stages = 2;
constexpr static u32 bytes = 0;
constexpr static u32 info = 1;
constexpr static u32 stages = 2;
};
}
4 changes: 2 additions & 2 deletions Engine/Source/Fyrion/Assets/FontAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Fyrion
Array<u8> bytes = FileSystem::ReadFileAsByteArray(path);
RID rid = Repository::CreateResource<UIFont>();
ResourceObject fontObject = Repository::Write(rid);
fontObject.SetValue(UIFont::FontBytes, bytes);
fontObject.SetValue(UIFont::fontBytes, bytes);
fontObject.Commit();

return rid;
Expand All @@ -21,7 +21,7 @@ namespace Fyrion
void RegisterFontAsset()
{
ResourceTypeBuilder<UIFont>::Builder()
.Value<UIFont::FontBytes, Array<u8>>("FontBytes")
.Value<UIFont::fontBytes, Array<u8>>("FontBytes")
.Build();
ResourceAssets::AddAssetImporter(".ttf,.otf", ImportFontAsset);
}
Expand Down
18 changes: 9 additions & 9 deletions Engine/Source/Fyrion/Assets/ShaderAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ namespace Fyrion
RID shader = Repository::CreateResource<ShaderAsset>();

ResourceObject write = Repository::Write(shader);
write[ShaderAsset::Bytes] = bytes;
write[ShaderAsset::Info] = ShaderManager::ExtractShaderInfo(bytes, stages, renderApi);
write[ShaderAsset::Stages] = stages;
write[ShaderAsset::bytes] = bytes;
write[ShaderAsset::info] = ShaderManager::ExtractShaderInfo(bytes, stages, renderApi);
write[ShaderAsset::stages] = stages;

write.Commit();

Expand Down Expand Up @@ -92,9 +92,9 @@ namespace Fyrion
});

ResourceObject write = Repository::Write(shader);
write[ShaderAsset::Bytes] = bytes;
write[ShaderAsset::Info] = ShaderManager::ExtractShaderInfo(bytes, stages, renderApi);
write[ShaderAsset::Stages] = stages;
write[ShaderAsset::bytes] = bytes;
write[ShaderAsset::info] = ShaderManager::ExtractShaderInfo(bytes, stages, renderApi);
write[ShaderAsset::stages] = stages;
write.Commit();

return shader;
Expand All @@ -106,9 +106,9 @@ namespace Fyrion
void RegisterShaderAsset()
{
ResourceTypeBuilder<ShaderAsset>::Builder()
.Value<ShaderAsset::Bytes, Array<u8>>("Bytes")
.Value<ShaderAsset::Info, ShaderInfo>("Info")
.Value<ShaderAsset::Stages, Array<ShaderStageInfo>>("Stages")
.Value<ShaderAsset::bytes, Array<u8>>("Bytes")
.Value<ShaderAsset::info, ShaderInfo>("Info")
.Value<ShaderAsset::stages, Array<ShaderStageInfo>>("Stages")
.Build();

ResourceAssets::AddAssetImporter(".raster", ImportRasterShader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Fyrion
VulkanBindingSet::VulkanBindingSet(VulkanDevice& vulkanDevice, const RID& shader, BindingSetType bindingSetType) : vulkanDevice(vulkanDevice), shader(shader), bindingSetType(bindingSetType)
{
ResourceObject shaderAsset = Repository::Read(shader);
const ShaderInfo& shaderInfo = shaderAsset[ShaderAsset::Info].As<ShaderInfo>();
const ShaderInfo& shaderInfo = shaderAsset[ShaderAsset::info].As<ShaderInfo>();

for(const DescriptorLayout& descriptorLayout: shaderInfo.descriptors)
{
Expand Down
6 changes: 3 additions & 3 deletions Engine/Source/Fyrion/Graphics/Device/Vulkan/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,9 @@ namespace Fyrion
{
ResourceObject shader = Repository::Read(graphicsPipelineCreation.shader);

Span<u8> bytes = shader[ShaderAsset::Bytes].As<Span<u8>>();
Span<ShaderStageInfo> stages = shader[ShaderAsset::Stages].As<Span<ShaderStageInfo>>();
ShaderInfo shaderInfo = shader[ShaderAsset::Info].As<ShaderInfo>();
Span<u8> bytes = shader[ShaderAsset::bytes].As<Span<u8>>();
Span<ShaderStageInfo> stages = shader[ShaderAsset::stages].As<Span<ShaderStageInfo>>();
ShaderInfo shaderInfo = shader[ShaderAsset::info].As<ShaderInfo>();

VulkanPipelineState* vulkanPipelineState = allocator.Alloc<VulkanPipelineState>();
vulkanPipelineState->graphicsPipelineCreation = graphicsPipelineCreation;
Expand Down
4 changes: 2 additions & 2 deletions Engine/Source/Fyrion/ImGui/ImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ namespace ImGui
ResourceObject dejaVuSans = Repository::Read(Repository::GetByPath("Fyrion://Fonts/DejaVuSans.ttf"));
if (dejaVuSans)
{
const Array<u8>& dejaVuSansBytes = dejaVuSans.GetValue<Array<u8>>(UIFont::FontBytes);
const Array<u8>& dejaVuSansBytes = dejaVuSans.GetValue<Array<u8>>(UIFont::fontBytes);

auto font = ImFontConfig();
font.SizePixels = fontSize * scaleFactor;
Expand Down Expand Up @@ -945,7 +945,7 @@ namespace ImGui
config.FontDataOwnedByAtlas = false;
memcpy(config.Name, "FontAwesome", 11);

const Array<u8>& faSolidBytes = faSolid.GetValue<Array<u8>>(UIFont::FontBytes);
const Array<u8>& faSolidBytes = faSolid.GetValue<Array<u8>>(UIFont::fontBytes);
io.Fonts->AddFontFromMemoryTTF((void*) faSolidBytes.Data(), faSolidBytes.Size(), config.SizePixels, &config, icon_ranges);
}
}
Expand Down
11 changes: 11 additions & 0 deletions Engine/Source/Fyrion/Scene/Components/RenderComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "RenderComponent.hpp"


namespace Fyrion
{
void RenderComponent::RegisterType(NativeTypeHandler<RenderComponent>& type)
{

}
}

13 changes: 13 additions & 0 deletions Engine/Source/Fyrion/Scene/Components/RenderComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#include "Fyrion/Scene/Component.hpp"


namespace Fyrion
{
class FY_API RenderComponent : public Component
{
public:
static void RegisterType(NativeTypeHandler<RenderComponent>& type);
private:
};
}
26 changes: 0 additions & 26 deletions Engine/Source/Fyrion/Scene/Components/Transform.cpp

This file was deleted.

26 changes: 26 additions & 0 deletions Engine/Source/Fyrion/Scene/Components/TransformComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "TransformComponent.hpp"

#include "Fyrion/Scene/SceneObject.hpp"

namespace Fyrion
{
void TransformComponent::NotifyTransformChange() const
{
if (object)
{
object->Notify(TransformChanged);
}
}

void TransformComponent::OnNotify(i64 type)
{
Component::OnNotify(type);
}

void TransformComponent::RegisterType(NativeTypeHandler<TransformComponent>& type)
{
type.Field<&TransformComponent::m_position, &TransformComponent::GetPosition, &TransformComponent::SetPosition>("position");
type.Field<&TransformComponent::m_rotation, &TransformComponent::GetRotation, &TransformComponent::SetRotation>("rotation");
type.Field<&TransformComponent::m_scale, &TransformComponent::GetScale, &TransformComponent::SetScale>("scale");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

namespace Fyrion
{
class Transform : public Component
class FY_API TransformComponent : public Component
{
public:
static void RegisterType(NativeTypeHandler<Transform>& type);

FY_FINLINE void SetPosition(const Vec3& position)
{
Expand Down Expand Up @@ -42,8 +41,10 @@ namespace Fyrion
FY_FINLINE const Mat4& GetGlobalTransform() const { return m_globalTransform; }

void OnNotify(i64 type) override;

inline static i64 TransformChanged = 1001;

static void RegisterType(NativeTypeHandler<TransformComponent>& type);
private:
Vec3 m_position{0, 0, 0};
Quat m_rotation{0, 0, 0, 1};
Expand Down
8 changes: 4 additions & 4 deletions Engine/Source/Fyrion/Scene/SceneAssets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Fyrion
{
struct SceneObjectAsset
{
constexpr static u32 Name = 0;
constexpr static u32 Components = 1;
constexpr static u32 Children = 2;
constexpr static u32 ChildrenSort = 3;
constexpr static u32 name = 0;
constexpr static u32 components = 1;
constexpr static u32 children = 2;
constexpr static u32 childrenSort = 3;
};
}
Loading

0 comments on commit 623b382

Please sign in to comment.