Compare commits

..

No commits in common. "2e05d871ebebe53a40900fe8eb065e2a845095e1" and "77d1619b1cd043ed8c65bfd9c8f274bf1ca49566" have entirely different histories.

9 changed files with 127 additions and 217 deletions

View file

@ -129,6 +129,7 @@ cppcoreguidelines-pro-type-cstyle-cast,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-pro-type-reinterpret-cast,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-pro-type-union-access,
cppcoreguidelines-pro-type-vararg,
cppcoreguidelines-rvalue-reference-param-not-moved,
cppcoreguidelines-slicing,

View file

@ -13,17 +13,9 @@ class EditorLayer: public Layer
public:
EditorLayer(const std::string &name);
~EditorLayer() override;
~EditorLayer();
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_update(float deltaTime) override;
void on_render() override;
@ -32,6 +24,7 @@ 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;
float m_file_size = 128.0f;
uint32_t m_file_size = 128u;
float m_file_padding = 8.0f;
uint32_t m_file_padding = 8u;
Ref<Scene> m_active_scene;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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