Skip to content

Commit

Permalink
Implemented base of WorldEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Dec 14, 2023
1 parent d36de49 commit 918e2eb
Show file tree
Hide file tree
Showing 23 changed files with 704 additions and 28 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
2 changes: 2 additions & 0 deletions Volt/Sandbox/src/Sandbox/Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "Sandbox/Window/Net/NetContractPanel.h"
#include "Sandbox/Window/BehaviourGraph/BehaviorPanel.h"
#include "Sandbox/Window/SceneSettingsPanel.h"
#include "Sandbox/Window/WorldEnginePanel.h"
#include "Sandbox/VertexPainting/VertexPainterPanel.h"

#include "Sandbox/Utility/EditorResources.h"
Expand Down Expand Up @@ -145,6 +146,7 @@ void Sandbox::OnAttach()
EditorLibrary::Register<NetPanel>("Advanced");
EditorLibrary::Register<NetContractPanel>("Advanced");
EditorLibrary::Register<SceneSettingsPanel>("", myRuntimeScene);
EditorLibrary::Register<WorldEnginePanel>("", myRuntimeScene);

if (userSettings.sceneSettings.lowMemoryUsage)
{
Expand Down
11 changes: 11 additions & 0 deletions Volt/Sandbox/src/Sandbox/Utility/EditorUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,3 +984,14 @@ void EditorUtils::MarkEntityAsEdited(const Volt::Entity& entity)
auto scene = entity.GetScene();
scene->MarkEntityAsEdited(entity);
}

void EditorUtils::MarkEntityAndChildrenAsEdited(const Volt::Entity& entity)
{
auto scene = entity.GetScene();
scene->MarkEntityAsEdited(entity);

for (const auto& child : entity.GetChildren())
{
MarkEntityAndChildrenAsEdited(child);
}
}
1 change: 1 addition & 0 deletions Volt/Sandbox/src/Sandbox/Utility/EditorUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class EditorUtils
static std::filesystem::path GetThumbnailPathFromPath(const std::filesystem::path& path);

static void MarkEntityAsEdited(const Volt::Entity& entity);
static void MarkEntityAndChildrenAsEdited(const Volt::Entity& entity);

private:
static bool AssetBrowserPopupInternal(const std::string& id, Volt::AssetHandle& assetHandle, bool startState, Volt::AssetType wantedType = Volt::AssetType::None);
Expand Down
2 changes: 1 addition & 1 deletion Volt/Sandbox/src/Sandbox/Window/PropertiesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void PropertiesPanel::UpdateMainContent()
ent.SetLocalPosition(transform.position);
myCurrentScene->InvalidateEntityTransform(entId);

EditorUtils::MarkEntityAsEdited(ent);
EditorUtils::MarkEntityAndChildrenAsEdited(ent);
}
}

Expand Down
20 changes: 18 additions & 2 deletions Volt/Sandbox/src/Sandbox/Window/SceneViewPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ void SceneViewPanel::UpdateMainContent()
//data->myChild = child;
//undoData.push_back(data);

EditorUtils::MarkEntityAsEdited(entity);
m_scene->MoveToLayer(entity, layer.id);
}

Expand Down Expand Up @@ -288,6 +289,7 @@ void SceneViewPanel::UpdateMainContent()
}

entity.SetVisible(newVal);
EditorUtils::MarkEntityAsEdited(entity);
}
}

Expand All @@ -313,6 +315,7 @@ void SceneViewPanel::UpdateMainContent()
}

entity.SetLocked(newVal);
EditorUtils::MarkEntityAsEdited(entity);
}
}
}
Expand Down Expand Up @@ -465,6 +468,7 @@ void SceneViewPanel::HighlightEntity(Volt::Entity entity)
void RecursiveUnpackPrefab(Ref<Volt::Scene> scene, Volt::EntityID id)
{
Volt::Entity entity = scene->GetEntityFromUUID(id);
EditorUtils::MarkEntityAsEdited(entity);

if (entity.HasComponent<Volt::PrefabComponent>())
{
Expand Down Expand Up @@ -845,6 +849,9 @@ void SceneViewPanel::DrawEntity(Volt::Entity entity, const std::string& filter)
undoData.push_back(data);

m_scene->ParentEntity(newParent, child);

EditorUtils::MarkEntityAsEdited(child);
EditorUtils::MarkEntityAsEdited(newParent);
}

Ref<ParentingCommand> command = CreateRef<ParentingCommand>(undoData, ParentingAction::Parent);
Expand Down Expand Up @@ -984,6 +991,7 @@ void SceneViewPanel::DrawEntity(Volt::Entity entity, const std::string& filter)
recursiveSetVisible(e, visible, recursiveSetVisible);
}

EditorUtils::MarkEntityAsEdited(entity);
return false;
};

Expand Down Expand Up @@ -1062,6 +1070,8 @@ void SceneViewPanel::CreatePrefabAndSetupEntities(Volt::Entity entity)

path.erase(std::remove_if(path.begin(), path.end(), ::isspace), path.end());
Volt::AssetManager::SaveAssetAs(prefab, path);

EditorUtils::MarkEntityAndChildrenAsEdited(entity);
}

void SceneViewPanel::UpdatePrefabsInScene(Ref<Volt::Prefab> prefab, Volt::Entity srcEntity)
Expand Down Expand Up @@ -1089,7 +1099,10 @@ void SceneViewPanel::UpdatePrefabsInScene(Ref<Volt::Prefab> prefab, Volt::Entity
return;
}

prefabAsset->UpdateEntityInScene(Volt::Entity{ id, m_scene });
auto entity = Volt::Entity{ id, m_scene };
prefabAsset->UpdateEntityInScene(entity);

EditorUtils::MarkEntityAsEdited(entity);
});

if (prefabAsset->IsReference(srcEntity))
Expand All @@ -1114,7 +1127,10 @@ void SceneViewPanel::UpdatePrefabsInScene(Ref<Volt::Prefab> prefab, Volt::Entity
return;
}

prefabRefAsset->UpdateEntityInScene(Volt::Entity{ id, m_scene });
auto entity = Volt::Entity{ id, m_scene };
prefabRefAsset->UpdateEntityInScene(entity);

EditorUtils::MarkEntityAsEdited(entity);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion Volt/Sandbox/src/Sandbox/Window/ViewportPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void ViewportPanel::UpdateMainContent()
for (const auto& entId : SelectionManager::GetSelectedEntities())
{
auto entity = m_editorScene->GetEntityFromUUID(entId);
EditorUtils::MarkEntityAsEdited(entity);
EditorUtils::MarkEntityAndChildrenAsEdited(entity);
}
}

Expand Down
72 changes: 72 additions & 0 deletions Volt/Sandbox/src/Sandbox/Window/WorldEnginePanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "sbpch.h"
#include "WorldEnginePanel.h"

#include <Volt/Utility/UIUtility.h>
#include <Volt/Math/Math.h>

WorldEnginePanel::WorldEnginePanel(Ref<Volt::Scene>& editorScene)
: EditorWindow("World Engine"), m_editorScene(editorScene)
{
}

void WorldEnginePanel::UpdateMainContent()
{
auto& worldEngine = m_editorScene->GetWorldEngineMutable();

if (UI::BeginProperties("worldEngineSettings"))
{
if (UI::Property("Cell Size", worldEngine.GetSettingsMutable().cellSize))
{
worldEngine.GenerateCells();
}

if (UI::Property("World Size", worldEngine.GetSettingsMutable().worldSize))
{
worldEngine.GenerateCells();
}

UI::EndProperties();
}

ImGui::Text("Cells");

const glm::uvec2& worldSize = worldEngine.GetSettings().worldSize;
const int32_t cellSize = worldEngine.GetSettings().cellSize;

const uint32_t cellCountX = Math::DivideRoundUp(worldSize.x, static_cast<uint32_t>(cellSize));
const uint32_t cellCountY = Math::DivideRoundUp(worldSize.y, static_cast<uint32_t>(cellSize));

const float contentWidth = ImGui::GetContentRegionAvail().x;
const float buttonSize = contentWidth / static_cast<float>(cellCountX);

UI::ScopedStyleFloat2 padding{ ImGuiStyleVar_ItemSpacing, { 0.f } };

for (uint32_t x = 0; x < cellCountX; x++)
{
for (uint32_t y = 0; y < cellCountY; y++)
{
glm::vec4 color = { 1.f, 0.f, 0.f, 1.f };

Volt::WorldCellID cellId = (x * cellCountX) + y;

if (worldEngine.IsCellLoaded(cellId))
{
color = { 0.f, 1.f, 0.f, 1.f };
}

UI::ScopedColor buttonColor{ ImGuiCol_Button, color };

std::string id = "Cell " + std::to_string(cellId) + "##" + std::to_string(x + y);
if (ImGui::Button(id.c_str(), { buttonSize, buttonSize }))
{
worldEngine.BeginStreamingCell(cellId);
}

if (y < cellCountY - 1)
{
ImGui::SameLine();
}
}
}
}

14 changes: 14 additions & 0 deletions Volt/Sandbox/src/Sandbox/Window/WorldEnginePanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "Sandbox/Window/EditorWindow.h"

class WorldEnginePanel : public EditorWindow
{
public:
WorldEnginePanel(Ref<Volt::Scene>& editorScene);

void UpdateMainContent() override;

private:
Ref<Volt::Scene>& m_editorScene;
};
Loading

0 comments on commit 918e2eb

Please sign in to comment.