From 735f2d972d1b3bd3443a36a33ab8ae42c0d11d63 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Tue, 4 Jun 2024 21:48:19 -0600 Subject: [PATCH] Replace sentinel values with `std::optional` --- examples/vulkan/Vulkan.cpp | 12 ++++++------ src/SFML/Window/DRM/InputImpl.cpp | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 10407928d..686f8cd62 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -701,12 +701,12 @@ public: if ((queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && (surfaceSupported == VK_TRUE)) { - queueFamilyIndex = static_cast(i); + queueFamilyIndex = static_cast(i); break; } } - if (queueFamilyIndex < 0) + if (!queueFamilyIndex.has_value()) { vulkanAvailable = false; return; @@ -717,7 +717,7 @@ public: VkDeviceQueueCreateInfo deviceQueueCreateInfo = VkDeviceQueueCreateInfo(); deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; deviceQueueCreateInfo.queueCount = 1; - deviceQueueCreateInfo.queueFamilyIndex = static_cast(queueFamilyIndex); + deviceQueueCreateInfo.queueFamilyIndex = *queueFamilyIndex; deviceQueueCreateInfo.pQueuePriorities = &queuePriority; // Enable the swapchain extension @@ -743,7 +743,7 @@ public: } // Retrieve a handle to the logical device command queue - vkGetDeviceQueue(device, static_cast(queueFamilyIndex), 0, &queue); + vkGetDeviceQueue(device, *queueFamilyIndex, 0, &queue); } // Query surface formats and set up swapchain @@ -1277,7 +1277,7 @@ public: // We want to be able to reset command buffers after submitting them VkCommandPoolCreateInfo commandPoolCreateInfo = VkCommandPoolCreateInfo(); commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - commandPoolCreateInfo.queueFamilyIndex = static_cast(queueFamilyIndex); + commandPoolCreateInfo.queueFamilyIndex = *queueFamilyIndex; commandPoolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; // Create our command pool @@ -2586,7 +2586,7 @@ private: VkDebugReportCallbackEXT debugReportCallback{}; VkSurfaceKHR surface{}; VkPhysicalDevice gpu{}; - int queueFamilyIndex{-1}; + std::optional queueFamilyIndex; VkDevice device{}; VkQueue queue{}; VkSurfaceFormatKHR swapchainFormat{}; diff --git a/src/SFML/Window/DRM/InputImpl.cpp b/src/SFML/Window/DRM/InputImpl.cpp index 028437859..508819923 100644 --- a/src/SFML/Window/DRM/InputImpl.cpp +++ b/src/SFML/Window/DRM/InputImpl.cpp @@ -53,9 +53,9 @@ namespace { struct TouchSlot { - int oldId{-1}; - int id{-1}; - sf::Vector2i pos; + std::optional oldId; + std::optional id; + sf::Vector2i pos; }; std::recursive_mutex inputMutex; // threadsafe? maybe... @@ -327,14 +327,14 @@ void processSlots() { if (slot.oldId == slot.id) { - pushEvent(sf::Event::TouchMoved{static_cast(slot.id), slot.pos}); + pushEvent(sf::Event::TouchMoved{*slot.id, slot.pos}); } else { - if (slot.oldId != -1) - pushEvent(sf::Event::TouchEnded{static_cast(slot.oldId), slot.pos}); - if (slot.id != -1) - pushEvent(sf::Event::TouchBegan{static_cast(slot.id), slot.pos}); + if (slot.oldId.has_value()) + pushEvent(sf::Event::TouchEnded{*slot.oldId, slot.pos}); + if (slot.id.has_value()) + pushEvent(sf::Event::TouchBegan{*slot.id, slot.pos}); slot.oldId = slot.id; }