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:
@@ -4,7 +4,6 @@
|
||||
#include "open_engine/scene/native_scriptable_entity.hpp"
|
||||
#include "open_engine/scene/scene_camera.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/fwd.hpp>
|
||||
@@ -19,10 +18,6 @@
|
||||
|
||||
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"});
|
||||
|
||||
struct TagComponent
|
||||
{
|
||||
std::string tag;
|
||||
@@ -43,18 +38,10 @@ namespace OpenEngine {
|
||||
TransformComponent(const TransformComponent&) = default;
|
||||
TransformComponent(const glm::vec3& position)
|
||||
: translation(position) {}
|
||||
|
||||
glm::mat4 GetTransform() const
|
||||
{
|
||||
glm::mat4 transform = glm::translate(glm::mat4(1.0f), translation);
|
||||
|
||||
transform *= glm::toMat4(glm::quat(rotation));
|
||||
transform *= glm::scale(glm::mat4(1.0f), scale);
|
||||
|
||||
return transform;
|
||||
};
|
||||
};
|
||||
|
||||
glm::mat4 GetTransformFromComp(TransformComponent& transform_comp);
|
||||
|
||||
struct SpriteRendererComponent
|
||||
{
|
||||
glm::vec4 color{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
@@ -1,83 +1,16 @@
|
||||
#include "imgui.h"
|
||||
#include <pch.hpp>
|
||||
|
||||
#include <scene/components.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
void DrawVec3Control(const char* label, glm::vec3& values,
|
||||
float reset_value, float column_width,
|
||||
const std::array<const char*, 3> labels)
|
||||
glm::mat4 GetTransformFromComp(TransformComponent& transform_comp)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
auto bold_font = io.Fonts->Fonts[0];
|
||||
glm::mat4 transform = glm::translate(glm::mat4(1.0f), transform_comp.translation);
|
||||
|
||||
ImGui::PushID(label);
|
||||
ImVec2 item_spacing = { 15.0f, 0.0f };
|
||||
ImGui::Columns(2);
|
||||
ImGui::SetColumnWidth(0, column_width);
|
||||
ImGui::Text("%s", label);
|
||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && ImGui::IsItemHovered())
|
||||
values = glm::vec3(reset_value);
|
||||
ImGui::NextColumn();
|
||||
transform *= glm::toMat4(glm::quat(transform_comp.rotation));
|
||||
transform *= glm::scale(glm::mat4(1.0f), transform_comp.scale);
|
||||
|
||||
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||
|
||||
float line_height = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
|
||||
ImVec2 button_size = { line_height + 3.0f, line_height };
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 1.0f, 0.8f, 0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.953f, 0.545f, 0.659f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[0], button_size))
|
||||
values.x = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##X", &values.x, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f, 1.0f, 0.9f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.650f, 0.890f, 0.631f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[1], button_size))
|
||||
values.y = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Y", &values.y, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, item_spacing);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.7f, 0.9f, 1.0f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.533f, 0.698f, 0.976f, 1.0f });
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
ImGui::PushFont(bold_font);
|
||||
if (ImGui::Button(labels[2], button_size))
|
||||
values.z = reset_value;
|
||||
ImGui::PopFont();
|
||||
ImGui::PopStyleColor(4);
|
||||
ImGui::PopStyleVar(1);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::DragFloat("##Z", &values.z, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::Columns(1);
|
||||
ImGui::PopID();
|
||||
}
|
||||
return transform;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "logging.hpp"
|
||||
#include <pch.hpp>
|
||||
|
||||
#include <scene/scene.hpp>
|
||||
#include <renderer/renderer2d.hpp>
|
||||
|
||||
#include <scene/entity.hpp>
|
||||
#include <scene/components.hpp>
|
||||
#include <scene/entity.hpp>
|
||||
#include <scene/scene.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
Entity Scene::CreateEntity(const std::string& name)
|
||||
@@ -49,7 +47,7 @@ namespace OpenEngine {
|
||||
|
||||
if (camera_component.primary) {
|
||||
main_camera = &camera_component.camera;
|
||||
main_transform = transform.GetTransform();
|
||||
main_transform = GetTransformFromComp(transform);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +59,7 @@ namespace OpenEngine {
|
||||
|
||||
for (const auto& entity : view) {
|
||||
auto [transform, sprite] = view.get<TransformComponent, SpriteRendererComponent>(entity);
|
||||
Renderer2D::DrawQuad(transform.GetTransform(), sprite.color, (int)entity);
|
||||
Renderer2D::DrawQuad(GetTransformFromComp(transform), sprite.color, (int)entity);
|
||||
}
|
||||
|
||||
Renderer2D::EndScene();
|
||||
@@ -78,7 +76,7 @@ namespace OpenEngine {
|
||||
{
|
||||
auto [transform, sprite] = group.get<TransformComponent, SpriteRendererComponent>(entity);
|
||||
|
||||
Renderer2D::DrawQuad(transform.GetTransform(), sprite.color, (int)entity);
|
||||
Renderer2D::DrawQuad(GetTransformFromComp(transform), sprite.color, (int)entity);
|
||||
}
|
||||
|
||||
Renderer2D::EndScene();
|
||||
|
||||
Reference in New Issue
Block a user