Skip to content

Commit

Permalink
Implemented fixes to areas of the engine
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Dec 3, 2023
1 parent ee995b8 commit 387cfca
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Engine/Launcher.exe
Git LFS file not shown
4 changes: 2 additions & 2 deletions Engine/Sandbox.exe
Git LFS file not shown
4 changes: 2 additions & 2 deletions Engine/Scripts/Volt-ScriptCore.dll
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ void ComponentPropertyUtility::DrawMonoMembers(Weak<Volt::Scene> scene, const Vo
// #TODO_Ivar: We probably should not have to check this here
if (!currentField->data.IsValid())
{
continue;
const auto& defaultValueData = defaultFieldValueMap.at(name)->data;
currentField->SetValue(defaultValueData.As<const void>(), defaultValueData.GetSize());
}

bool fontChanged = false;
Expand Down
39 changes: 28 additions & 11 deletions Volt/Sandbox/src/Sandbox/Window/SceneViewPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ void SceneViewPanel::UpdateMainContent()

const auto flags = ImGuiTableFlags_Reorderable | ImGuiTableFlags_ScrollY | ImGuiTableFlags_NoPadInnerX;

constexpr uint32_t columnCount = 2;
const uint32_t columnCount = m_showEntityUUIDs ? 3 : 2;
if (ImGui::BeginTable("entitiesTable", columnCount, flags, ImGui::GetContentRegionAvail()))
{
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);

if (m_showEntityUUIDs)
{
ImGui::TableSetupColumn("UUID", ImGuiTableColumnFlags_WidthStretch);
}

ImGui::TableSetupColumn("Modifiers", ImGuiTableColumnFlags_WidthFixed, 70.f);

// Headers
Expand Down Expand Up @@ -231,14 +237,14 @@ void SceneViewPanel::UpdateMainContent()
// If there is a payload, assume it's all the selected entities
if (payload)
{
const size_t count = payload->DataSize / sizeof(entt::entity);
const size_t count = payload->DataSize / sizeof(Volt::EntityID);
std::vector<Ref<ParentChildData>> undoData;

for (size_t i = 0; i < count; i++)
{
entt::entity id = *(((entt::entity*)payload->Data) + i);
Volt::EntityID id = *(((Volt::EntityID*)payload->Data) + i);
//Volt::Entity parent(entity, myScene.get());
Volt::Entity entity(id, m_scene.get());
Volt::Entity entity = m_scene->GetEntityFromUUID(id);

//Ref<ParentChildData> data = CreateRef<ParentChildData>();
//data->myParent = parent;
Expand Down Expand Up @@ -355,13 +361,13 @@ void SceneViewPanel::UpdateMainContent()
// If there is a payload, assume it's all the selected entities
if (payload)
{
const size_t count = payload->DataSize / sizeof(entt::entity);
const size_t count = payload->DataSize / sizeof(Volt::EntityID);
std::vector<Ref<ParentChildData>> undoData;

for (size_t i = 0; i < count; i++)
{
entt::entity id = *(((entt::entity*)payload->Data) + i);
Volt::Entity child(id, m_scene.get());
Volt::EntityID id = *(((Volt::EntityID*)payload->Data) + i);
Volt::Entity child = m_scene->GetEntityFromUUID(id);

Ref<ParentChildData> data = CreateRef<ParentChildData>();
data->myParent = child.GetParent();
Expand Down Expand Up @@ -812,7 +818,7 @@ void SceneViewPanel::DrawEntity(Volt::Entity entity, const std::string& filter)
i++;
}

ImGui::SetDragDropPayload("scene_entity_hierarchy", selectedEntities.data(), selectedEntities.size() * sizeof(entt::entity));
ImGui::SetDragDropPayload("scene_entity_hierarchy", selectedEntities.data(), selectedEntities.size() * sizeof(Volt::EntityID));
ImGui::EndDragDropSource();
}
}
Expand All @@ -824,14 +830,14 @@ void SceneViewPanel::DrawEntity(Volt::Entity entity, const std::string& filter)
// If there is a payload, assume it's all the selected entities
if (payload)
{
const size_t count = payload->DataSize / sizeof(entt::entity);
const size_t count = payload->DataSize / sizeof(Volt::EntityID);
std::vector<Ref<ParentChildData>> undoData;

for (size_t i = 0; i < count; i++)
{
entt::entity id = *(((entt::entity*)payload->Data) + i);
Volt::EntityID id = *(((Volt::EntityID*)payload->Data) + i);
Volt::Entity newParent = entity;
Volt::Entity child(id, m_scene);
Volt::Entity child = m_scene->GetEntityFromUUID(id);

Ref<ParentChildData> data = CreateRef<ParentChildData>();
data->myParent = newParent;
Expand Down Expand Up @@ -945,6 +951,14 @@ void SceneViewPanel::DrawEntity(Volt::Entity entity, const std::string& filter)

ImGui::TableNextColumn();

// UUIDs
if (m_showEntityUUIDs)
{
const std::string text = std::to_string(entity.GetID());
ImGui::TextUnformatted(text.c_str());
ImGui::TableNextColumn();
}

// Modifiers
{
const float imageSize = 21.f;
Expand Down Expand Up @@ -1444,6 +1458,9 @@ void SceneViewPanel::DrawMainRightClickPopup()
});
UI::Notify(NotificationType::Success, "8===D", "Brrrrrrrrrrrrrrrrrrrr");
}

ImGui::MenuItem("Show UUIDS", nullptr, &m_showEntityUUIDs);

ImGui::EndPopup();
}
}
Expand Down
2 changes: 2 additions & 0 deletions Volt/Sandbox/src/Sandbox/Window/SceneViewPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ class SceneViewPanel : public EditorWindow
std::unordered_map<Volt::EntityID, ImGuiID> m_entityToImGuiID;
bool m_rebuildDrawList = false;

bool m_showEntityUUIDs = false;

Ref<Volt::Scene>& m_scene;
};
6 changes: 6 additions & 0 deletions Volt/Sandbox/src/Sandbox/Window/VisonPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ void VisionPanel::UpdateCameraProperties()

UI::PushID();

const int32_t cameraCount = static_cast<int32_t>(myVisionCams.size());
if (mySelectedCamera > cameraCount)
{
mySelectedCamera = cameraCount - 1;
}

if (mySelectedCamera == -1 || !myVisionCams[mySelectedCamera].IsValid())
{
UI::PopID();
Expand Down
14 changes: 13 additions & 1 deletion Volt/Volt/src/Volt/Asset/AssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ namespace Volt
std::vector<std::filesystem::path> AssetManager::GetEngineMetaFiles()
{
std::vector<std::filesystem::path> files;
std::string ext(".vtmeta");
const std::string ext(".vtmeta");

// Engine Directory
for (auto& p : std::filesystem::recursive_directory_iterator(ProjectManager::GetEngineDirectory() / "Engine"))
Expand All @@ -1184,6 +1184,18 @@ namespace Volt
}
}

const auto editorFolder = ProjectManager::GetEngineDirectory() / "Editor";
if (FileSystem::Exists(editorFolder))
{
for (auto& p : std::filesystem::recursive_directory_iterator(editorFolder))
{
if (p.path().extension() == ext)
{
files.emplace_back(p.path());
}
}
}

return files;
}

Expand Down
2 changes: 2 additions & 0 deletions Volt/Volt/src/Volt/Components/CoreComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace Volt
reflect.SetHidden();
reflect.AddMember(&IDComponent::id, "id", "ID", "", EntityID{}, ComponentMemberFlag::NoSerialize);
}

REGISTER_COMPONENT(IDComponent);
};

struct TransformComponent
Expand Down
10 changes: 5 additions & 5 deletions Volt/Volt/src/Volt/Core/UUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

namespace Volt
{
static std::random_device s_RandomDevice;
static std::mt19937_64 s_Engine(s_RandomDevice());
static std::mt19937 s_Engine32(s_RandomDevice());
static std::random_device s_randomDevice;
static std::mt19937_64 s_Engine(s_randomDevice());
static std::mt19937 s_engine32(s_randomDevice());
static std::uniform_int_distribution<uint64_t> s_UniformDistribution;
static std::uniform_int_distribution<uint32_t> s_UniformDistribution32;
static std::uniform_int_distribution<uint32_t> s_uniformDistribution32;

UUID::UUID()
: myUUID(s_UniformDistribution(s_Engine))
{
}

UUID32::UUID32()
: myUUID(s_UniformDistribution32(s_Engine32))
: m_uuid(s_uniformDistribution32(s_engine32))
{
}
}
6 changes: 3 additions & 3 deletions Volt/Volt/src/Volt/Core/UUID.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ namespace Volt
public:
UUID32();
constexpr UUID32(uint32_t uuid)
: myUUID(uuid)
: m_uuid(uuid)
{}

UUID32(const UUID32&) = default;
~UUID32() = default;

operator uint32_t() const { return myUUID; }
operator uint32_t() const { return m_uuid; }
private:
uint32_t myUUID;
uint32_t m_uuid;
};
}

Expand Down
15 changes: 15 additions & 0 deletions Volt/Volt/src/Volt/Rendering/DebugRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ namespace Volt

void DebugRenderer::DrawMesh(Ref<Mesh> mesh, const glm::vec3& position, const glm::vec3& rotation, const glm::vec3& scale)
{
if (!mesh)
{
return;
}

s_debugRenderData->functionQueue.emplace_back([mesh, position, rotation, scale](SceneRenderer::PerThreadData& data)
{
const glm::mat4 transform = glm::translate(glm::mat4{ 1.f }, position)* glm::mat4_cast(glm::quat(rotation))* glm::scale(glm::mat4{ 1.f }, scale);
Expand All @@ -107,6 +112,11 @@ namespace Volt

void DebugRenderer::DrawMesh(Ref<Mesh> mesh, const glm::mat4& transform)
{
if (!mesh)
{
return;
}

s_debugRenderData->functionQueue.emplace_back([mesh, transform](SceneRenderer::PerThreadData& data)
{
for (uint32_t i = 0; const auto & subMesh : mesh->GetSubMeshes())
Expand All @@ -123,6 +133,11 @@ namespace Volt

void DebugRenderer::DrawMesh(Ref<Mesh> mesh, Ref<Material> material, const glm::mat4& transform, uint32_t id)
{
if (!material || !mesh)
{
return;
}

s_debugRenderData->functionQueue.emplace_back([mesh, transform, id, material](SceneRenderer::PerThreadData& data)
{
for (uint32_t i = 0; const auto & subMesh : mesh->GetSubMeshes())
Expand Down
6 changes: 3 additions & 3 deletions Volt/Volt/src/Volt/Scene/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ namespace Volt
const auto& srcFields = srcScene->GetScriptFieldCache().GetCache().at(srcComponent.scriptIds.at(i));
auto& dstFields = dstScene->GetScriptFieldCache().GetCache()[dstComponent.scriptIds[i]];

for (const auto& [name, field] : classFields)
for (const auto [name, field] : classFields)
{
if (!srcFields.contains(name))
{
Expand All @@ -676,10 +676,10 @@ namespace Volt
auto& srcField = srcFields.at(name);

dstFields[name] = CreateRef<MonoScriptFieldInstance>();
dstFields.at(name)->field = srcFields.at(name)->field;
dstFields.at(name)->field = srcField->field;

const void* dataPtr = srcField->data.As<void>();
dstFields.at(name)->SetValue(dataPtr, srcFields.at(name)->field.type.typeSize);
dstFields.at(name)->SetValue(dataPtr, srcField->field.type.typeSize);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions Volt/Volt/src/Volt/Scene/EntityID.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "vtpch.h"
#include "EntityID.h"

#include <random>

namespace Volt
{
static std::random_device s_randomDevice;
static std::mt19937 s_engine32(s_randomDevice());
static std::uniform_int_distribution<uint32_t> s_uniformDistribution32;

EntityID::EntityID()
: m_uuid(s_uniformDistribution32(s_engine32))
{
}
}
33 changes: 30 additions & 3 deletions Volt/Volt/src/Volt/Scene/EntityID.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
#pragma once

#include "Volt/Core/UUID.h"

namespace Volt
{
typedef UUID32 EntityID;
class EntityID
{
public:
EntityID();
constexpr EntityID(uint32_t uuid)
: m_uuid(uuid)
{
}

EntityID(const EntityID&) = default;
~EntityID() = default;

operator uint32_t() const { return m_uuid; }
private:
uint32_t m_uuid;
};
}

namespace std
{
template <typename T> struct hash;

template<>
struct hash<Volt::EntityID>
{
std::size_t operator()(const Volt::EntityID& uuid) const
{
return (uint32_t)uuid;
}
};
}
6 changes: 4 additions & 2 deletions Volt/Volt/src/Volt/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,10 @@ namespace Volt

m_registry.each([&](entt::entity id)
{
id = otherScene->m_registry.create(id);
Entity::Copy(Entity{ id, this }, Entity{ id, otherScene }, EntityCopyFlags::None);
const EntityID uuid = m_registry.get<IDComponent>(id).id;

auto entity = otherScene->CreateEntityWithUUID(uuid);
Entity::Copy(Entity{ id, this }, entity, EntityCopyFlags::None);
});
}

Expand Down
2 changes: 1 addition & 1 deletion Volt/Volt/src/Volt/Scripting/Mono/MonoScriptGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace Volt
return scene->IsEntityValid(entityId);
}

inline static bool Entity_HasComponent(EntityID entityId, MonoString* componentType)
inline static bool Entity_HasComponent(uint32_t entityId, MonoString* componentType)
{
Scene* scene = MonoScriptEngine::GetSceneContext();
Entity entity = scene->GetEntityFromUUID(entityId);
Expand Down
5 changes: 5 additions & 0 deletions Volt/Volt/src/Volt/Scripting/Mono/MonoScriptInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,9 @@ namespace Volt

return true;
}

//bool MonoScriptInstance::GetFieldInternal(const std::string& name, EntityID& outData)
//{
// return false;
//}
}
Loading

0 comments on commit 387cfca

Please sign in to comment.