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

Store SceneInfo through a pointer instead of by value #631

Merged
merged 1 commit into from
Oct 1, 2023
Merged
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
27 changes: 15 additions & 12 deletions engine/src/cubos/engine/tools/scene_editor/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <memory>
#include <vector>

#include <imgui.h>
#include <misc/cpp/imgui_stdlib.h>

Expand Down Expand Up @@ -30,7 +33,7 @@ struct SceneInfo
bool shouldBeRemoved{false};
std::string name;
std::vector<std::pair<std::string, Entity>> entities;
std::vector<std::pair<std::string, SceneInfo>> scenes;
std::vector<std::pair<std::string, std::unique_ptr<SceneInfo>>> scenes;
};

static void closeScene(Commands& commands, SceneInfo& scene)
Expand All @@ -43,7 +46,7 @@ static void closeScene(Commands& commands, SceneInfo& scene)

for (auto& [name, subscene] : scene.scenes)
{
closeScene(commands, subscene);
closeScene(commands, *subscene);
}
scene.scenes.clear();
}
Expand All @@ -62,14 +65,14 @@ static void placeEntity(const std::string& name, Entity handle, SceneInfo& scene
{
if (sname == subsceneName)
{
placeEntity(name.substr(split + 1), handle, subscene);
placeEntity(name.substr(split + 1), handle, *subscene);
return;
}
}
SceneInfo subScene;
subScene.name = subsceneName;
auto& [_, subSceneHandle] = scene.scenes.emplace_back(subsceneName, subScene);
placeEntity(name.substr(split + 1), handle, subSceneHandle);
auto subScene = std::make_unique<SceneInfo>();
subScene->name = subsceneName;
auto& subSceneHandle = scene.scenes.emplace_back(subsceneName, std::move(subScene)).second;
placeEntity(name.substr(split + 1), handle, *subSceneHandle);
}
}

Expand Down Expand Up @@ -211,9 +214,9 @@ static void showSceneHierarchy(SceneInfo& scene, Commands& cmds, cubos::engine::
if (ImGui::Button("Add Scene"))
{
std::string sceneName = scene.name + "_scene_" + std::to_string(scene.scenes.size() + 1);
SceneInfo newSubscene;
newSubscene.name = sceneName;
scene.scenes.emplace_back(sceneName, newSubscene);
auto newSubscene = std::make_unique<SceneInfo>();
newSubscene->name = sceneName;
scene.scenes.emplace_back(sceneName, std::move(newSubscene));
}
ImGui::SameLine();
}
Expand All @@ -222,13 +225,13 @@ static void showSceneHierarchy(SceneInfo& scene, Commands& cmds, cubos::engine::
std::vector<std::size_t> sceneToRemove;
for (std::size_t i = 0; i < scene.scenes.size(); i++)
{
if (scene.scenes[i].second.shouldBeRemoved)
if (scene.scenes[i].second->shouldBeRemoved)
{
sceneToRemove.push_back(i);
}
else
{
showSceneHierarchy(scene.scenes[i].second, cmds, selector, hierarchyDepth + 1);
showSceneHierarchy(*scene.scenes[i].second, cmds, selector, hierarchyDepth + 1);
}
}
for (const auto& i : sceneToRemove)
Expand Down
Loading