From 87e84bc9e55cc33d3a3bbb06032893e6534a61ba Mon Sep 17 00:00:00 2001 From: Vittorio Romeo Date: Wed, 8 Dec 2021 19:24:23 +0000 Subject: [PATCH] Minor modernization changes: 'nullptr', range-based 'for' loops, ... --- examples/island/Island.cpp | 4 +- examples/shader/Shader.cpp | 12 ++-- examples/vulkan/Vulkan.cpp | 72 +++++++++---------- examples/win32/Win32.cpp | 2 +- include/SFML/Window/Vulkan.hpp | 2 +- include/SFML/Window/WindowBase.hpp | 2 +- src/SFML/Audio/SoundRecorder.cpp | 2 +- src/SFML/Audio/SoundStream.cpp | 4 +- src/SFML/Graphics/Font.cpp | 4 +- .../Graphics/RenderTextureImplDefault.cpp | 2 +- src/SFML/Graphics/RenderTextureImplFBO.cpp | 2 +- src/SFML/Graphics/Shader.cpp | 8 +-- src/SFML/Graphics/VertexBuffer.cpp | 10 +-- src/SFML/Network/Ftp.cpp | 4 +- src/SFML/Network/Packet.cpp | 4 +- src/SFML/Network/Unix/SocketImpl.cpp | 4 +- src/SFML/System/Unix/ClockImpl.cpp | 2 +- src/SFML/System/Unix/SleepImpl.cpp | 4 +- src/SFML/Window/Cursor.cpp | 2 +- src/SFML/Window/GlContext.cpp | 7 +- src/SFML/Window/JoystickManager.cpp | 6 +- src/SFML/Window/SensorManager.cpp | 12 ++-- src/SFML/Window/Unix/JoystickImpl.cpp | 2 +- src/SFML/Window/Unix/WindowImplX11.cpp | 4 +- src/SFML/Window/Win32/JoystickImpl.cpp | 26 +++---- src/SFML/Window/Win32/VulkanImplWin32.cpp | 6 +- src/SFML/Window/Win32/WglContext.cpp | 2 +- src/SFML/Window/Win32/WindowImplWin32.cpp | 6 +- src/SFML/Window/WindowBase.cpp | 2 +- src/SFML/Window/WindowImpl.cpp | 4 +- 30 files changed, 111 insertions(+), 112 deletions(-) diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 3df5a221b..ab70f621f 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -529,12 +529,12 @@ void threadFunction() std::vector vertices(resolutionX * rowBlockSize * 6); - WorkItem workItem = {0, 0}; + WorkItem workItem = {nullptr, 0}; // Loop until the application exits for (;;) { - workItem.targetBuffer = 0; + workItem.targetBuffer = nullptr; // Check if there are new work items in the queue { diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index 69de18e01..410db0fa8 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -236,8 +236,8 @@ public: // Render the updated scene to the off-screen surface m_surface.clear(sf::Color::White); m_surface.draw(m_backgroundSprite); - for (std::size_t i = 0; i < m_entities.size(); ++i) - m_surface.draw(m_entities[i]); + for (const sf::Sprite& entity : m_entities) + m_surface.draw(entity); m_surface.display(); } @@ -366,8 +366,8 @@ int main() std::size_t current = 0; // Initialize them - for (std::size_t i = 0; i < effects.size(); ++i) - effects[i]->load(); + for (Effect* effect : effects) + effect->load(); // Create the messages background sf::Texture textBackgroundTexture; @@ -457,8 +457,8 @@ int main() } // delete the effects - for (std::size_t i = 0; i < effects.size(); ++i) - delete effects[i]; + for (Effect* effect : effects) + delete effect; return EXIT_SUCCESS; } diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 4134d1e6d..e1ad63ddd 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -89,8 +89,8 @@ namespace // Normalize float factor = 1.0f / std::sqrt(forward[0] * forward[0] + forward[1] * forward[1] + forward[2] * forward[2]); - for(int i = 0; i < 3; i++) - forward[i] = forward[i] * factor; + for(float& f : forward) + f *= factor; // Side vector (Forward cross product Up) Vec3 side = { @@ -102,8 +102,8 @@ namespace // Normalize factor = 1.0f / std::sqrt(side[0] * side[0] + side[1] * side[1] + side[2] * side[2]); - for(int i = 0; i < 3; i++) - side[i] = side[i] * factor; + for(float& f : side) + f *= factor; result[0][0] = side[0]; result[0][1] = side[1] * forward[2] - side[2] * forward[1]; @@ -266,23 +266,23 @@ public: cleanupSwapchain(); // Vulkan teardown procedure - for (std::size_t i = 0; i < fences.size(); i++) - vkDestroyFence(device, fences[i], 0); + for (VkFence fence : fences) + vkDestroyFence(device, fence, 0); - for (std::size_t i = 0; i < renderFinishedSemaphores.size(); i++) - vkDestroySemaphore(device, renderFinishedSemaphores[i], 0); + for (VkSemaphore renderFinishedSemaphore : renderFinishedSemaphores) + vkDestroySemaphore(device, renderFinishedSemaphore, 0); - for (std::size_t i = 0; i < imageAvailableSemaphores.size(); i++) - vkDestroySemaphore(device, imageAvailableSemaphores[i], 0); + for (VkSemaphore imageAvailableSemaphore : imageAvailableSemaphores) + vkDestroySemaphore(device, imageAvailableSemaphore, 0); if (descriptorPool) vkDestroyDescriptorPool(device, descriptorPool, 0); - for (std::size_t i = 0; i < uniformBuffersMemory.size(); i++) - vkFreeMemory(device, uniformBuffersMemory[i], 0); + for (VkDeviceMemory i : uniformBuffersMemory) + vkFreeMemory(device, i, 0); - for (std::size_t i = 0; i < uniformBuffers.size(); i++) - vkDestroyBuffer(device, uniformBuffers[i], 0); + for (VkBuffer uniformBuffer : uniformBuffers) + vkDestroyBuffer(device, uniformBuffer, 0); if (textureSampler) vkDestroySampler(device, textureSampler, 0); @@ -337,16 +337,16 @@ public: void cleanupSwapchain() { // Swapchain teardown procedure - for (std::size_t i = 0; i < fences.size(); i++) - vkWaitForFences(device, 1, &fences[i], VK_TRUE, std::numeric_limits::max()); + for (VkFence fence : fences) + vkWaitForFences(device, 1, &fence, VK_TRUE, std::numeric_limits::max()); if (commandBuffers.size()) vkFreeCommandBuffers(device, commandPool, static_cast(commandBuffers.size()), commandBuffers.data()); commandBuffers.clear(); - for (std::size_t i = 0; i < swapchainFramebuffers.size(); i++) - vkDestroyFramebuffer(device, swapchainFramebuffers[i], 0); + for (VkFramebuffer swapchainFramebuffer : swapchainFramebuffers) + vkDestroyFramebuffer(device, swapchainFramebuffer, 0); swapchainFramebuffers.clear(); @@ -368,8 +368,8 @@ public: if (depthImage) vkDestroyImage(device, depthImage, 0); - for (std::size_t i = 0; i < swapchainImageViews.size(); i++) - vkDestroyImageView(device, swapchainImageViews[i], 0); + for (VkImageView swapchainImageView : swapchainImageViews) + vkDestroyImageView(device, swapchainImageView, 0); swapchainImageViews.clear(); @@ -433,7 +433,7 @@ public: // Activate the layers we are interested in std::vector validationLayers; - for (std::size_t i = 0; i < layers.size(); i++) + for (VkLayerProperties& layer : layers) { // VK_LAYER_LUNARG_standard_validation, meta-layer for the following layers: // -- VK_LAYER_GOOGLE_threading @@ -446,11 +446,11 @@ public: // -- VK_LAYER_GOOGLE_unique_objects // These layers perform error checking and warn about bad or sub-optimal Vulkan API usage // VK_LAYER_LUNARG_monitor appends an FPS counter to the window title - if (!std::strcmp(layers[i].layerName, "VK_LAYER_LUNARG_standard_validation")) + if (!std::strcmp(layer.layerName, "VK_LAYER_LUNARG_standard_validation")) { validationLayers.push_back("VK_LAYER_LUNARG_standard_validation"); } - else if (!std::strcmp(layers[i].layerName, "VK_LAYER_LUNARG_monitor")) + else if (!std::strcmp(layer.layerName, "VK_LAYER_LUNARG_monitor")) { validationLayers.push_back("VK_LAYER_LUNARG_monitor"); } @@ -560,14 +560,14 @@ public: } // Look for a GPU that supports swapchains - for (std::size_t i = 0; i < devices.size(); i++) + for (VkPhysicalDevice dev : devices) { VkPhysicalDeviceProperties deviceProperties; - vkGetPhysicalDeviceProperties(devices[i], &deviceProperties); + vkGetPhysicalDeviceProperties(dev, &deviceProperties); std::vector extensions; - if (vkEnumerateDeviceExtensionProperties(devices[i], 0, &objectCount, 0) != VK_SUCCESS) + if (vkEnumerateDeviceExtensionProperties(dev, 0, &objectCount, 0) != VK_SUCCESS) { vulkanAvailable = false; return; @@ -575,7 +575,7 @@ public: extensions.resize(objectCount); - if (vkEnumerateDeviceExtensionProperties(devices[i], 0, &objectCount, extensions.data()) != VK_SUCCESS) + if (vkEnumerateDeviceExtensionProperties(dev, 0, &objectCount, extensions.data()) != VK_SUCCESS) { vulkanAvailable = false; return; @@ -583,9 +583,9 @@ public: bool supportsSwapchain = false; - for (std::size_t j = 0; j < extensions.size(); j++) + for (VkExtensionProperties& extension : extensions) { - if (!std::strcmp(extensions[j].extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) + if (!std::strcmp(extension.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) { supportsSwapchain = true; break; @@ -598,12 +598,12 @@ public: // Prefer discrete over integrated GPUs if multiple are available if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { - gpu = devices[i]; + gpu = dev; break; } else if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) { - gpu = devices[i]; + gpu = dev; } } @@ -743,9 +743,9 @@ public: } else if (!surfaceFormats.empty()) { - for (std::size_t i = 0; i < surfaceFormats.size(); i++) + for (VkSurfaceFormatKHR& surfaceFormat : surfaceFormats) { - if ((surfaceFormats[i].format == VK_FORMAT_B8G8R8A8_UNORM) && (surfaceFormats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)) + if ((surfaceFormat.format == VK_FORMAT_B8G8R8A8_UNORM) && (surfaceFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)) { swapchainFormat.format = VK_FORMAT_B8G8R8A8_UNORM; swapchainFormat.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; @@ -783,11 +783,11 @@ public: // Prefer mailbox over FIFO if it is available VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; - for (std::size_t i = 0; i < presentModes.size(); i++) + for (VkPresentModeKHR& i : presentModes) { - if (presentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR) + if (i == VK_PRESENT_MODE_MAILBOX_KHR) { - presentMode = presentModes[i]; + presentMode = i; break; } } diff --git a/examples/win32/Win32.cpp b/examples/win32/Win32.cpp index ccf32b8a8..090e51236 100644 --- a/examples/win32/Win32.cpp +++ b/examples/win32/Win32.cpp @@ -59,7 +59,7 @@ int main() windowClass.cbWndExtra = 0; windowClass.hInstance = instance; windowClass.hIcon = nullptr; - windowClass.hCursor = 0; + windowClass.hCursor = nullptr; windowClass.hbrBackground = reinterpret_cast(COLOR_BACKGROUND); windowClass.lpszMenuName = nullptr; windowClass.lpszClassName = TEXT("SFML App"); diff --git a/include/SFML/Window/Vulkan.hpp b/include/SFML/Window/Vulkan.hpp index 0dc8ab577..5a0927a6e 100644 --- a/include/SFML/Window/Vulkan.hpp +++ b/include/SFML/Window/Vulkan.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include using VkInstance = struct VkInstance_T*; diff --git a/include/SFML/Window/WindowBase.hpp b/include/SFML/Window/WindowBase.hpp index fbbe76ebe..49e8848ca 100644 --- a/include/SFML/Window/WindowBase.hpp +++ b/include/SFML/Window/WindowBase.hpp @@ -404,7 +404,7 @@ public: /// \return True if surface creation was successful, false otherwise /// //////////////////////////////////////////////////////////// - bool createVulkanSurface(const VkInstance& instance, VkSurfaceKHR& surface, const VkAllocationCallbacks* allocator = 0); + bool createVulkanSurface(const VkInstance& instance, VkSurfaceKHR& surface, const VkAllocationCallbacks* allocator = nullptr); protected: diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 6c1b0968d..2ca37c407 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -153,7 +153,7 @@ std::vector SoundRecorder::getAvailableDevices() { while (*deviceList) { - deviceNameList.push_back(deviceList); + deviceNameList.emplace_back(deviceList); deviceList += std::strlen(deviceList) + 1; } } diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index bdd8d23c9..be882a51f 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -289,8 +289,8 @@ void SoundStream::streamData() // Create the buffers alCheck(alGenBuffers(BufferCount, m_buffers)); - for (int i = 0; i < BufferCount; ++i) - m_bufferSeeks[i] = NoLoop; + for (Int64& bufferSeek : m_bufferSeeks) + bufferSeek = NoLoop; // Fill the queue requestStop = fillQueue(); diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index f4bc85366..40636fad2 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -294,7 +294,7 @@ bool Font::loadFromStream(InputStream& stream) FT_Open_Args args; args.flags = FT_OPEN_STREAM; args.stream = rec; - args.driver = 0; + args.driver = nullptr; // Load the new font face from the specified stream FT_Face face; @@ -616,7 +616,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f // Convert the glyph to a bitmap (i.e. rasterize it) // Warning! After this line, do not read any data from glyphDesc directly, use // bitmapGlyph.root to access the FT_Glyph data. - FT_Glyph_To_Bitmap(&glyphDesc, FT_RENDER_MODE_NORMAL, 0, 1); + FT_Glyph_To_Bitmap(&glyphDesc, FT_RENDER_MODE_NORMAL, nullptr, 1); auto bitmapGlyph = reinterpret_cast(glyphDesc); FT_Bitmap& bitmap = bitmapGlyph->bitmap; diff --git a/src/SFML/Graphics/RenderTextureImplDefault.cpp b/src/SFML/Graphics/RenderTextureImplDefault.cpp index 92d364ec6..41844c970 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.cpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.cpp @@ -37,7 +37,7 @@ namespace priv { //////////////////////////////////////////////////////////// RenderTextureImplDefault::RenderTextureImplDefault() : -m_context(0), +m_context(nullptr), m_width (0), m_height (0) { diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index b58a06925..6c7f72359 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -128,7 +128,7 @@ m_sRgb (false) Lock lock(mutex); // Register the context destruction callback - registerContextDestroyCallback(contextDestroyCallback, 0); + registerContextDestroyCallback(contextDestroyCallback, nullptr); // Insert the new frame buffer mapping into the set of all active mappings frameBuffers.insert(&m_frameBuffers); diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index c65e243a6..f7f05f7bd 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -868,7 +868,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod if (success == GL_FALSE) { char log[1024]; - glCheck(GLEXT_glGetInfoLog(vertexShader, sizeof(log), 0, log)); + glCheck(GLEXT_glGetInfoLog(vertexShader, sizeof(log), nullptr, log)); err() << "Failed to compile vertex shader:" << std::endl << log << std::endl; glCheck(GLEXT_glDeleteObject(vertexShader)); @@ -895,7 +895,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod if (success == GL_FALSE) { char log[1024]; - glCheck(GLEXT_glGetInfoLog(geometryShader, sizeof(log), 0, log)); + glCheck(GLEXT_glGetInfoLog(geometryShader, sizeof(log), nullptr, log)); err() << "Failed to compile geometry shader:" << std::endl << log << std::endl; glCheck(GLEXT_glDeleteObject(geometryShader)); @@ -923,7 +923,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod if (success == GL_FALSE) { char log[1024]; - glCheck(GLEXT_glGetInfoLog(fragmentShader, sizeof(log), 0, log)); + glCheck(GLEXT_glGetInfoLog(fragmentShader, sizeof(log), nullptr, log)); err() << "Failed to compile fragment shader:" << std::endl << log << std::endl; glCheck(GLEXT_glDeleteObject(fragmentShader)); @@ -945,7 +945,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod if (success == GL_FALSE) { char log[1024]; - glCheck(GLEXT_glGetInfoLog(shaderProgram, sizeof(log), 0, log)); + glCheck(GLEXT_glGetInfoLog(shaderProgram, sizeof(log), nullptr, log)); err() << "Failed to link shader:" << std::endl << log << std::endl; glCheck(GLEXT_glDeleteObject(shaderProgram)); diff --git a/src/SFML/Graphics/VertexBuffer.cpp b/src/SFML/Graphics/VertexBuffer.cpp index 3c09716c6..7b88ebf79 100644 --- a/src/SFML/Graphics/VertexBuffer.cpp +++ b/src/SFML/Graphics/VertexBuffer.cpp @@ -147,7 +147,7 @@ bool VertexBuffer::create(std::size_t vertexCount) } glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, m_buffer)); - glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast(sizeof(Vertex) * vertexCount), 0, VertexBufferImpl::usageToGlEnum(m_usage))); + glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast(sizeof(Vertex) * vertexCount), nullptr, VertexBufferImpl::usageToGlEnum(m_usage))); glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, 0)); m_size = vertexCount; @@ -190,7 +190,7 @@ bool VertexBuffer::update(const Vertex* vertices, std::size_t vertexCount, unsig // Check if we need to resize or orphan the buffer if (vertexCount >= m_size) { - glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast(sizeof(Vertex) * vertexCount), 0, VertexBufferImpl::usageToGlEnum(m_usage))); + glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast(sizeof(Vertex) * vertexCount), nullptr, VertexBufferImpl::usageToGlEnum(m_usage))); m_size = vertexCount; } @@ -234,14 +234,14 @@ bool VertexBuffer::update(const VertexBuffer& vertexBuffer) } glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, m_buffer)); - glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast(sizeof(Vertex) * vertexBuffer.m_size), 0, VertexBufferImpl::usageToGlEnum(m_usage))); + glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast(sizeof(Vertex) * vertexBuffer.m_size), nullptr, VertexBufferImpl::usageToGlEnum(m_usage))); - void* destination = 0; + void* destination = nullptr; glCheck(destination = GLEXT_glMapBuffer(GLEXT_GL_ARRAY_BUFFER, GLEXT_GL_WRITE_ONLY)); glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, vertexBuffer.m_buffer)); - void* source = 0; + void* source = nullptr; glCheck(source = GLEXT_glMapBuffer(GLEXT_GL_ARRAY_BUFFER, GLEXT_GL_READ_ONLY)); std::memcpy(destination, source, sizeof(Vertex) * vertexBuffer.m_size); diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index c76f2f294..d9e66b9f4 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -544,12 +544,12 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode) Uint8 data[6] = {0, 0, 0, 0, 0, 0}; std::string str = response.getMessage().substr(begin); std::size_t index = 0; - for (int i = 0; i < 6; ++i) + for (unsigned char& datum : data) { // Extract the current number while (isdigit(str[index])) { - data[i] = static_cast(static_cast(data[i] * 10) + static_cast(str[index] - '0')); + datum = static_cast(static_cast(datum * 10) + static_cast(str[index] - '0')); index++; } diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index 535599107..89508dbb1 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -575,8 +575,8 @@ Packet& Packet::operator <<(const String& data) // Then insert characters if (length > 0) { - for (String::ConstIterator c = data.begin(); c != data.end(); ++c) - *this << *c; + for (unsigned int datum : data) + *this << datum; } return *this; diff --git a/src/SFML/Network/Unix/SocketImpl.cpp b/src/SFML/Network/Unix/SocketImpl.cpp index d9b236612..3cb3a9dbd 100644 --- a/src/SFML/Network/Unix/SocketImpl.cpp +++ b/src/SFML/Network/Unix/SocketImpl.cpp @@ -27,9 +27,9 @@ //////////////////////////////////////////////////////////// #include #include -#include -#include +#include #include +#include namespace sf diff --git a/src/SFML/System/Unix/ClockImpl.cpp b/src/SFML/System/Unix/ClockImpl.cpp index 7f6a97aa4..85cf18a07 100644 --- a/src/SFML/System/Unix/ClockImpl.cpp +++ b/src/SFML/System/Unix/ClockImpl.cpp @@ -29,7 +29,7 @@ #if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) #include #else - #include + #include #endif diff --git a/src/SFML/System/Unix/SleepImpl.cpp b/src/SFML/System/Unix/SleepImpl.cpp index 474778d46..670702fab 100644 --- a/src/SFML/System/Unix/SleepImpl.cpp +++ b/src/SFML/System/Unix/SleepImpl.cpp @@ -26,8 +26,8 @@ // Headers //////////////////////////////////////////////////////////// #include -#include -#include +#include +#include namespace sf diff --git a/src/SFML/Window/Cursor.cpp b/src/SFML/Window/Cursor.cpp index 087342017..ee8fb627a 100644 --- a/src/SFML/Window/Cursor.cpp +++ b/src/SFML/Window/Cursor.cpp @@ -49,7 +49,7 @@ Cursor::~Cursor() //////////////////////////////////////////////////////////// bool Cursor::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot) { - if ((pixels == 0) || (size.x == 0) || (size.y == 0)) + if ((pixels == nullptr) || (size.x == 0) || (size.y == 0)) return false; else return m_impl->loadFromPixels(pixels, size, hotspot); diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 05dd56d95..b3848646c 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -189,8 +189,8 @@ namespace //////////////////////////////////////////////////////////// TransientContext() : referenceCount (0), - context (0), - sharedContextLock(0), + context (nullptr), + sharedContextLock(nullptr), useSharedContext (false) { if (resourceCount == 0) @@ -279,8 +279,7 @@ namespace for (unsigned int i = 0; i < static_cast(numExtensions); ++i) { const char* extensionString = reinterpret_cast(glGetStringiFunc(GL_EXTENSIONS, i)); - - extensions.push_back(extensionString); + extensions.emplace_back(extensionString); } } } diff --git a/src/SFML/Window/JoystickManager.cpp b/src/SFML/Window/JoystickManager.cpp index 457b2aff5..fd326d34b 100644 --- a/src/SFML/Window/JoystickManager.cpp +++ b/src/SFML/Window/JoystickManager.cpp @@ -109,10 +109,10 @@ JoystickManager::JoystickManager() //////////////////////////////////////////////////////////// JoystickManager::~JoystickManager() { - for (int i = 0; i < Joystick::Count; ++i) + for (Item& item : m_joysticks) { - if (m_joysticks[i].state.connected) - m_joysticks[i].joystick.close(); + if (item.state.connected) + item.joystick.close(); } JoystickImpl::cleanup(); diff --git a/src/SFML/Window/SensorManager.cpp b/src/SFML/Window/SensorManager.cpp index a60699576..0ab952833 100644 --- a/src/SFML/Window/SensorManager.cpp +++ b/src/SFML/Window/SensorManager.cpp @@ -80,11 +80,11 @@ Vector3f SensorManager::getValue(Sensor::Type sensor) const //////////////////////////////////////////////////////////// void SensorManager::update() { - for (int i = 0; i < Sensor::Count; ++i) + for (Item& item : m_sensors) { // Only process available sensors - if (m_sensors[i].available) - m_sensors[i].value = m_sensors[i].sensor.update(); + if (item.available) + item.value = item.sensor.update(); } } @@ -114,10 +114,10 @@ SensorManager::SensorManager() SensorManager::~SensorManager() { // Per sensor cleanup - for (int i = 0; i < Sensor::Count; ++i) + for (Item& item : m_sensors) { - if (m_sensors[i].available) - m_sensors[i].sensor.close(); + if (item.available) + item.sensor.close(); } // Global sensor cleanup diff --git a/src/SFML/Window/Unix/JoystickImpl.cpp b/src/SFML/Window/Unix/JoystickImpl.cpp index e9091be9d..becdaac9d 100644 --- a/src/SFML/Window/Unix/JoystickImpl.cpp +++ b/src/SFML/Window/Unix/JoystickImpl.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index bbf339023..ac601d843 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -366,9 +366,9 @@ namespace if (!ewmhSupported()) return false; - for (size_t i = 0; i < (sizeof(wmAbsPosGood) / sizeof(wmAbsPosGood[0])); i++) + for (const sf::String& name : wmAbsPosGood) { - if (wmAbsPosGood[i] == windowManagerName) + if (name == windowManagerName) return true; } diff --git a/src/SFML/Window/Win32/JoystickImpl.cpp b/src/SFML/Window/Win32/JoystickImpl.cpp index 73db3091d..79f1babed 100644 --- a/src/SFML/Window/Win32/JoystickImpl.cpp +++ b/src/SFML/Window/Win32/JoystickImpl.cpp @@ -465,8 +465,8 @@ bool JoystickImpl::isConnectedDInput(unsigned int index) void JoystickImpl::updateConnectionsDInput() { // Clear plugged flags so we can determine which devices were added/removed - for (std::size_t i = 0; i < joystickList.size(); ++i) - joystickList[i].plugged = false; + for (JoystickRecord& record : joystickList) + record.plugged = false; // Enumerate devices HRESULT result = directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, &JoystickImpl::deviceEnumerationCallback, nullptr, DIEDFL_ATTACHEDONLY); @@ -511,11 +511,11 @@ bool JoystickImpl::openDInput(unsigned int index) // Initialize DirectInput members m_device = nullptr; - for (int i = 0; i < Joystick::AxisCount; ++i) - m_axes[i] = -1; + for (int& axis : m_axes) + axis = -1; - for (int i = 0; i < Joystick::ButtonCount; ++i) - m_buttons[i] = -1; + for (int& button : m_buttons) + button = -1; std::memset(&m_deviceCaps, 0, sizeof(DIDEVCAPS)); m_deviceCaps.dwSize = sizeof(DIDEVCAPS); @@ -706,9 +706,9 @@ bool JoystickImpl::openDInput(unsigned int index) } // Set device's axis mode to absolute if the device reports having at least one axis - for (int i = 0; i < Joystick::AxisCount; ++i) + for (int axis : m_axes) { - if (m_axes[i] != -1) + if (axis != -1) { std::memset(&property, 0, sizeof(property)); property.diph.dwSize = sizeof(property); @@ -843,9 +843,9 @@ JoystickCaps JoystickImpl::getCapabilitiesDInput() const // Count how many buttons have valid offsets caps.buttonCount = 0; - for (int i = 0; i < Joystick::ButtonCount; ++i) + for (int button : m_buttons) { - if (m_buttons[i] != -1) + if (button != -1) ++caps.buttonCount; } @@ -1047,11 +1047,11 @@ JoystickState JoystickImpl::updateDInputPolled() //////////////////////////////////////////////////////////// BOOL CALLBACK JoystickImpl::deviceEnumerationCallback(const DIDEVICEINSTANCE* deviceInstance, void*) { - for (std::size_t i = 0; i < joystickList.size(); ++i) + for (JoystickRecord& record : joystickList) { - if (joystickList[i].guid == deviceInstance->guidInstance) + if (record.guid == deviceInstance->guidInstance) { - joystickList[i].plugged = true; + record.plugged = true; return DIENUM_CONTINUE; } diff --git a/src/SFML/Window/Win32/VulkanImplWin32.cpp b/src/SFML/Window/Win32/VulkanImplWin32.cpp index 633b741bf..ff4a1dabb 100644 --- a/src/SFML/Window/Win32/VulkanImplWin32.cpp +++ b/src/SFML/Window/Win32/VulkanImplWin32.cpp @@ -135,11 +135,11 @@ bool VulkanImplWin32::isAvailable(bool requireGraphics) uint32_t extensionCount = 0; - wrapper.vkEnumerateInstanceExtensionProperties(0, &extensionCount, nullptr); + wrapper.vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); extensionProperties.resize(extensionCount); - wrapper.vkEnumerateInstanceExtensionProperties(0, &extensionCount, extensionProperties.data()); + wrapper.vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensionProperties.data()); // Check if the necessary extensions are available bool has_VK_KHR_surface = false; @@ -173,7 +173,7 @@ bool VulkanImplWin32::isAvailable(bool requireGraphics) VulkanFunctionPointer VulkanImplWin32::getFunction(const char* name) { if (!isAvailable(false)) - return 0; + return nullptr; return reinterpret_cast(GetProcAddress(wrapper.library, name)); } diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index ed7f9c8e5..c65795670 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -211,7 +211,7 @@ GlFunctionPointer WglContext::getFunction(const char* name) if (module) return reinterpret_cast(GetProcAddress(module, reinterpret_cast(name))); - return 0; + return nullptr; } diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 69fc1117a..112938a71 100755 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -113,7 +113,7 @@ namespace if (user32Dll) { - using SetProcessDPIAwareFuncType = BOOL (*)(); + using SetProcessDPIAwareFuncType = BOOL (WINAPI *)(); auto SetProcessDPIAwareFunc = reinterpret_cast(reinterpret_cast(GetProcAddress(user32Dll, "SetProcessDPIAware"))); if (SetProcessDPIAwareFunc) @@ -474,8 +474,8 @@ void WindowImplWin32::registerWindowClass() windowClass.cbWndExtra = 0; windowClass.hInstance = GetModuleHandleW(nullptr); windowClass.hIcon = nullptr; - windowClass.hCursor = 0; - windowClass.hbrBackground = 0; + windowClass.hCursor = nullptr; + windowClass.hbrBackground = nullptr; windowClass.lpszMenuName = nullptr; windowClass.lpszClassName = className; RegisterClassW(&windowClass); diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index 6303526e0..159ff19ff 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -308,7 +308,7 @@ bool WindowBase::hasFocus() const //////////////////////////////////////////////////////////// WindowHandle WindowBase::getSystemHandle() const { - return m_impl ? m_impl->getSystemHandle() : 0; + return m_impl ? m_impl->getSystemHandle() : WindowHandle{}; } diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index e7933c86a..803e1e3ae 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -104,8 +104,8 @@ m_joystickThreshold(0.1f) } // Get the initial sensor states - for (unsigned int i = 0; i < Sensor::Count; ++i) - m_sensorValue[i] = Vector3f(0, 0, 0); + for (sf::Vector3f& vec : m_sensorValue) + vec = Vector3f(0, 0, 0); }