From d40fa774c1c0d5aa2b4fcdde9df37977b5d589a1 Mon Sep 17 00:00:00 2001 From: anulax1225 Date: Mon, 17 Jun 2024 23:34:10 +0200 Subject: [PATCH] Cleaned up project and ajusted window interface --- premake5.lua | 10 ++- src/bakara.h | 2 - src/bakara/core/application.h | 4 +- src/bakara/core/entry.cpp | 2 +- src/bakara/core/layer.h | 2 +- src/bakara/core/layer_stack.h | 2 +- src/bakara/{io => core}/window.h | 6 +- src/bakara/events/event.h | 2 +- src/bakara/events/window_event.h | 1 - src/bakara/math/mathpch.h | 8 --- src/bakara/math/type.h | 3 +- src/bakara/tools/string_fmt.h | 65 ------------------- src/bakarapch.cpp | 1 + src/{bkpch.h => bakarapch.h} | 2 +- .../glfw/glfw_window.cpp | 0 .../glfw/glfw_window.h | 11 +++- 16 files changed, 28 insertions(+), 93 deletions(-) rename src/bakara/{io => core}/window.h (95%) delete mode 100644 src/bakara/math/mathpch.h delete mode 100644 src/bakara/tools/string_fmt.h create mode 100644 src/bakarapch.cpp rename src/{bkpch.h => bakarapch.h} (91%) rename src/{plaforms => platforms}/glfw/glfw_window.cpp (100%) rename src/{plaforms => platforms}/glfw/glfw_window.h (79%) diff --git a/premake5.lua b/premake5.lua index 4a1ceac..d4c8b2d 100644 --- a/premake5.lua +++ b/premake5.lua @@ -6,6 +6,9 @@ project "bakara" targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") + pchheader "bakarapch.h" + pchsource "bakarapch.cpp" + files { "%{wks.location}/vendor/glm/glm/**.hpp", @@ -13,8 +16,11 @@ project "bakara" "%{wks.location}/vendor/imgui/misc/cpp/imgui_stdlib.cpp", "%{wks.location}/vendor/imgui/backends/imgui_impl_opengl3.cpp", "%{wks.location}/vendor/imgui/backends/imgui_impl_glfw.cpp", - "src/**.h", - "src/**.cpp", + "src/bakara/**.h", + "src/bakara/**.cpp", + "src/platforms/**.h", + "src/platforms/**.cpp", + "src/*pch.*", } defines diff --git a/src/bakara.h b/src/bakara.h index 3b96af3..d408bd1 100644 --- a/src/bakara.h +++ b/src/bakara.h @@ -14,8 +14,6 @@ Plaform namespace doc */ namespace Bk::Plaform {} -#define BKMOD_ALL -#include #include #include diff --git a/src/bakara/core/application.h b/src/bakara/core/application.h index 59f8705..c6e23c7 100644 --- a/src/bakara/core/application.h +++ b/src/bakara/core/application.h @@ -4,8 +4,8 @@ This file contains the main app abstraction. */ -#include -#include +#include +#include #include #include diff --git a/src/bakara/core/entry.cpp b/src/bakara/core/entry.cpp index 9faa324..0957b69 100644 --- a/src/bakara/core/entry.cpp +++ b/src/bakara/core/entry.cpp @@ -1,4 +1,4 @@ -#include +#include #include "application.h" /*! \file entry.cpp diff --git a/src/bakara/core/layer.h b/src/bakara/core/layer.h index eeb3453..b6202cc 100644 --- a/src/bakara/core/layer.h +++ b/src/bakara/core/layer.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include namespace Bk { diff --git a/src/bakara/core/layer_stack.h b/src/bakara/core/layer_stack.h index 3b0801e..e2b6948 100644 --- a/src/bakara/core/layer_stack.h +++ b/src/bakara/core/layer_stack.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "layer.h" namespace Bk { diff --git a/src/bakara/io/window.h b/src/bakara/core/window.h similarity index 95% rename from src/bakara/io/window.h rename to src/bakara/core/window.h index a1ec832..f29318f 100644 --- a/src/bakara/io/window.h +++ b/src/bakara/core/window.h @@ -5,7 +5,7 @@ This file contiens all the interfaces to create a window. Implementation possible with GLFW, Win32, etc. */ -#include +#include #include namespace Bk { @@ -89,7 +89,7 @@ namespace Bk { Indicates if the window is opened @return Open flag */ - bool is_open() { return h_is_open; } + virtual bool is_open() = 0; virtual void* get_native_window() = 0; @@ -99,7 +99,5 @@ namespace Bk { @param props : Window information */ static Window* create_window(const WindowProps& props = WindowProps()); - protected: - bool h_is_open; //!< indicaste if the window is opened or not }; } \ No newline at end of file diff --git a/src/bakara/events/event.h b/src/bakara/events/event.h index f925970..8ce826c 100644 --- a/src/bakara/events/event.h +++ b/src/bakara/events/event.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace Bk { enum class EventType diff --git a/src/bakara/events/window_event.h b/src/bakara/events/window_event.h index d44b8ac..ee6d702 100644 --- a/src/bakara/events/window_event.h +++ b/src/bakara/events/window_event.h @@ -1,6 +1,5 @@ #pragma once -#include #include "event.h" namespace Bk { diff --git a/src/bakara/math/mathpch.h b/src/bakara/math/mathpch.h deleted file mode 100644 index 5982144..0000000 --- a/src/bakara/math/mathpch.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -/*! \file mathpch.h -Precompiled headers communly used in math functionnalitys. -*/ - -#include -#include \ No newline at end of file diff --git a/src/bakara/math/type.h b/src/bakara/math/type.h index c6a4ae7..a78b8fa 100644 --- a/src/bakara/math/type.h +++ b/src/bakara/math/type.h @@ -5,7 +5,8 @@ Math types alias file used to abstract math types and not depend on any library. As long as it's implemented here. */ -#include +#include +#include namespace Bk { diff --git a/src/bakara/tools/string_fmt.h b/src/bakara/tools/string_fmt.h deleted file mode 100644 index 4eb14d1..0000000 --- a/src/bakara/tools/string_fmt.h +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -/*! \file string_fmt.h -This file provides functions to do string formatting. -*/ - -#include -#include -#include - -namespace Bk::Tools { - - inline void format_impl(std::stringstream& ss, const char* format) { - while (*format) { - if (*format == '%' && *++format != '%') // %% == % (not a format directive) - throw std::invalid_argument("not enough arguments !\n"); - ss << *format++; - } - } - - template - void format_impl(std::stringstream& ss, const char* format, Arg arg, Args... args) { - while (*format) { - if (*format == '%' && *++format != '%') { - auto current_format_qualifier = *format; - switch(current_format_qualifier) { - case 'd' : - if (!std::is_integral()) throw std::invalid_argument("%d introduces integral argument"); - break; - case 'f' : - if (!std::is_floating_point()) throw std::invalid_argument("%f introduces floating point argument"); - break; - case 'b' : - if(arg) ss << "true"; - else ss << "false"; - return format_impl(ss, ++format, args...); - case 's' : - break; - // etc. - default: - throw std::invalid_argument("Not a standard format"); - break; - } - // it's true you'd have to handle many more format qualifiers, but on a safer basis - ss << arg; // arg type is deduced - return format_impl(ss, ++format, args...); // one arg less - } - ss << *format++; - } // the format string is exhausted and we still have args : throw - throw std::invalid_argument("Too many arguments\n"); - } - /*! \fn std::string Bk::Tools::format(const char* fmt, Args... args) - Formats a string, printf like. Accepts integers, floating point numbers, strings, booléen. - @param fmt : string to format - @param args : variable arguments to put in the string - @return String formatted - */ - template - inline std::string format(const char* fmt, Args... args) { - std::stringstream ss; - format_impl(ss, fmt, args...); - return ss.str(); - } -} - diff --git a/src/bakarapch.cpp b/src/bakarapch.cpp new file mode 100644 index 0000000..6c81d8d --- /dev/null +++ b/src/bakarapch.cpp @@ -0,0 +1 @@ +#include "bakarapch.h" \ No newline at end of file diff --git a/src/bkpch.h b/src/bakarapch.h similarity index 91% rename from src/bkpch.h rename to src/bakarapch.h index 659f1bf..050f41a 100644 --- a/src/bkpch.h +++ b/src/bakarapch.h @@ -17,4 +17,4 @@ Precompiled headers communly used in bakara. #include #include -#include +#include \ No newline at end of file diff --git a/src/plaforms/glfw/glfw_window.cpp b/src/platforms/glfw/glfw_window.cpp similarity index 100% rename from src/plaforms/glfw/glfw_window.cpp rename to src/platforms/glfw/glfw_window.cpp diff --git a/src/plaforms/glfw/glfw_window.h b/src/platforms/glfw/glfw_window.h similarity index 79% rename from src/plaforms/glfw/glfw_window.h rename to src/platforms/glfw/glfw_window.h index dc851d3..66d2e87 100644 --- a/src/plaforms/glfw/glfw_window.h +++ b/src/platforms/glfw/glfw_window.h @@ -1,6 +1,6 @@ #pragma once -#include -#include +#include +#include #include #include #include @@ -25,8 +25,13 @@ namespace Bk::Plaform { void open() override; void* get_native_window() override { return p_window; } - + /*! \fn Bk::Window::is_open + Indicates if the window is opened + @return Open flag + */ + bool is_open() override { return h_is_open; } private: + bool h_is_open; //!< indicaste if the window is opened or not GLFWwindow* p_window; bool p_shutdown;