Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#146]: Implement logic to render selected layers in Editor #154

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
34 changes: 24 additions & 10 deletions editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Editor::Editor(const glm::ivec2& screenSize) : gui_(*this)
m_window = std::make_unique< renderer::Window >(screenSize, "Editor", true);

InputManager::Init(m_window->GetWindowHandle());

renderer::VulkanRenderer::Initialize(m_window->GetWindowHandle(),
renderer::ApplicationType::EDITOR);
gui_.Init();
Expand Down Expand Up @@ -455,6 +455,19 @@ Editor::CheckIfObjectGotSelected(const glm::vec2& cursorPosition)
}
}

int32_t
Editor::GetRenderLayerToDraw() const
{
return renderLayerToDraw_;
}

void
Editor::SetRenderLayerToDraw(int32_t layer)
{
renderLayerToDraw_ = layer;
}


void
Editor::SetupRendererData()
{
Expand Down Expand Up @@ -580,8 +593,10 @@ Editor::Render(VkCommandBuffer cmdBuffer)
{
const auto idx = static_cast< size_t >(layer);
const auto& numObjects = renderData.numMeshes.at(idx);
if (numObjects == 0
or (idx == 9 and not m_renderPathfinderNodes) /* layer 9 means pathfinder nodes*/)
const auto renderThisLayer = renderLayerToDraw_ == -1 ? true : renderLayerToDraw_ == layer;
if (numObjects == 0 or !renderThisLayer
or (idx == 9 and not m_renderPathfinderNodes) /* layer 9 means pathfinder nodes*/
)
{
continue;
}
Expand Down Expand Up @@ -834,11 +849,11 @@ Editor::LoadLevel(const std::string& levelPath)

{
SCOPED_TIMER("Total level load");
m_levelFileName = levelPath;
m_currentLevel = std::make_shared< Level >();
m_currentLevel->Load(this, levelPath);

m_levelFileName = levelPath;
m_currentLevel = std::make_shared< Level >();
m_currentLevel->Load(this, levelPath);

SetupPathfinderNodes();

{
Expand Down Expand Up @@ -875,9 +890,8 @@ Editor::LoadLevel(const std::string& levelPath)
gui_.LevelLoaded(m_currentLevel);

m_window->MakeFocus();

}

SetupRendererData();
}

Expand Down
6 changes: 6 additions & 0 deletions editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ class Editor : public Application
bool
IsAnyObjectSelected() const;

int32_t
GetRenderLayerToDraw() const;

void SetRenderLayerToDraw(int32_t);

private:
// [[nodiscard]] std::shared_ptr< EditorObject >
// GetEditorObjectByID(Object::ID ID);
Expand Down Expand Up @@ -253,6 +258,7 @@ class Editor : public Application

bool m_drawGrid = false;
int32_t m_gridCellSize = 128;
int32_t renderLayerToDraw_ = -1;

// constructed in initializer list
EditorGUI gui_;
Expand Down
19 changes: 19 additions & 0 deletions editor/gui/editor_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,25 @@ EditorGUI::RenderLevelMenu() // NOLINT
}
});

CreateActionRowLabel("RenderLayer", [this] {
const auto items = std::to_array< std::string >(
{"All", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"});
const auto layer = parent_.GetRenderLayerToDraw();
if (ImGui::BeginCombo(
"##combo",
fmt::format("{}", layer == -1 ? "All" : std::to_string(layer)).c_str()))
{
for (const auto& item : items)
{
if (ImGui::Selectable(item.c_str()))
{
parent_.SetRenderLayerToDraw(item == "All" ? -1 : std::stoi(item));
}
}
ImGui::EndCombo();
}
});

ImGui::EndTable();
}
}
Expand Down