Kajetan Johannes Hammerle 4 giorni fa
parent
commit
fb8c63f328

+ 6 - 37
CMakeLists.txt

@@ -44,6 +44,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
     include("cmake/clang_warnings.cmake")
 endif()
+include("${CMAKE_INSTALL_PREFIX}/cmake/add_modules.cmake")
 
 add_library(gamingcore STATIC ${SRC})
 target_compile_options(gamingcore PUBLIC
@@ -63,43 +64,11 @@ target_include_directories(gamingcore SYSTEM
     PUBLIC stb
     PUBLIC glfw/include
 )
-target_sources(gamingcore PUBLIC
-    FILE_SET CXX_MODULES
-    BASE_DIRS ${CMAKE_INSTALL_PREFIX}/modules
-    FILES
-        "${CMAKE_INSTALL_PREFIX}/modules/Array.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/AlignedData.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/ArrayList.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/BitArray.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Box.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Buffer.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Clock.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Color.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Components.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/File.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Frustum.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/HashMap.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/HashedString.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/List.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Logger.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Math.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Matrix.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Meta.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Plane.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Quaternion.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Queue.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Random.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/ReadLine.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Terminal.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Test.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Thread.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/ToString.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Types.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Unicode.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/UniquePointer.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Utility.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/Vector.cppm"
-        "${CMAKE_INSTALL_PREFIX}/modules/View.cppm"
+add_modules(
+    TARGET gamingcore
+    NAME core_modules
+    PREFIX ${CMAKE_INSTALL_PREFIX}/
+    FILES ${core_modules}
 )
 target_link_directories(gamingcore
     PUBLIC ${CMAKE_INSTALL_PREFIX}/lib

+ 16 - 13
include/core/VulkanWrapper.hpp

@@ -19,55 +19,58 @@ namespace Core::Vulkan {
         VkDevice device = VK_NULL_HANDLE;
         T handle = VK_NULL_HANDLE;
 
-        BaseWrapper() = default;
+        BaseWrapper() noexcept = default;
         BaseWrapper(const BaseWrapper&) = delete;
 
-        BaseWrapper(BaseWrapper&& o) : BaseWrapper() {
+        BaseWrapper(BaseWrapper&& o) noexcept : BaseWrapper() {
             swap(o);
         }
 
         BaseWrapper& operator=(const BaseWrapper&) = delete;
 
-        BaseWrapper& operator=(BaseWrapper&& o) {
+        BaseWrapper& operator=(BaseWrapper&& o) noexcept {
             swap(o);
             return *this;
         }
 
-        void swap(BaseWrapper& o) {
+        void swap(BaseWrapper& o) noexcept {
             Core::swap(device, o.device);
             Core::swap(handle, o.handle);
         }
 
-        operator T() {
+        operator T() noexcept {
             return handle;
         }
 
-        operator T*() {
+        operator T*() noexcept {
             return &handle;
         }
 
-        operator const T*() const {
+        operator const T*() const noexcept {
             return &handle;
         }
     };
 
     struct ImageView : public BaseWrapper<VkImageView> {
-        ImageView() = default;
-        ImageView(ImageView&&) = default;
+        ImageView() noexcept = default;
+        ImageView(ImageView&&) noexcept = default;
+        ImageView& operator=(ImageView&&) noexcept = default;
         ~ImageView();
         bool init(VkDevice d, VkImage image, VkFormat format);
     };
 
     struct Framebuffer : public BaseWrapper<VkFramebuffer> {
-        Framebuffer() = default;
-        Framebuffer(Framebuffer&&) = default;
+        Framebuffer() noexcept = default;
+        Framebuffer(Framebuffer&&) noexcept = default;
+        Framebuffer& operator=(Framebuffer&&) noexcept = default;
         ~Framebuffer();
         bool init(const ImageView& iv, VkRenderPass rp, u32 width, u32 height);
     };
 
     struct Semaphore : public BaseWrapper<VkSemaphore> {
-        Semaphore() = default;
-        Semaphore(Semaphore&&) = default;
+        Semaphore() noexcept = default;
+        Semaphore(Semaphore&&) noexcept = default;
+        Semaphore& operator=(Semaphore&&) noexcept = default;
         ~Semaphore();
         bool init(VkDevice d);
     };

+ 1 - 1
src/Image.cpp

@@ -21,7 +21,7 @@ import Core.Utility;
 
 static void reportError(const char* path) {
     Core::report(
-        Core::LogLevel::ERROR, "Cannot read image '#': #", path,
+        Core::LogLevel::ERROR, "Cannot read image '{}': {}", path,
         strerror(errno));
 }
 

+ 2 - 2
src/VulkanBase.cpp

@@ -65,7 +65,7 @@ bool Base::initInstance() {
 static VKAPI_ATTR VkBool32 onVulkanDebugMessenger VKAPI_CALL(
     VkDebugUtilsMessageSeverityFlagBitsEXT, VkDebugUtilsMessageTypeFlagsEXT,
     const VkDebugUtilsMessengerCallbackDataEXT* data, void*) {
-    VK_REPORT_WARNING("Vulkan validation layer message: #", data->pMessage);
+    VK_REPORT_WARNING("Vulkan validation layer message: {}", data->pMessage);
     return false;
 }
 
@@ -90,7 +90,7 @@ bool Base::initDebugMessenger() {
 static VKAPI_ATTR VkBool32 onVulkanDebugReport VKAPI_CALL(
     VkDebugReportFlagsEXT, VkDebugReportObjectTypeEXT, uint64_t, size_t,
     int32_t, const char* pLayerPrefix, const char* pMessage, void*) {
-    VK_REPORT_WARNING("Vulkan debug message '#': #", pLayerPrefix, pMessage);
+    VK_REPORT_WARNING("Vulkan debug message '{}': {}", pLayerPrefix, pMessage);
     return false;
 }
 

+ 7 - 7
src/VulkanWrapper.cpp

@@ -589,7 +589,7 @@ struct VulkanDummy {
         if(c.currentExtent.width != 0xFFFF'FFFFu &&
            c.currentExtent.height != 0xFFFF'FFFFu) {
             *size = c.currentExtent;
-            Core::logInfo("Swapchain size: #x#", size->width, size->height);
+            Core::logInfo("Swapchain size: {}x{}", size->width, size->height);
             return false;
         }
         int w = 0;
@@ -599,14 +599,14 @@ struct VulkanDummy {
             Core::logError("Could not get framebuffer size");
             return true;
         }
-        Core::logInfo("Framebuffer size: #x#", w, h);
+        Core::logInfo("Framebuffer size: {}x{}", w, h);
         size->width = Core::clamp(
             static_cast<u32>(w), c.minImageExtent.width,
             c.maxImageExtent.width);
         size->height = Core::clamp(
             static_cast<u32>(h), c.minImageExtent.height,
             c.maxImageExtent.height);
-        Core::logInfo("Swapchain size: #x#", size->width, size->height);
+        Core::logInfo("Swapchain size: {}x{}", size->width, size->height);
         return false;
     }
 
@@ -655,7 +655,7 @@ struct VulkanDummy {
         int points = 0;
         VkPhysicalDeviceProperties p;
         b.getPhysicalDeviceProperties(p);
-        Core::logInfo("Checking '#'", p.deviceName);
+        Core::logInfo("Checking '{}'", p.deviceName);
         switch(p.deviceType) {
             case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: points += 100; break;
             case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: points += 50; break;
@@ -689,7 +689,7 @@ struct VulkanDummy {
         } else {
             points += getSurfacePresentModePoints(d.presentMode);
         }
-        Core::logInfo("> Final points: #", points);
+        Core::logInfo("> Final points: {}", points);
         return points;
     }
 
@@ -701,7 +701,7 @@ struct VulkanDummy {
         }
         VkPhysicalDeviceProperties p;
         base.getPhysicalDeviceProperties(p);
-        Core::logInfo("Best Device: #", p.deviceName);
+        Core::logInfo("Best Device: {}", p.deviceName);
         return false;
     }
 
@@ -710,7 +710,7 @@ struct VulkanDummy {
             Core::logError("Could not get swapchain images");
             return true;
         }
-        Core::logInfo("Found # images", images.images.getLength());
+        Core::logInfo("Found {} images", images.images.getLength());
         return false;
     }
 

+ 4 - 4
test/modules/ImageTests.cpp

@@ -6,8 +6,8 @@ import Core.ToString;
 
 static void testReadPNG8(
     const char* path, const char* name, int width, int height, int channels) {
-    char fullPath[512];
-    Core::formatBuffer(fullPath, sizeof(fullPath), "#/#.png", path, name);
+    Core::String<512> fullPath;
+    fullPath.format("{}/{}.png", path, name);
     Core::Image8 i;
     Core::test(width == 0, i.read(fullPath));
     if(width != 0) {
@@ -20,8 +20,8 @@ static void testReadPNG8(
 
 static void testReadPNG16(
     const char* path, const char* name, int width, int height, int channels) {
-    char fullPath[512];
-    Core::formatBuffer(fullPath, sizeof(fullPath), "#/#.png", path, name);
+    Core::String<512> fullPath;
+    fullPath.format("{}/{}.png", path, name);
     Core::Image16 i;
     Core::test(width == 0, i.read(fullPath));
     if(width != 0) {

+ 4 - 3
test/modules/WindowManagerTests.cpp

@@ -8,6 +8,7 @@
 
 import Core.Logger;
 import Core.Terminal;
+import Core.TerminalConstants;
 import Core.Vector;
 
 namespace W = Core::Window;
@@ -23,7 +24,7 @@ static bool isRunning(void*) {
 static void tick(void*) {
     if(!W::isInputEnabled()) {
         Core::logInfo(
-            "TPS: #\nFPS: #\n", W::getTicksPerSecond(),
+            "TPS: {}\nFPS: {}\n", W::getTicksPerSecond(),
             W::getFramesPerSecond());
         printf(
             "%12s | Down: %d | DownTime: %3d | Released: %d\n",
@@ -35,7 +36,7 @@ static void tick(void*) {
             W::getButtonName(testButton), W::isButtonDown(testButton),
             W::getButtonDownTime(testButton), W::wasButtonReleased(testButton));
         Core::Vector2 mouse = W::getLastMousePosition();
-        Core::logInfo("Mouse: # #\n", mouse[0], mouse[1]);
+        Core::logInfo("Mouse: {} {}\n", mouse[0], mouse[1]);
     }
     if(W::getButtonDownTime(textButton) == 1) {
         if(W::isInputEnabled()) {
@@ -57,7 +58,7 @@ static void printReport(
     Core::LogLevel l, const std::source_location& sl, void*,
     const char* message) {
     Core::log(
-        l, Core::Terminal::FG_RED, Core::FormatLocation("#", sl), message);
+        l, Core::Terminal::FG_RED, Core::FormatLocation("{}", sl), message);
 }
 
 void testWindow() {