fix: clang-tidy checks for mirror

This commit is contained in:
light7734 2025-07-06 15:10:34 +03:30
parent 31880d7291
commit 2e05d871eb
Signed by: light7734
GPG key ID: 8C30176798F1A6BA
8 changed files with 217 additions and 126 deletions

View file

@ -13,9 +13,17 @@ class EditorLayer: public Layer
public:
EditorLayer(const std::string &name);
~EditorLayer();
~EditorLayer() override;
void on_update(float deltaTime) override;
EditorLayer(EditorLayer &&) = delete;
EditorLayer(const EditorLayer &) = delete;
auto operator=(EditorLayer &&) const -> EditorLayer & = delete;
auto operator=(const EditorLayer &) const -> EditorLayer & = delete;
void on_update(float delta_time) override;
void on_render() override;
@ -24,7 +32,6 @@ public:
private:
std::string m_scene_dir;
// #todo: add camera controller class to the engine
glm::vec2 m_direction;
float m_speed = 1000.0f;

View file

@ -27,9 +27,9 @@ private:
const std::filesystem::path m_assets_path;
uint32_t m_file_size = 128u;
float m_file_size = 128.0f;
uint32_t m_file_padding = 8u;
float m_file_padding = 8.0f;
Ref<Scene> m_active_scene;

View file

@ -10,18 +10,16 @@ class PropertiesPanel: public Panel
public:
PropertiesPanel() = default;
~PropertiesPanel() = default;
void on_user_interface_update();
void set_entity_context(Entity entity);
void set_entity_context(const Entity &entity);
private:
void draw_vec3_control(
const std::string &label,
glm::vec3 &values,
float resetValue = 0.0f,
float columnWidth = 100.0f
float reset_value = 0.0f,
float column_width = 100.0f
);
template<typename ComponentType, typename UIFunction>

View file

@ -3,7 +3,10 @@
namespace Light {
EditorLayer::EditorLayer(const std::string &name): Layer(name), m_scene_dir("")
EditorLayer::EditorLayer(const std::string &name)
: Layer(name)
, m_scene_dir("")
, m_direction { 0.0, 0.0 }
{
m_scene = create_ref<Scene>();
@ -11,7 +14,14 @@ EditorLayer::EditorLayer(const std::string &name): Layer(name), m_scene_dir("")
m_sceneHierarchyPanel = create_ref<SceneHierarchyPanel>(m_scene, m_properties_panel);
m_content_browser_panel = create_ref<AssetBrowserPanel>(m_scene);
m_framebuffer = Framebuffer::create({ 1, 1, 1 }, GraphicsContext::get_shared_context());
m_framebuffer = Framebuffer::create(
{
.width = 1,
.height = 1,
.samples = 1,
},
GraphicsContext::get_shared_context()
);
if (m_scene_dir.empty())
{
@ -44,23 +54,43 @@ EditorLayer::~EditorLayer()
}
}
void EditorLayer::on_update(float deltaTime)
void EditorLayer::on_update(float delta_time)
{
m_scene->on_update(deltaTime);
m_scene->on_update(delta_time);
m_direction.x = Input::get_keyboard_key(Key::A) ? -1.0f :
Input::get_keyboard_key(Key::D) ? 1.0f :
0.0f;
if (Input::get_keyboard_key(Key::A))
{
m_direction.x = -1.0;
}
else if (Input::get_keyboard_key(Key::D))
{
m_direction.x = 1.0f;
}
else
{
m_direction.x = 0.0;
}
m_direction.y = Input::get_keyboard_key(Key::S) ? -1.0f :
Input::get_keyboard_key(Key::W) ? 1.0f :
0.0f;
if (Input::get_keyboard_key(Key::S))
{
m_direction.y = -1.0;
}
else if (Input::get_keyboard_key(Key::W))
{
m_direction.y = 1.0f;
}
else
{
m_direction.y = 0.0;
}
auto &cameraTranslation = m_camera_entity.get_component<TransformComponent>().translation;
cameraTranslation += glm::vec3(m_direction * m_speed * deltaTime, 0.0f);
auto &translation = m_camera_entity.get_component<TransformComponent>().translation;
translation += glm::vec3 { m_direction * m_speed * delta_time, 0.0f };
if (Input::get_keyboard_key(Key::Escape))
{
Application::quit();
}
}
void EditorLayer::on_render()
@ -76,26 +106,33 @@ void EditorLayer::on_user_interface_update()
if (ImGui::Begin("Game"))
{
Input::receive_game_events(ImGui::IsWindowFocused());
auto regionAvail = ImGui::GetContentRegionAvail();
auto available_region = ImGui::GetContentRegionAvail();
if (m_available_content_region_prev != regionAvail)
if (m_available_content_region_prev != available_region)
{
m_framebuffer->resize({ regionAvail.x, regionAvail.y });
m_framebuffer->resize({ available_region.x, available_region.y });
auto &camera = m_camera_entity.get_component<CameraComponent>().camera;
camera.set_viewport_size(regionAvail.x, regionAvail.y);
camera.set_viewport_size(
static_cast<uint32_t>(available_region.x),
static_cast<uint32_t>(available_region.y)
);
m_available_content_region_prev = regionAvail;
m_available_content_region_prev = available_region;
}
if (GraphicsContext::get_graphics_api() == GraphicsAPI::DirectX)
ImGui::Image(m_framebuffer->get_color_attachment(), regionAvail);
{
ImGui::Image(m_framebuffer->get_color_attachment(), available_region);
}
else
{
ImGui::Image(
m_framebuffer->get_color_attachment(),
regionAvail,
available_region,
ImVec2(0, 1),
ImVec2(1, 0)
);
}
}
ImGui::End();

View file

@ -27,9 +27,9 @@ public:
}
};
auto create_application() -> Application *
auto create_application() -> Light::Scope<Application>
{
return new Mirror();
return Light::create_scope<Mirror>();
}
} // namespace Light

View file

@ -34,37 +34,47 @@ void AssetBrowserPanel::on_user_interface_update()
}
}
auto regionAvail = ImGui::GetContentRegionAvail();
auto cellSize = m_file_size + m_file_padding;
auto columnCount = std::clamp(
static_cast<uint32_t>(std::floor(regionAvail.x / cellSize)),
const auto available_region = ImGui::GetContentRegionAvail();
const auto cell_size = m_file_size + m_file_padding;
const auto column_count = std::clamp(
static_cast<uint32_t>(std::floor(available_region.x / cell_size)),
1u,
64u
);
if (ImGui::BeginTable("ContentBrowser", columnCount))
if (ImGui::BeginTable("ContentBrowser", static_cast<int>(column_count)))
{
m_directory_texture->bind(0u);
for (const auto &dirEntry : std::filesystem::directory_iterator(m_current_directory))
for (const auto &directory_entry : std::filesystem::directory_iterator(m_current_directory))
{
const auto &path = dirEntry.path();
auto extension = dirEntry.path().extension().string();
const auto &path = directory_entry.path();
auto extension = directory_entry.path().extension().string();
// TODO: Tidy up
auto assetType = AssetType {};
assetType = extension.empty() ? AssetType::directory :
auto asset_type = AssetType {};
extension == ".txt" ? AssetType::text :
extension == ".glsl" ? AssetType::text :
extension == ".png" ? AssetType::image :
extension == ".scene" ? AssetType::scene :
AssetType::none;
if (extension.empty())
{
asset_type = AssetType::directory;
}
else if (extension == ".txt" || extension == ".glsl")
{
asset_type = AssetType::text;
}
else if (extension == ".png")
{
asset_type = AssetType::image;
}
else if (extension == ".scene")
{
asset_type = AssetType::scene;
}
else
{
asset_type = AssetType::none;
}
// Extension not supported
if (assetType == AssetType::none)
if (asset_type == AssetType::none)
{
continue;
}
@ -72,7 +82,7 @@ void AssetBrowserPanel::on_user_interface_update()
// Button
ImGui::TableNextColumn();
ImGui::PushID(path.c_str());
switch (assetType)
switch (asset_type)
{
// Directory
case AssetType::directory:
@ -142,7 +152,7 @@ void AssetBrowserPanel::on_user_interface_update()
default: break;
}
// Label
ImGui::Text("%s", path.filename().c_str());
ImGui::TextUnformatted(fmt::format("{}", path.filename().string()).c_str());
ImGui::PopID();
}

View file

@ -32,7 +32,9 @@ void PropertiesPanel::on_user_interface_update()
ImGui::PushItemWidth(-1);
if (ImGui::Button("Add component"))
{
ImGui::OpenPopup("Components");
}
if (ImGui::BeginPopup("Components"))
{
@ -41,20 +43,24 @@ void PropertiesPanel::on_user_interface_update()
false,
m_entity_context.has_component<SpriteRendererComponent>() ?
ImGuiSelectableFlags_Disabled :
NULL
ImGuiSelectableFlags {}
))
{
m_entity_context.add_component<SpriteRendererComponent>(
Light::ResourceManager::get_texture("awesomeface")
);
}
if (ImGui::Selectable(
"Camera",
false,
m_entity_context.has_component<CameraComponent>() ?
ImGuiSelectableFlags_Disabled :
NULL
ImGuiSelectableFlags {}
))
{
m_entity_context.add_component<CameraComponent>();
}
ImGui::EndPopup();
}
@ -82,68 +88,82 @@ void PropertiesPanel::on_user_interface_update()
[&](auto &cameraComponent) {
auto &camera = cameraComponent.camera;
auto projectionType = camera.get_projection_type();
auto projectionTypesString = std::array<const char *, 2> {
auto projection_type = camera.get_projection_type();
auto projection_types_str = std::array<const char *, 2> {
"Orthographic",
"Perspective",
};
if (ImGui::BeginCombo("ProjectionType", projectionTypesString[(int)projectionType]))
if (ImGui::BeginCombo("ProjectionType", projection_types_str[(int)projection_type]))
{
for (int i = 0; i < 2; i++)
for (auto idx = 0; idx < 2; idx++)
{
const auto isSelected = (int)projectionType == i;
if (ImGui::Selectable(projectionTypesString[i], isSelected))
const auto is_selected = static_cast<int>(projection_type) == idx;
if (ImGui::Selectable(projection_types_str[idx], is_selected))
{
projectionType = (SceneCamera::ProjectionType)i;
camera.set_projection_type(projectionType);
projection_type = static_cast<SceneCamera::ProjectionType>(idx);
camera.set_projection_type(projection_type);
}
if (isSelected)
if (is_selected)
{
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
if (projectionType == SceneCamera::ProjectionType::Orthographic)
if (projection_type == SceneCamera::ProjectionType::Orthographic)
{
auto orthoSize = float {};
auto nearPlane = float {};
auto farPlane = float {};
auto ortho_size = float {};
auto near_plane = float {};
auto far_plane = float {};
orthoSize = camera.get_orthographic_size();
nearPlane = camera.get_orthographic_near_plane();
farPlane = camera.get_orthographic_far_plane();
ortho_size = camera.get_orthographic_size();
near_plane = camera.get_orthographic_near_plane();
far_plane = camera.get_orthographic_far_plane();
if (ImGui::DragFloat("Orthographic Size", &orthoSize))
camera.set_orthographic_size(orthoSize);
if (ImGui::DragFloat("Orthographic Size", &ortho_size))
{
camera.set_orthographic_size(ortho_size);
}
if (ImGui::DragFloat("Near Plane", &nearPlane))
camera.set_orthographic_near_plane(nearPlane);
if (ImGui::DragFloat("Near Plane", &near_plane))
{
camera.set_orthographic_near_plane(near_plane);
}
if (ImGui::DragFloat("Far Plane", &farPlane))
camera.set_orthographic_far_plane(farPlane);
if (ImGui::DragFloat("Far Plane", &far_plane))
{
camera.set_orthographic_far_plane(far_plane);
}
}
else // perspective
{
auto verticalFOV = float {};
auto nearPlane = float {};
auto farPlane = float {};
auto vertical_fov = float {};
auto near_plane = float {};
auto far_plane = float {};
verticalFOV = glm::degrees(camera.get_perspective_vertical_fov());
nearPlane = camera.get_perspective_near_plane();
farPlane = camera.get_perspective_far_plane();
vertical_fov = glm::degrees(camera.get_perspective_vertical_fov());
near_plane = camera.get_perspective_near_plane();
far_plane = camera.get_perspective_far_plane();
if (ImGui::DragFloat("Vertical FOV", &verticalFOV))
camera.set_perspective_vertical_fov(glm::radians(verticalFOV));
if (ImGui::DragFloat("Vertical FOV", &vertical_fov))
{
camera.set_perspective_vertical_fov(glm::radians(vertical_fov));
}
if (ImGui::DragFloat("Near Plane", &nearPlane))
camera.set_perspective_near_plane(nearPlane);
if (ImGui::DragFloat("Near Plane", &near_plane))
{
camera.set_perspective_near_plane(near_plane);
}
if (ImGui::DragFloat("Far Plane", &farPlane))
camera.set_perspective_far_plane(farPlane);
if (ImGui::DragFloat("Far Plane", &far_plane))
{
camera.set_perspective_far_plane(far_plane);
}
}
ImGui::Separator();
@ -154,7 +174,7 @@ void PropertiesPanel::on_user_interface_update()
ImGui::End();
}
void PropertiesPanel::set_entity_context(Entity entity)
void PropertiesPanel::set_entity_context(const Entity &entity)
{
m_entity_context = entity;
}
@ -162,31 +182,33 @@ void PropertiesPanel::set_entity_context(Entity entity)
void PropertiesPanel::draw_vec3_control(
const std::string &label,
glm::vec3 &values,
float resetValue /*= 0.0f*/,
float columnWidth /*= 100.0f*/
float reset_value,
float column_width
)
{
auto &io = ImGui::GetIO();
auto boldFont = io.Fonts->Fonts[0];
auto *bold_font = io.Fonts->Fonts[0];
ImGui::Columns(2);
ImGui::SetColumnWidth(0, columnWidth);
ImGui::Text(label.c_str());
ImGui::SetColumnWidth(0, column_width);
ImGui::TextUnformatted(label.c_str());
ImGui::NextColumn();
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2 { 0, 0 });
auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
auto buttonSize = ImVec2 { lineHeight + 3.0f, lineHeight };
auto line_height = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
auto button_size = ImVec2 { line_height + 3.0f, line_height };
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.1f, 0.15f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.9f, 0.2f, 0.2f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.8f, 0.1f, 0.15f, 1.0f));
ImGui::PushFont(boldFont);
if (ImGui::Button("X", buttonSize))
values.x = resetValue;
ImGui::PushFont(bold_font);
if (ImGui::Button("X", button_size))
{
values.x = reset_value;
}
ImGui::PopFont();
ImGui::PopStyleColor(3);
@ -198,9 +220,11 @@ void PropertiesPanel::draw_vec3_control(
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.7f, 0.2f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.3f, 0.8f, 0.3f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.2f, 0.7f, 0.2f, 1.0f));
ImGui::PushFont(boldFont);
if (ImGui::Button("Y", buttonSize))
values.y = resetValue;
ImGui::PushFont(bold_font);
if (ImGui::Button("Y", button_size))
{
values.y = reset_value;
}
ImGui::PopFont();
ImGui::PopStyleColor(3);
@ -213,9 +237,11 @@ void PropertiesPanel::draw_vec3_control(
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.1f, 0.25f, 0.8f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.35f, 0.9f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.25f, 0.8f, 1.0f));
ImGui::PushFont(boldFont);
if (ImGui::Button("Z", buttonSize))
values.z = resetValue;
ImGui::PushFont(bold_font);
if (ImGui::Button("Z", button_size))
{
values.z = reset_value;
}
ImGui::PopFont();
ImGui::PopStyleColor(3);
@ -232,16 +258,19 @@ template<typename ComponentType, typename UIFunction>
void PropertiesPanel::draw_component(
const std::string &name,
Entity entity,
UIFunction userInterfaceFunction
UIFunction user_interface_function
)
{
if (!entity.has_component<ComponentType>())
{
return;
}
auto &component = entity.get_component<ComponentType>();
auto regionAvail = ImGui::GetContentRegionAvail();
auto available_region = ImGui::GetContentRegionAvail();
// NOLINTNEXTLINE
auto flags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth
| ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_AllowItemOverlap
| ImGuiTreeNodeFlags_FramePadding;
@ -250,27 +279,34 @@ void PropertiesPanel::draw_component(
auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
ImGui::Separator();
// NOLINTNEXTLINE
if (ImGui::TreeNodeEx((void *)typeid(ComponentType).hash_code(), flags, name.c_str()))
{
ImGui::PopStyleVar();
ImGui::SameLine(regionAvail.x - lineHeight * .5f);
ImGui::SameLine(available_region.x - lineHeight * .5f);
if (ImGui::Button("+", { lineHeight, lineHeight }))
{
ImGui::OpenPopup("ComponentSettings");
}
if (ImGui::BeginPopup("ComponentSettings"))
{
if (ImGui::Selectable("Remove component"))
{
entity.remove_component<ComponentType>();
}
ImGui::EndPopup();
}
userInterfaceFunction(component);
user_interface_function(component);
ImGui::TreePop();
}
else
{
ImGui::PopStyleVar();
}
}
} // namespace Light

View file

@ -6,17 +6,13 @@
namespace Light {
SceneHierarchyPanel::SceneHierarchyPanel()
: m_context(nullptr)
, m_properties_panel_context(nullptr)
, m_selection_context()
SceneHierarchyPanel::SceneHierarchyPanel(): m_context(nullptr), m_properties_panel_context(nullptr)
{
}
SceneHierarchyPanel::
SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
: m_context(context)
, m_properties_panel_context(propertiesPanel)
SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> properties_panel)
: m_context(std::move(context))
, m_properties_panel_context(std::move(properties_panel))
{
}
@ -41,22 +37,29 @@ void SceneHierarchyPanel::on_user_interface_update()
ImGui::End();
}
void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel)
void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> properties_panel)
{
if (propertiesPanel)
m_properties_panel_context = propertiesPanel;
if (properties_panel)
{
m_properties_panel_context = std::move(properties_panel);
}
m_context = context;
m_context = std::move(context);
}
void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
{
auto flags = (m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : NULL)
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
auto flags = ImGuiTreeNodeFlags {
// NOLINTNEXTLINE
(m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : ImGuiTreeNodeFlags {})
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth
};
// NOLINTNEXTLINE
const auto expanded = ImGui::TreeNodeEx(
(void *)(uint64_t)(uint32_t)(entity),
std::bit_cast<void *>(static_cast<uint64_t>(entity)),
flags,
"%s",
label.c_str()
);
@ -68,7 +71,7 @@ void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
if (expanded)
{
ImGui::Text("TEST_OPENED_TREE!");
ImGui::TextUnformatted("TEST_OPENED_TREE!");
ImGui::TreePop();
}
}