Skip to content

Commit

Permalink
ref: fix some more warnings from clang-tidy analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
viini42 committed Apr 21, 2024
1 parent 9a247c3 commit 7da0b95
Show file tree
Hide file tree
Showing 29 changed files with 251 additions and 256 deletions.
14 changes: 6 additions & 8 deletions Grapengine/controllers/ge_app_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using namespace GE;

GE::Ctrl::App::App() {}

void Ctrl::App::Init(const Ref<Application>& app)
{
Get().m_application = app;
Expand All @@ -18,17 +16,17 @@ void GE::Ctrl::App::Shutdown()

void GE::Ctrl::App::Close()
{
GE_ASSERT(Get().m_application.has_value(), "Controller not initialized")
GE_ASSERT(Get().m_application != nullptr, "Application destroyed")
const auto app = Get().m_application;
GE_ASSERT(app != nullptr, "Application destroyed")

Get().m_application.value()->Close();
app->Close();
}
void GE::Ctrl::App::AllowImGuiEvents(bool value)
{
GE_ASSERT(Get().m_application.has_value(), "Controller not initialized")
GE_ASSERT(Get().m_application != nullptr, "Application destroyed")
const auto app = Get().m_application;
GE_ASSERT(app != nullptr, "Application destroyed")

Get().m_application.value()->GetImGuiLayer()->AllowMouseAndKeyboardEvents(value);
app->GetImGuiLayer()->AllowMouseAndKeyboardEvents(value);
}

Ctrl::App& Ctrl::App::Get()
Expand Down
6 changes: 3 additions & 3 deletions Grapengine/controllers/ge_app_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ namespace GE::Ctrl
class App
{
public:
static void Init(const Ref<GE::Application>& app);
static void Init(const Ref<Application>& app);
static void Shutdown();

static void Close();

static void AllowImGuiEvents(bool value);

private:
App();
App() = default;

static App& Get();

std::optional<Ref<Application>> m_application = std::nullopt;
Ref<Application> m_application = nullptr;
};
}
#endif // GRAPENGINE_GE_APP_CONTROLLER_HPP
13 changes: 6 additions & 7 deletions Grapengine/core/ge_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

using namespace GE;

Application::Application(std::string_view title, u32 width, u32 height, std::string_view icon)
Application::Application(std::string_view title, Dimension dim, std::string_view icon)
{
GE_INFO("Application creation")

Init(title, width, height, icon, [this](auto&& e) { OnEvent(e); });
Init(title, dim, icon, [this](auto&& e) { OnEvent(e); });

Renderer::Init();
Renderer::SetViewport(0, 0, width, height);
Renderer::SetViewport(0, 0, dim);
}

Application::~Application()
Expand All @@ -30,12 +30,11 @@ Application::~Application()
}

void Application::Init(std::string_view title,
u32 width,
u32 height,
Dimension dim,
std::string_view icon,
const EventCallbackFn& cb)
{
m_window = MakeScope<Window>(WindowProps{ title, width, height, icon }, cb);
m_window = MakeScope<Window>(WindowProps{ title, dim, icon }, cb);
Input::Initialize(m_window);
m_imgui_layer = ImGuiLayer::Make(m_window);
m_imgui_layer->OnAttach();
Expand All @@ -57,7 +56,7 @@ void Application::Run()
{
while (m_running)
{
u64 time_ms = Platform::GetCurrentTimeMS();
const u64 time_ms = Platform::GetCurrentTimeMS();
TimeStep step{ time_ms - m_last_frame_time };
m_last_frame_time = time_ms;

Expand Down
9 changes: 3 additions & 6 deletions Grapengine/core/ge_application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace GE
class Application
{
public:
Application(std::string_view title, u32 width, u32 height, std::string_view icon);
Application(std::string_view title, Dimension dim, std::string_view icon);
virtual ~Application();

void AddLayer(const Ref<Layer>& layer);
Expand All @@ -32,11 +32,8 @@ namespace GE
[[nodiscard]] Ref<ImGuiLayer> GetImGuiLayer() const;

private:
void Init(std::string_view title,
u32 width,
u32 height,
std::string_view icon,
const EventCallbackFn& cb);
void
Init(std::string_view title, Dimension dim, std::string_view icon, const EventCallbackFn& cb);

void OnDestroy();

Expand Down
7 changes: 7 additions & 0 deletions Grapengine/core/ge_type_aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cstdint>
#include <memory>
#include <optional>

using i8 [[maybe_unused]] = std::int8_t;
using i16 [[maybe_unused]] = std::int16_t;
Expand All @@ -17,6 +18,12 @@ using f64 [[maybe_unused]] = double;

namespace GE
{
/**
* Pointer that acts as reference
*/
template <class T>
using Opt = std::optional<T>;

/**
* Pointer that acts as reference
*/
Expand Down
45 changes: 20 additions & 25 deletions Grapengine/core/ge_window.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "core/ge_window.hpp"

#include "core/ge_assert.hpp"
#include "drawables/ge_canvas.hpp"

#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <stb_image.h>

using namespace GE;
Expand All @@ -17,7 +15,8 @@ namespace
}
}

Window::Window(const WindowProps& props, const EventCallbackFn& cb) : m_window_props(props)
Window::Window(const WindowProps& props, const EventCallbackFn& cb) :
m_window_props(props), m_vsync(true)
{
// GE_INFO("Window creation")

Expand All @@ -29,8 +28,11 @@ Window::Window(const WindowProps& props, const EventCallbackFn& cb) : m_window_p
glfwSetErrorCallback(ErrorCB);

glfwWindowHint(GLFW_SAMPLES, 4);
m_window =
glfwCreateWindow(i32(props.width), i32(props.height), props.title.c_str(), nullptr, nullptr);
m_window = glfwCreateWindow(i32(props.dim.width),
i32(props.dim.height),
props.title.c_str(),
nullptr,
nullptr);
// glfwSetWindowAspectRatio(m_window,
// static_cast<i32>(props.width),
// static_cast<i32>(props.height));
Expand All @@ -42,8 +44,6 @@ Window::Window(const WindowProps& props, const EventCallbackFn& cb) : m_window_p

glfwSetWindowUserPointer(m_window, this);

m_canvas = MakeRef<Canvas>(props.width, props.height);

m_context = Context{ m_window };
m_context.Init();

Expand All @@ -63,19 +63,23 @@ Window::~Window()

u32 Window::GetWidth() const
{
return m_window_props.width;
return m_window_props.dim.width;
}

u32 Window::GetHeight() const
{
return m_window_props.height;
return m_window_props.dim.height;
}

void Window::SetVsync(bool enabled)
Dimension Window::GetDimension() const
{
glfwSwapInterval(enabled ? 1 : 0);
return m_window_props.dim;
}

// m_vsync = enabled;
void Window::SetVsync(bool enabled)
{
m_vsync = enabled;
glfwSwapInterval(m_vsync ? 1 : 0);
}

void Window::OnUpdate()
Expand All @@ -84,16 +88,6 @@ void Window::OnUpdate()
m_context.SwapBuffers();
}

void Window::Clear(Color color) const
{
m_canvas->Clear(color.ToVec4());
}

void Window::Draw(const Ref<Drawable>& drawable) const
{
m_canvas->Draw(drawable);
}

std::any Window::GetNativeHandler() const
{
return std::make_any<GLFWwindow*>(m_window);
Expand All @@ -115,18 +109,19 @@ void Window::SetupCallbacks(const EventCallbackFn& cb)
glfwSetWindowCloseCallback(m_window, close_callback);

//-----------------------------
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
auto resize_callback = [](GLFWwindow* win, i32 width, i32 height)
{
Event event{ EvType::WINDOW_RESIZE,
std::make_pair(static_cast<u32>(width), static_cast<u32>(height)) };
auto* data = static_cast<Window*>(glfwGetWindowUserPointer(win));
data->m_event_callback(event);
data->m_window_props.width = static_cast<u32>(width);
data->m_window_props.height = static_cast<u32>(height);
data->m_window_props.dim = Dimension{ u32(width), u32(height) };
};
glfwSetWindowSizeCallback(m_window, resize_callback);

//-----------------------------
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
auto key_callback = [](GLFWwindow* win, i32 key, i32 /*scancode*/, i32 action, i32 /*mods*/)
{
EvType type = EvType::NONE;
Expand All @@ -142,6 +137,7 @@ void Window::SetupCallbacks(const EventCallbackFn& cb)
glfwSetKeyCallback(m_window, key_callback);

//-----------------------------
// NOLINTNEXTLINE(*-easily-swappable-parameters)
auto mouse_bt_callback = [](GLFWwindow* win, i32 button, i32 action, i32 /*mods*/)
{
// if (ImGui::GetIO().WantCaptureMouse)
Expand Down Expand Up @@ -178,7 +174,6 @@ void Window::SetupCallbacks(const EventCallbackFn& cb)
};
glfwSetScrollCallback(m_window, mouse_scroll);
}

Ref<Window> Window::Make(const WindowProps& props, const EventCallbackFn& cb)
{
return MakeRef<Window>(props, cb);
Expand Down
18 changes: 7 additions & 11 deletions Grapengine/core/ge_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

#include "GLFW/glfw3.h"
#include "core/ge_macros.hpp"
#include "drawables/ge_canvas.hpp"
#include "drawables/ge_color.hpp"
#include "events/ge_event.hpp"
#include "ge_context.hpp"
#include "log/ge_logger.hpp"
#include "math/ge_vector.hpp"
#include "utils/ge_dimension.hpp"

#include <any>
#include <functional>
Expand All @@ -24,11 +24,10 @@ namespace GE
{
std::string title;
std::string icon_path;
u32 width;
u32 height;
Dimension dim;

explicit WindowProps(std::string_view titleStr, u32 w, u32 h, std::string_view icon) :
title(titleStr), icon_path(icon), width(w), height(h)
explicit WindowProps(std::string_view titleStr, Dimension d, std::string_view icon) :
title(titleStr), icon_path(icon), dim(d)
{
}
};
Expand All @@ -41,16 +40,14 @@ namespace GE
explicit Window(const WindowProps& props, const EventCallbackFn& cb);
~Window();

[[nodiscard]] u32 GetWidth() const;
[[nodiscard]] u32 GetHeight() const;
[[deprecated("Use GetDimension")]] [[nodiscard]] u32 GetWidth() const;
[[deprecated("Use GetDimension")]] [[nodiscard]] u32 GetHeight() const;
[[nodiscard]] Dimension GetDimension() const;

void SetVsync(bool enabled);

void OnUpdate();

void Clear(Color color) const;
void Draw(const Ref<Drawable>& drawable) const;

[[nodiscard]] std::any GetNativeHandler() const;

private:
Expand All @@ -61,7 +58,6 @@ namespace GE
GLFWwindow* m_window;
Context m_context;
EventCallbackFn m_event_callback;
Ref<Canvas> m_canvas;
};
}

Expand Down
19 changes: 0 additions & 19 deletions Grapengine/drawables/ge_canvas.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions Grapengine/drawables/ge_canvas.hpp

This file was deleted.

Loading

0 comments on commit 7da0b95

Please sign in to comment.