cleanup and removing nasty segv upon entity deletion

+ Fixing bug where clicking an entity in the hierarchy didn't update the
stats
This commit is contained in:
Erris
2026-02-24 18:10:39 +01:00
parent 38b92611be
commit e69764e149
8 changed files with 96 additions and 148 deletions

View File

@@ -14,7 +14,6 @@
#include <ImGuizmo.h>
#include <cstdint>
#include <imgui.h>
#include <vector>
#include <string>
@@ -148,6 +147,7 @@ namespace OpenEngine {
clicked = true;
} else {
clicked = false;
selected_entity = scene_hierarchy.GetSelectedEntity();
}
framebuffer->Unbind();
@@ -310,7 +310,7 @@ namespace OpenEngine {
glm::mat4 camera_view = editor_camera.GetViewMatrix();
auto& transform_comp = selected_entity.GetComponents<TransformComponent>();
glm::mat4 transform = transform_comp.GetTransform();
glm::mat4 transform = GetTransformFromComp(transform_comp);
bool snap = Input::IsKeyPressed(KeyCode::LeftControl);
float snap_value = 0.1f;
@@ -333,7 +333,8 @@ namespace OpenEngine {
transform_comp.rotation += delta_rotation;
transform_comp.scale = scale;
}
}
} else
guizmo_operation = -1;
};
void OnImGuiRender() override

View File

@@ -1,18 +1,16 @@
#ifndef EDITOR_COMPONENT_HPP
#define EDITOR_COMPONENT_HPP
#include "open_engine/scene/components.hpp"
#include <array>
#include <entt/entity/fwd.hpp>
#include <glm/fwd.hpp>
#include <imgui.h>
namespace OpenEngine {
/*
void DrawVec3Control(const char* label, glm::vec3& values,
float reset_value = 0.0f, float column_width = 100.0f,
const std::array<const char*, 3> labels = {"x", "y", "z"});
*/
void TagOnImGuiRender(entt::registry& registry, entt::entity entity);
@@ -21,7 +19,6 @@ namespace OpenEngine {
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity);
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity);
}
#endif // EDITOR_COMPONENT_HPP

View File

@@ -32,49 +32,6 @@ namespace OpenEngine {
void DrawEntityNode(Entity& entity);
void DrawComponents(Entity& entity);
/*
template <typename T>
void DrawComponentDrawer(Entity& entity, const char* header)
{
bool component_marked_deletion = false;
ImVec2 region_available = ImGui::GetContentRegionAvail();
ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_DefaultOpen
| ImGuiTreeNodeFlags_Framed
| ImGuiTreeNodeFlags_AllowOverlap;
if (entity.HasComponent<T>()) {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{ 4, 4 });
float line_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
bool opened = ImGui::TreeNodeEx((void*)typeid(T).hash_code(), tree_node_flags, "%s", header);
ImGui::SameLine(region_available.x - line_height * 0.5f);
ImGui::PushStyleColor(ImGuiCol_Button, { 0.290f, 0.301f, 0.388f, 1.0f });
if (ImGui::Button("...", ImVec2{ line_height, line_height }))
ImGui::OpenPopup("component_settings");
ImGui::PopStyleColor();
ImGui::PopStyleVar();
if (ImGui::BeginPopup("component_settings")) {
if (ImGui::MenuItem("Remove component"))
component_marked_deletion = true;
ImGui::EndPopup();
}
if (opened) {
entity.GetComponents<T>().OnImGuiRender(entity);
ImGui::TreePop();
}
ImGui::Separator();
}
if (component_marked_deletion)
entity.RemoveComponents<T>();
}
*/
private:
template<typename T>
static void RegisterDrawer(const std::string& name, std::function<void(entt::registry&, entt::entity)> func) {