Minor modernization changes: 'nullptr', range-based 'for' loops, ...

This commit is contained in:
Vittorio Romeo 2021-12-08 19:24:23 +00:00
parent 2839f6b4d2
commit 87e84bc9e5
30 changed files with 111 additions and 112 deletions

View File

@ -529,12 +529,12 @@ void threadFunction()
std::vector<sf::Vertex> vertices(resolutionX * rowBlockSize * 6); std::vector<sf::Vertex> vertices(resolutionX * rowBlockSize * 6);
WorkItem workItem = {0, 0}; WorkItem workItem = {nullptr, 0};
// Loop until the application exits // Loop until the application exits
for (;;) for (;;)
{ {
workItem.targetBuffer = 0; workItem.targetBuffer = nullptr;
// Check if there are new work items in the queue // Check if there are new work items in the queue
{ {

View File

@ -236,8 +236,8 @@ public:
// Render the updated scene to the off-screen surface // Render the updated scene to the off-screen surface
m_surface.clear(sf::Color::White); m_surface.clear(sf::Color::White);
m_surface.draw(m_backgroundSprite); m_surface.draw(m_backgroundSprite);
for (std::size_t i = 0; i < m_entities.size(); ++i) for (const sf::Sprite& entity : m_entities)
m_surface.draw(m_entities[i]); m_surface.draw(entity);
m_surface.display(); m_surface.display();
} }
@ -366,8 +366,8 @@ int main()
std::size_t current = 0; std::size_t current = 0;
// Initialize them // Initialize them
for (std::size_t i = 0; i < effects.size(); ++i) for (Effect* effect : effects)
effects[i]->load(); effect->load();
// Create the messages background // Create the messages background
sf::Texture textBackgroundTexture; sf::Texture textBackgroundTexture;
@ -457,8 +457,8 @@ int main()
} }
// delete the effects // delete the effects
for (std::size_t i = 0; i < effects.size(); ++i) for (Effect* effect : effects)
delete effects[i]; delete effect;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -89,8 +89,8 @@ namespace
// Normalize // Normalize
float factor = 1.0f / std::sqrt(forward[0] * forward[0] + forward[1] * forward[1] + forward[2] * forward[2]); 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++) for(float& f : forward)
forward[i] = forward[i] * factor; f *= factor;
// Side vector (Forward cross product Up) // Side vector (Forward cross product Up)
Vec3 side = { Vec3 side = {
@ -102,8 +102,8 @@ namespace
// Normalize // Normalize
factor = 1.0f / std::sqrt(side[0] * side[0] + side[1] * side[1] + side[2] * side[2]); factor = 1.0f / std::sqrt(side[0] * side[0] + side[1] * side[1] + side[2] * side[2]);
for(int i = 0; i < 3; i++) for(float& f : side)
side[i] = side[i] * factor; f *= factor;
result[0][0] = side[0]; result[0][0] = side[0];
result[0][1] = side[1] * forward[2] - side[2] * forward[1]; result[0][1] = side[1] * forward[2] - side[2] * forward[1];
@ -266,23 +266,23 @@ public:
cleanupSwapchain(); cleanupSwapchain();
// Vulkan teardown procedure // Vulkan teardown procedure
for (std::size_t i = 0; i < fences.size(); i++) for (VkFence fence : fences)
vkDestroyFence(device, fences[i], 0); vkDestroyFence(device, fence, 0);
for (std::size_t i = 0; i < renderFinishedSemaphores.size(); i++) for (VkSemaphore renderFinishedSemaphore : renderFinishedSemaphores)
vkDestroySemaphore(device, renderFinishedSemaphores[i], 0); vkDestroySemaphore(device, renderFinishedSemaphore, 0);
for (std::size_t i = 0; i < imageAvailableSemaphores.size(); i++) for (VkSemaphore imageAvailableSemaphore : imageAvailableSemaphores)
vkDestroySemaphore(device, imageAvailableSemaphores[i], 0); vkDestroySemaphore(device, imageAvailableSemaphore, 0);
if (descriptorPool) if (descriptorPool)
vkDestroyDescriptorPool(device, descriptorPool, 0); vkDestroyDescriptorPool(device, descriptorPool, 0);
for (std::size_t i = 0; i < uniformBuffersMemory.size(); i++) for (VkDeviceMemory i : uniformBuffersMemory)
vkFreeMemory(device, uniformBuffersMemory[i], 0); vkFreeMemory(device, i, 0);
for (std::size_t i = 0; i < uniformBuffers.size(); i++) for (VkBuffer uniformBuffer : uniformBuffers)
vkDestroyBuffer(device, uniformBuffers[i], 0); vkDestroyBuffer(device, uniformBuffer, 0);
if (textureSampler) if (textureSampler)
vkDestroySampler(device, textureSampler, 0); vkDestroySampler(device, textureSampler, 0);
@ -337,16 +337,16 @@ public:
void cleanupSwapchain() void cleanupSwapchain()
{ {
// Swapchain teardown procedure // Swapchain teardown procedure
for (std::size_t i = 0; i < fences.size(); i++) for (VkFence fence : fences)
vkWaitForFences(device, 1, &fences[i], VK_TRUE, std::numeric_limits<uint64_t>::max()); vkWaitForFences(device, 1, &fence, VK_TRUE, std::numeric_limits<uint64_t>::max());
if (commandBuffers.size()) if (commandBuffers.size())
vkFreeCommandBuffers(device, commandPool, static_cast<sf::Uint32>(commandBuffers.size()), commandBuffers.data()); vkFreeCommandBuffers(device, commandPool, static_cast<sf::Uint32>(commandBuffers.size()), commandBuffers.data());
commandBuffers.clear(); commandBuffers.clear();
for (std::size_t i = 0; i < swapchainFramebuffers.size(); i++) for (VkFramebuffer swapchainFramebuffer : swapchainFramebuffers)
vkDestroyFramebuffer(device, swapchainFramebuffers[i], 0); vkDestroyFramebuffer(device, swapchainFramebuffer, 0);
swapchainFramebuffers.clear(); swapchainFramebuffers.clear();
@ -368,8 +368,8 @@ public:
if (depthImage) if (depthImage)
vkDestroyImage(device, depthImage, 0); vkDestroyImage(device, depthImage, 0);
for (std::size_t i = 0; i < swapchainImageViews.size(); i++) for (VkImageView swapchainImageView : swapchainImageViews)
vkDestroyImageView(device, swapchainImageViews[i], 0); vkDestroyImageView(device, swapchainImageView, 0);
swapchainImageViews.clear(); swapchainImageViews.clear();
@ -433,7 +433,7 @@ public:
// Activate the layers we are interested in // Activate the layers we are interested in
std::vector<const char*> validationLayers; std::vector<const char*> 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_LUNARG_standard_validation, meta-layer for the following layers:
// -- VK_LAYER_GOOGLE_threading // -- VK_LAYER_GOOGLE_threading
@ -446,11 +446,11 @@ public:
// -- VK_LAYER_GOOGLE_unique_objects // -- VK_LAYER_GOOGLE_unique_objects
// These layers perform error checking and warn about bad or sub-optimal Vulkan API usage // 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 // 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"); 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"); validationLayers.push_back("VK_LAYER_LUNARG_monitor");
} }
@ -560,14 +560,14 @@ public:
} }
// Look for a GPU that supports swapchains // Look for a GPU that supports swapchains
for (std::size_t i = 0; i < devices.size(); i++) for (VkPhysicalDevice dev : devices)
{ {
VkPhysicalDeviceProperties deviceProperties; VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(devices[i], &deviceProperties); vkGetPhysicalDeviceProperties(dev, &deviceProperties);
std::vector<VkExtensionProperties> extensions; std::vector<VkExtensionProperties> extensions;
if (vkEnumerateDeviceExtensionProperties(devices[i], 0, &objectCount, 0) != VK_SUCCESS) if (vkEnumerateDeviceExtensionProperties(dev, 0, &objectCount, 0) != VK_SUCCESS)
{ {
vulkanAvailable = false; vulkanAvailable = false;
return; return;
@ -575,7 +575,7 @@ public:
extensions.resize(objectCount); extensions.resize(objectCount);
if (vkEnumerateDeviceExtensionProperties(devices[i], 0, &objectCount, extensions.data()) != VK_SUCCESS) if (vkEnumerateDeviceExtensionProperties(dev, 0, &objectCount, extensions.data()) != VK_SUCCESS)
{ {
vulkanAvailable = false; vulkanAvailable = false;
return; return;
@ -583,9 +583,9 @@ public:
bool supportsSwapchain = false; 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; supportsSwapchain = true;
break; break;
@ -598,12 +598,12 @@ public:
// Prefer discrete over integrated GPUs if multiple are available // Prefer discrete over integrated GPUs if multiple are available
if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
{ {
gpu = devices[i]; gpu = dev;
break; break;
} }
else if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) else if (deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
{ {
gpu = devices[i]; gpu = dev;
} }
} }
@ -743,9 +743,9 @@ public:
} }
else if (!surfaceFormats.empty()) 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.format = VK_FORMAT_B8G8R8A8_UNORM;
swapchainFormat.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; swapchainFormat.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
@ -783,11 +783,11 @@ public:
// Prefer mailbox over FIFO if it is available // Prefer mailbox over FIFO if it is available
VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR; 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; break;
} }
} }

View File

@ -59,7 +59,7 @@ int main()
windowClass.cbWndExtra = 0; windowClass.cbWndExtra = 0;
windowClass.hInstance = instance; windowClass.hInstance = instance;
windowClass.hIcon = nullptr; windowClass.hIcon = nullptr;
windowClass.hCursor = 0; windowClass.hCursor = nullptr;
windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND); windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
windowClass.lpszMenuName = nullptr; windowClass.lpszMenuName = nullptr;
windowClass.lpszClassName = TEXT("SFML App"); windowClass.lpszClassName = TEXT("SFML App");

View File

@ -31,7 +31,7 @@
#include <SFML/Window/Export.hpp> #include <SFML/Window/Export.hpp>
#include <SFML/Window/WindowHandle.hpp> #include <SFML/Window/WindowHandle.hpp>
#include <vector> #include <vector>
#include <stdint.h> #include <cstdint>
using VkInstance = struct VkInstance_T*; using VkInstance = struct VkInstance_T*;

View File

@ -404,7 +404,7 @@ public:
/// \return True if surface creation was successful, false otherwise /// \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: protected:

View File

@ -153,7 +153,7 @@ std::vector<std::string> SoundRecorder::getAvailableDevices()
{ {
while (*deviceList) while (*deviceList)
{ {
deviceNameList.push_back(deviceList); deviceNameList.emplace_back(deviceList);
deviceList += std::strlen(deviceList) + 1; deviceList += std::strlen(deviceList) + 1;
} }
} }

View File

@ -289,8 +289,8 @@ void SoundStream::streamData()
// Create the buffers // Create the buffers
alCheck(alGenBuffers(BufferCount, m_buffers)); alCheck(alGenBuffers(BufferCount, m_buffers));
for (int i = 0; i < BufferCount; ++i) for (Int64& bufferSeek : m_bufferSeeks)
m_bufferSeeks[i] = NoLoop; bufferSeek = NoLoop;
// Fill the queue // Fill the queue
requestStop = fillQueue(); requestStop = fillQueue();

View File

@ -294,7 +294,7 @@ bool Font::loadFromStream(InputStream& stream)
FT_Open_Args args; FT_Open_Args args;
args.flags = FT_OPEN_STREAM; args.flags = FT_OPEN_STREAM;
args.stream = rec; args.stream = rec;
args.driver = 0; args.driver = nullptr;
// Load the new font face from the specified stream // Load the new font face from the specified stream
FT_Face face; 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) // Convert the glyph to a bitmap (i.e. rasterize it)
// Warning! After this line, do not read any data from glyphDesc directly, use // Warning! After this line, do not read any data from glyphDesc directly, use
// bitmapGlyph.root to access the FT_Glyph data. // 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<FT_BitmapGlyph>(glyphDesc); auto bitmapGlyph = reinterpret_cast<FT_BitmapGlyph>(glyphDesc);
FT_Bitmap& bitmap = bitmapGlyph->bitmap; FT_Bitmap& bitmap = bitmapGlyph->bitmap;

View File

@ -37,7 +37,7 @@ namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderTextureImplDefault::RenderTextureImplDefault() : RenderTextureImplDefault::RenderTextureImplDefault() :
m_context(0), m_context(nullptr),
m_width (0), m_width (0),
m_height (0) m_height (0)
{ {

View File

@ -128,7 +128,7 @@ m_sRgb (false)
Lock lock(mutex); Lock lock(mutex);
// Register the context destruction callback // Register the context destruction callback
registerContextDestroyCallback(contextDestroyCallback, 0); registerContextDestroyCallback(contextDestroyCallback, nullptr);
// Insert the new frame buffer mapping into the set of all active mappings // Insert the new frame buffer mapping into the set of all active mappings
frameBuffers.insert(&m_frameBuffers); frameBuffers.insert(&m_frameBuffers);

View File

@ -868,7 +868,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod
if (success == GL_FALSE) if (success == GL_FALSE)
{ {
char log[1024]; 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 err() << "Failed to compile vertex shader:" << std::endl
<< log << std::endl; << log << std::endl;
glCheck(GLEXT_glDeleteObject(vertexShader)); glCheck(GLEXT_glDeleteObject(vertexShader));
@ -895,7 +895,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod
if (success == GL_FALSE) if (success == GL_FALSE)
{ {
char log[1024]; 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 err() << "Failed to compile geometry shader:" << std::endl
<< log << std::endl; << log << std::endl;
glCheck(GLEXT_glDeleteObject(geometryShader)); glCheck(GLEXT_glDeleteObject(geometryShader));
@ -923,7 +923,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod
if (success == GL_FALSE) if (success == GL_FALSE)
{ {
char log[1024]; 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 err() << "Failed to compile fragment shader:" << std::endl
<< log << std::endl; << log << std::endl;
glCheck(GLEXT_glDeleteObject(fragmentShader)); glCheck(GLEXT_glDeleteObject(fragmentShader));
@ -945,7 +945,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod
if (success == GL_FALSE) if (success == GL_FALSE)
{ {
char log[1024]; 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 err() << "Failed to link shader:" << std::endl
<< log << std::endl; << log << std::endl;
glCheck(GLEXT_glDeleteObject(shaderProgram)); glCheck(GLEXT_glDeleteObject(shaderProgram));

View File

@ -147,7 +147,7 @@ bool VertexBuffer::create(std::size_t vertexCount)
} }
glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, m_buffer)); glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, m_buffer));
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexCount), 0, VertexBufferImpl::usageToGlEnum(m_usage))); glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexCount), nullptr, VertexBufferImpl::usageToGlEnum(m_usage)));
glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, 0)); glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, 0));
m_size = vertexCount; 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 // Check if we need to resize or orphan the buffer
if (vertexCount >= m_size) if (vertexCount >= m_size)
{ {
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexCount), 0, VertexBufferImpl::usageToGlEnum(m_usage))); glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexCount), nullptr, VertexBufferImpl::usageToGlEnum(m_usage)));
m_size = vertexCount; m_size = vertexCount;
} }
@ -234,14 +234,14 @@ bool VertexBuffer::update(const VertexBuffer& vertexBuffer)
} }
glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, m_buffer)); glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, m_buffer));
glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(sizeof(Vertex) * vertexBuffer.m_size), 0, VertexBufferImpl::usageToGlEnum(m_usage))); glCheck(GLEXT_glBufferData(GLEXT_GL_ARRAY_BUFFER, static_cast<GLsizeiptrARB>(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(destination = GLEXT_glMapBuffer(GLEXT_GL_ARRAY_BUFFER, GLEXT_GL_WRITE_ONLY));
glCheck(GLEXT_glBindBuffer(GLEXT_GL_ARRAY_BUFFER, vertexBuffer.m_buffer)); 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)); glCheck(source = GLEXT_glMapBuffer(GLEXT_GL_ARRAY_BUFFER, GLEXT_GL_READ_ONLY));
std::memcpy(destination, source, sizeof(Vertex) * vertexBuffer.m_size); std::memcpy(destination, source, sizeof(Vertex) * vertexBuffer.m_size);

View File

@ -544,12 +544,12 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode)
Uint8 data[6] = {0, 0, 0, 0, 0, 0}; Uint8 data[6] = {0, 0, 0, 0, 0, 0};
std::string str = response.getMessage().substr(begin); std::string str = response.getMessage().substr(begin);
std::size_t index = 0; std::size_t index = 0;
for (int i = 0; i < 6; ++i) for (unsigned char& datum : data)
{ {
// Extract the current number // Extract the current number
while (isdigit(str[index])) while (isdigit(str[index]))
{ {
data[i] = static_cast<Uint8>(static_cast<Uint8>(data[i] * 10) + static_cast<Uint8>(str[index] - '0')); datum = static_cast<Uint8>(static_cast<Uint8>(datum * 10) + static_cast<Uint8>(str[index] - '0'));
index++; index++;
} }

View File

@ -575,8 +575,8 @@ Packet& Packet::operator <<(const String& data)
// Then insert characters // Then insert characters
if (length > 0) if (length > 0)
{ {
for (String::ConstIterator c = data.begin(); c != data.end(); ++c) for (unsigned int datum : data)
*this << *c; *this << datum;
} }
return *this; return *this;

View File

@ -27,9 +27,9 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Network/Unix/SocketImpl.hpp> #include <SFML/Network/Unix/SocketImpl.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <errno.h> #include <cerrno>
#include <fcntl.h>
#include <cstring> #include <cstring>
#include <fcntl.h>
namespace sf namespace sf

View File

@ -29,7 +29,7 @@
#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) #if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS)
#include <mach/mach_time.h> #include <mach/mach_time.h>
#else #else
#include <time.h> #include <ctime>
#endif #endif

View File

@ -26,8 +26,8 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Unix/SleepImpl.hpp> #include <SFML/System/Unix/SleepImpl.hpp>
#include <errno.h> #include <cerrno>
#include <time.h> #include <ctime>
namespace sf namespace sf

View File

@ -49,7 +49,7 @@ Cursor::~Cursor()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Cursor::loadFromPixels(const Uint8* pixels, Vector2u size, Vector2u hotspot) 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; return false;
else else
return m_impl->loadFromPixels(pixels, size, hotspot); return m_impl->loadFromPixels(pixels, size, hotspot);

View File

@ -189,8 +189,8 @@ namespace
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
TransientContext() : TransientContext() :
referenceCount (0), referenceCount (0),
context (0), context (nullptr),
sharedContextLock(0), sharedContextLock(nullptr),
useSharedContext (false) useSharedContext (false)
{ {
if (resourceCount == 0) if (resourceCount == 0)
@ -279,8 +279,7 @@ namespace
for (unsigned int i = 0; i < static_cast<unsigned int>(numExtensions); ++i) for (unsigned int i = 0; i < static_cast<unsigned int>(numExtensions); ++i)
{ {
const char* extensionString = reinterpret_cast<const char*>(glGetStringiFunc(GL_EXTENSIONS, i)); const char* extensionString = reinterpret_cast<const char*>(glGetStringiFunc(GL_EXTENSIONS, i));
extensions.emplace_back(extensionString);
extensions.push_back(extensionString);
} }
} }
} }

View File

@ -109,10 +109,10 @@ JoystickManager::JoystickManager()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
JoystickManager::~JoystickManager() JoystickManager::~JoystickManager()
{ {
for (int i = 0; i < Joystick::Count; ++i) for (Item& item : m_joysticks)
{ {
if (m_joysticks[i].state.connected) if (item.state.connected)
m_joysticks[i].joystick.close(); item.joystick.close();
} }
JoystickImpl::cleanup(); JoystickImpl::cleanup();

View File

@ -80,11 +80,11 @@ Vector3f SensorManager::getValue(Sensor::Type sensor) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SensorManager::update() void SensorManager::update()
{ {
for (int i = 0; i < Sensor::Count; ++i) for (Item& item : m_sensors)
{ {
// Only process available sensors // Only process available sensors
if (m_sensors[i].available) if (item.available)
m_sensors[i].value = m_sensors[i].sensor.update(); item.value = item.sensor.update();
} }
} }
@ -114,10 +114,10 @@ SensorManager::SensorManager()
SensorManager::~SensorManager() SensorManager::~SensorManager()
{ {
// Per sensor cleanup // Per sensor cleanup
for (int i = 0; i < Sensor::Count; ++i) for (Item& item : m_sensors)
{ {
if (m_sensors[i].available) if (item.available)
m_sensors[i].sensor.close(); item.sensor.close();
} }
// Global sensor cleanup // Global sensor cleanup

View File

@ -31,7 +31,7 @@
#include <libudev.h> #include <libudev.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <cerrno>
#include <vector> #include <vector>
#include <string> #include <string>
#include <cstring> #include <cstring>

View File

@ -366,9 +366,9 @@ namespace
if (!ewmhSupported()) if (!ewmhSupported())
return false; 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; return true;
} }

View File

@ -465,8 +465,8 @@ bool JoystickImpl::isConnectedDInput(unsigned int index)
void JoystickImpl::updateConnectionsDInput() void JoystickImpl::updateConnectionsDInput()
{ {
// Clear plugged flags so we can determine which devices were added/removed // Clear plugged flags so we can determine which devices were added/removed
for (std::size_t i = 0; i < joystickList.size(); ++i) for (JoystickRecord& record : joystickList)
joystickList[i].plugged = false; record.plugged = false;
// Enumerate devices // Enumerate devices
HRESULT result = directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, &JoystickImpl::deviceEnumerationCallback, nullptr, DIEDFL_ATTACHEDONLY); HRESULT result = directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, &JoystickImpl::deviceEnumerationCallback, nullptr, DIEDFL_ATTACHEDONLY);
@ -511,11 +511,11 @@ bool JoystickImpl::openDInput(unsigned int index)
// Initialize DirectInput members // Initialize DirectInput members
m_device = nullptr; m_device = nullptr;
for (int i = 0; i < Joystick::AxisCount; ++i) for (int& axis : m_axes)
m_axes[i] = -1; axis = -1;
for (int i = 0; i < Joystick::ButtonCount; ++i) for (int& button : m_buttons)
m_buttons[i] = -1; button = -1;
std::memset(&m_deviceCaps, 0, sizeof(DIDEVCAPS)); std::memset(&m_deviceCaps, 0, sizeof(DIDEVCAPS));
m_deviceCaps.dwSize = 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 // 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)); std::memset(&property, 0, sizeof(property));
property.diph.dwSize = sizeof(property); property.diph.dwSize = sizeof(property);
@ -843,9 +843,9 @@ JoystickCaps JoystickImpl::getCapabilitiesDInput() const
// Count how many buttons have valid offsets // Count how many buttons have valid offsets
caps.buttonCount = 0; 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; ++caps.buttonCount;
} }
@ -1047,11 +1047,11 @@ JoystickState JoystickImpl::updateDInputPolled()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
BOOL CALLBACK JoystickImpl::deviceEnumerationCallback(const DIDEVICEINSTANCE* deviceInstance, void*) 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; return DIENUM_CONTINUE;
} }

View File

@ -135,11 +135,11 @@ bool VulkanImplWin32::isAvailable(bool requireGraphics)
uint32_t extensionCount = 0; uint32_t extensionCount = 0;
wrapper.vkEnumerateInstanceExtensionProperties(0, &extensionCount, nullptr); wrapper.vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
extensionProperties.resize(extensionCount); extensionProperties.resize(extensionCount);
wrapper.vkEnumerateInstanceExtensionProperties(0, &extensionCount, extensionProperties.data()); wrapper.vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensionProperties.data());
// Check if the necessary extensions are available // Check if the necessary extensions are available
bool has_VK_KHR_surface = false; bool has_VK_KHR_surface = false;
@ -173,7 +173,7 @@ bool VulkanImplWin32::isAvailable(bool requireGraphics)
VulkanFunctionPointer VulkanImplWin32::getFunction(const char* name) VulkanFunctionPointer VulkanImplWin32::getFunction(const char* name)
{ {
if (!isAvailable(false)) if (!isAvailable(false))
return 0; return nullptr;
return reinterpret_cast<VulkanFunctionPointer>(GetProcAddress(wrapper.library, name)); return reinterpret_cast<VulkanFunctionPointer>(GetProcAddress(wrapper.library, name));
} }

View File

@ -211,7 +211,7 @@ GlFunctionPointer WglContext::getFunction(const char* name)
if (module) if (module)
return reinterpret_cast<GlFunctionPointer>(GetProcAddress(module, reinterpret_cast<LPCSTR>(name))); return reinterpret_cast<GlFunctionPointer>(GetProcAddress(module, reinterpret_cast<LPCSTR>(name)));
return 0; return nullptr;
} }

View File

@ -113,7 +113,7 @@ namespace
if (user32Dll) if (user32Dll)
{ {
using SetProcessDPIAwareFuncType = BOOL (*)(); using SetProcessDPIAwareFuncType = BOOL (WINAPI *)();
auto SetProcessDPIAwareFunc = reinterpret_cast<SetProcessDPIAwareFuncType>(reinterpret_cast<void*>(GetProcAddress(user32Dll, "SetProcessDPIAware"))); auto SetProcessDPIAwareFunc = reinterpret_cast<SetProcessDPIAwareFuncType>(reinterpret_cast<void*>(GetProcAddress(user32Dll, "SetProcessDPIAware")));
if (SetProcessDPIAwareFunc) if (SetProcessDPIAwareFunc)
@ -474,8 +474,8 @@ void WindowImplWin32::registerWindowClass()
windowClass.cbWndExtra = 0; windowClass.cbWndExtra = 0;
windowClass.hInstance = GetModuleHandleW(nullptr); windowClass.hInstance = GetModuleHandleW(nullptr);
windowClass.hIcon = nullptr; windowClass.hIcon = nullptr;
windowClass.hCursor = 0; windowClass.hCursor = nullptr;
windowClass.hbrBackground = 0; windowClass.hbrBackground = nullptr;
windowClass.lpszMenuName = nullptr; windowClass.lpszMenuName = nullptr;
windowClass.lpszClassName = className; windowClass.lpszClassName = className;
RegisterClassW(&windowClass); RegisterClassW(&windowClass);

View File

@ -308,7 +308,7 @@ bool WindowBase::hasFocus() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
WindowHandle WindowBase::getSystemHandle() const WindowHandle WindowBase::getSystemHandle() const
{ {
return m_impl ? m_impl->getSystemHandle() : 0; return m_impl ? m_impl->getSystemHandle() : WindowHandle{};
} }

View File

@ -104,8 +104,8 @@ m_joystickThreshold(0.1f)
} }
// Get the initial sensor states // Get the initial sensor states
for (unsigned int i = 0; i < Sensor::Count; ++i) for (sf::Vector3f& vec : m_sensorValue)
m_sensorValue[i] = Vector3f(0, 0, 0); vec = Vector3f(0, 0, 0);
} }