Skip to content
This repository was archived by the owner on Sep 6, 2025. It is now read-only.

Commit 546436e

Browse files
committed
fix: Rendering artifacts when switching projects; change: EditorSceneRenderer now lives in Editor class
1 parent 3986a13 commit 546436e

File tree

17 files changed

+707
-592
lines changed

17 files changed

+707
-592
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
This file was deleted.

Lava/src/Lava/Core/SceneRenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ void RuntimeSceneRenderer::OnSceneLoad() {
235235

236236
void RuntimeSceneRenderer::OnSceneClose() {
237237
s_ParticleEmitters.clear();
238+
s_MaterialMeshes.clear();
238239
}
239240

240241
void RuntimeSceneRenderer::Update(TimeStep ts) {

Magma/src/Editor/Editor/Editor.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct {
5454
} tab;
5555
} static menu;
5656

57+
static UI::Image s_WelcomeImage;
58+
5759
void Editor::Open() {
5860
Physics::Init();
5961
AudioEngine::Init();
@@ -63,7 +65,7 @@ void Editor::Open() {
6365
m_App = CreateRef<Lava::App>();
6466

6567
Application::PushDir();
66-
m_WelcomeImage.Content =
68+
s_WelcomeImage.Content =
6769
AssetImporter::GetTexture("Magma/assets/images/VolcanicDisplay.png");
6870
Application::PopDir();
6971
}
@@ -279,7 +281,8 @@ void Editor::RenderEmptyTab(Ref<Tab>& tab) {
279281

280282
void Editor::RenderWelcomeScreen() {
281283
auto flags = ImGuiWindowFlags_NoDecoration
282-
| ImGuiWindowFlags_NoMove;
284+
| ImGuiWindowFlags_NoMove
285+
| ImGuiWindowFlags_NoDocking;
283286
ImGui::Begin("##Welcome", nullptr, flags);
284287
{
285288
ImVec2 size = { 300, ImGui::GetContentRegionAvail().y };
@@ -298,10 +301,10 @@ void Editor::RenderWelcomeScreen() {
298301
ImGui::EndChild();
299302
ImGui::SameLine();
300303

301-
m_WelcomeImage.UsePosition = false;
302-
m_WelcomeImage.Width = 800;
303-
m_WelcomeImage.Height = 800;
304-
m_WelcomeImage.Render();
304+
s_WelcomeImage.UsePosition = false;
305+
s_WelcomeImage.Width = 800;
306+
s_WelcomeImage.Height = 800;
307+
s_WelcomeImage.Render();
305308
}
306309
ImGui::End();
307310
}
@@ -312,6 +315,7 @@ void Editor::SetTab(Ref<Tab> tab) {
312315
auto [_, idx] = m_Tabs.Find([&](auto& val) { return val == tab; });
313316
m_CurrentTab = idx;
314317
title += " - " + tab->GetName();
318+
tab->OnSelect();
315319
}
316320

317321
Application::GetWindow()->SetTitle(title);
@@ -389,7 +393,6 @@ void Editor::NewProject() {
389393
void Editor::NewProject(const std::string& volcPath) {
390394
m_Project.Load(volcPath);
391395

392-
m_AssetManager.Clear();
393396
m_AssetManager.Load(m_Project.Path);
394397

395398
auto rootPath = fs::path(volcPath).parent_path();
@@ -437,11 +440,13 @@ void Editor::OpenProject() {
437440
auto instance = ImGuiFileDialog::Instance();
438441
instance->OpenDialog("ChooseFile", "Choose File", ".magma.proj", config);
439442

440-
if(instance->Display("ChooseFile")) {
443+
if(instance->Display("ChooseFile", 32, { 500.0f, 600.0f })) {
441444
if(instance->IsOk()) {
442-
std::string path = instance->GetFilePathName();
445+
std::string path = instance->GetCurrentPath();
446+
std::string name = instance->GetFilePathName();
447+
auto fullPath = fs::path(path) / name;
443448
CloseProject();
444-
NewProject(path);
449+
NewProject(fullPath.string());
445450
NewTab(CreateRef<ProjectTab>());
446451
}
447452

@@ -465,16 +470,15 @@ void Editor::RunProject() {
465470
}
466471

467472
void Editor::CloseProject() {
468-
if(!GetProjectTab())
469-
return;
470-
471473
m_Tabs.Clear();
472474
m_ClosedTabs.Clear();
475+
m_CurrentTab = 0;
473476

474477
m_AssetManager.Save();
475478
m_AssetManager.Clear();
476479

477480
m_Project.Save((fs::path(m_Project.Path) / ".magma.proj").string());
481+
m_Project = { };
478482
}
479483

480484
void Editor::ExportProject() {

Magma/src/Editor/Editor/Editor.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "UI/UITab.h"
1313

1414
#include "AssetManager.h"
15+
#include "SceneRenderer.h"
1516

1617
using namespace VolcaniCore;
1718

@@ -43,23 +44,25 @@ class Editor {
4344
static EditorAssetManager& GetAssetManager() {
4445
return s_Instance->m_AssetManager;
4546
}
47+
static EditorSceneRenderer& GetSceneRenderer() {
48+
return s_Instance->m_SceneRenderer;
49+
}
4650
static Project& GetProject() { return s_Instance->m_Project; }
47-
static Ref<Lava::App>& GetApp() { return s_Instance->m_App; }
51+
static Ref<Lava::App> GetApp() { return s_Instance->m_App; }
4852

4953
private:
5054
inline static Editor* s_Instance;
5155

5256
private:
57+
Ref<Lava::App> m_App;
5358
Project m_Project;
5459
EditorAssetManager m_AssetManager;
55-
Ref<Lava::App> m_App;
60+
EditorSceneRenderer m_SceneRenderer;
5661

57-
uint64_t m_CurrentTab;
62+
uint64_t m_CurrentTab = 0;
5863
List<Ref<Tab>> m_Tabs;
5964
List<Ref<Tab>> m_ClosedTabs;
6065

61-
UI::Image m_WelcomeImage;
62-
6366
void SetTab(Ref<Tab> tab);
6467
void NewTab();
6568
void OpenTab(TabType type = TabType::None);

0 commit comments

Comments
 (0)