Replace sentinel values with std::optional

This commit is contained in:
Chris Thrasher 2024-06-04 21:48:19 -06:00
parent 8805b93c57
commit 735f2d972d
2 changed files with 14 additions and 14 deletions

View File

@ -701,12 +701,12 @@ public:
if ((queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && (surfaceSupported == VK_TRUE)) if ((queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && (surfaceSupported == VK_TRUE))
{ {
queueFamilyIndex = static_cast<int>(i); queueFamilyIndex = static_cast<std::uint32_t>(i);
break; break;
} }
} }
if (queueFamilyIndex < 0) if (!queueFamilyIndex.has_value())
{ {
vulkanAvailable = false; vulkanAvailable = false;
return; return;
@ -717,7 +717,7 @@ public:
VkDeviceQueueCreateInfo deviceQueueCreateInfo = VkDeviceQueueCreateInfo(); VkDeviceQueueCreateInfo deviceQueueCreateInfo = VkDeviceQueueCreateInfo();
deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
deviceQueueCreateInfo.queueCount = 1; deviceQueueCreateInfo.queueCount = 1;
deviceQueueCreateInfo.queueFamilyIndex = static_cast<std::uint32_t>(queueFamilyIndex); deviceQueueCreateInfo.queueFamilyIndex = *queueFamilyIndex;
deviceQueueCreateInfo.pQueuePriorities = &queuePriority; deviceQueueCreateInfo.pQueuePriorities = &queuePriority;
// Enable the swapchain extension // Enable the swapchain extension
@ -743,7 +743,7 @@ public:
} }
// Retrieve a handle to the logical device command queue // Retrieve a handle to the logical device command queue
vkGetDeviceQueue(device, static_cast<std::uint32_t>(queueFamilyIndex), 0, &queue); vkGetDeviceQueue(device, *queueFamilyIndex, 0, &queue);
} }
// Query surface formats and set up swapchain // Query surface formats and set up swapchain
@ -1277,7 +1277,7 @@ public:
// We want to be able to reset command buffers after submitting them // We want to be able to reset command buffers after submitting them
VkCommandPoolCreateInfo commandPoolCreateInfo = VkCommandPoolCreateInfo(); VkCommandPoolCreateInfo commandPoolCreateInfo = VkCommandPoolCreateInfo();
commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
commandPoolCreateInfo.queueFamilyIndex = static_cast<std::uint32_t>(queueFamilyIndex); commandPoolCreateInfo.queueFamilyIndex = *queueFamilyIndex;
commandPoolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; commandPoolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
// Create our command pool // Create our command pool
@ -2586,7 +2586,7 @@ private:
VkDebugReportCallbackEXT debugReportCallback{}; VkDebugReportCallbackEXT debugReportCallback{};
VkSurfaceKHR surface{}; VkSurfaceKHR surface{};
VkPhysicalDevice gpu{}; VkPhysicalDevice gpu{};
int queueFamilyIndex{-1}; std::optional<std::uint32_t> queueFamilyIndex;
VkDevice device{}; VkDevice device{};
VkQueue queue{}; VkQueue queue{};
VkSurfaceFormatKHR swapchainFormat{}; VkSurfaceFormatKHR swapchainFormat{};

View File

@ -53,9 +53,9 @@ namespace
{ {
struct TouchSlot struct TouchSlot
{ {
int oldId{-1}; std::optional<unsigned int> oldId;
int id{-1}; std::optional<unsigned int> id;
sf::Vector2i pos; sf::Vector2i pos;
}; };
std::recursive_mutex inputMutex; // threadsafe? maybe... std::recursive_mutex inputMutex; // threadsafe? maybe...
@ -327,14 +327,14 @@ void processSlots()
{ {
if (slot.oldId == slot.id) if (slot.oldId == slot.id)
{ {
pushEvent(sf::Event::TouchMoved{static_cast<unsigned int>(slot.id), slot.pos}); pushEvent(sf::Event::TouchMoved{*slot.id, slot.pos});
} }
else else
{ {
if (slot.oldId != -1) if (slot.oldId.has_value())
pushEvent(sf::Event::TouchEnded{static_cast<unsigned int>(slot.oldId), slot.pos}); pushEvent(sf::Event::TouchEnded{*slot.oldId, slot.pos});
if (slot.id != -1) if (slot.id.has_value())
pushEvent(sf::Event::TouchBegan{static_cast<unsigned int>(slot.id), slot.pos}); pushEvent(sf::Event::TouchBegan{*slot.id, slot.pos});
slot.oldId = slot.id; slot.oldId = slot.id;
} }