From 1a2ca9c8096401aa68bef455874df60dbdc9c2bf Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sat, 18 Mar 2017 13:18:59 +0100 Subject: [PATCH 01/18] Bump the required CMake version to 3.1.0 and enforce compiler C++14 support. --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 419d56d7..7ce5bf50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,7 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.1.0) + +# set the minimum required C++ standard to C++14 +set(CMAKE_CXX_STANDARD 14) # define a macro that helps defining an option macro(sfml_set_option var default type docstring) From 6d76b65fcf4e0df606be0a46be5418656497345c Mon Sep 17 00:00:00 2001 From: Mario Liebisch Date: Sat, 18 Mar 2017 14:09:58 +0100 Subject: [PATCH 02/18] Fixed compiler detection on Mac OS --- cmake/Config.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Config.cmake b/cmake/Config.cmake index c447113a..becb3829 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -89,7 +89,7 @@ endif() # detect the compiler and its version # Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true # even when CLANG is used, therefore the Clang test is done first -if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang") # CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change, # but there is no other way to detect CLang at the moment set(SFML_COMPILER_CLANG 1) @@ -122,7 +122,7 @@ elseif(MSVC) set(SFML_MSVC_VERSION 14) endif() else() - message(FATAL_ERROR "Unsupported compiler") + message(FATAL_ERROR "Unsupported compiler ('${CMAKE_CXX_COMPILER_ID}' by '${CMAKE_CXX_COMPILER}')") return() endif() From 686d0fa76c8f5af11214f3aed46bb4aa51e2ef82 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sat, 18 Mar 2017 14:53:45 +0100 Subject: [PATCH 03/18] Fixed trying to illegally cast NULL (nullptr in C++14) to void*. --- src/SFML/Window/Unix/WindowImplX11.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 91086e14..f14f69b0 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -1275,7 +1275,7 @@ void WindowImplX11::initialize() m_window, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - reinterpret_cast(NULL)); + NULL); } else { From 8ebb62205775eee85972fc50cca8e089ce094715 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sat, 1 Apr 2017 21:56:43 +0200 Subject: [PATCH 04/18] Removed auto_ptr usage. --- src/SFML/Audio/AudioDevice.cpp | 86 ++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/src/SFML/Audio/AudioDevice.cpp b/src/SFML/Audio/AudioDevice.cpp index 4a2c55f0..02fd0e37 100644 --- a/src/SFML/Audio/AudioDevice.cpp +++ b/src/SFML/Audio/AudioDevice.cpp @@ -29,7 +29,6 @@ #include #include #include -#include namespace @@ -103,50 +102,67 @@ AudioDevice::~AudioDevice() //////////////////////////////////////////////////////////// bool AudioDevice::isExtensionSupported(const std::string& extension) { - // Create a temporary audio device in case none exists yet. - // This device will not be used in this function and merely - // makes sure there is a valid OpenAL device for extension - // queries if none has been created yet. - std::auto_ptr device; - if (!audioDevice) - device.reset(new AudioDevice); + auto checkExtension = [&extension] + { - if ((extension.length() > 2) && (extension.substr(0, 3) == "ALC")) - return alcIsExtensionPresent(audioDevice, extension.c_str()) != AL_FALSE; - else - return alIsExtensionPresent(extension.c_str()) != AL_FALSE; + if ((extension.length() > 2) && (extension.substr(0, 3) == "ALC")) + return alcIsExtensionPresent(audioDevice, extension.c_str()) != AL_FALSE; + else + return alIsExtensionPresent(extension.c_str()) != AL_FALSE; + }; + + if (!audioDevice) + { + // Create a temporary audio device in case none exists yet. + // This device will not be used in this function and merely + // makes sure there is a valid OpenAL device for extension + // queries if none has been created yet. + AudioDevice device; + + return checkExtension(); + } + + return checkExtension(); } //////////////////////////////////////////////////////////// int AudioDevice::getFormatFromChannelCount(unsigned int channelCount) { - // Create a temporary audio device in case none exists yet. - // This device will not be used in this function and merely - // makes sure there is a valid OpenAL device for format - // queries if none has been created yet. - std::auto_ptr device; - if (!audioDevice) - device.reset(new AudioDevice); - - // Find the good format according to the number of channels - int format = 0; - switch (channelCount) + auto getFormat = [channelCount] { - case 1: format = AL_FORMAT_MONO16; break; - case 2: format = AL_FORMAT_STEREO16; break; - case 4: format = alGetEnumValue("AL_FORMAT_QUAD16"); break; - case 6: format = alGetEnumValue("AL_FORMAT_51CHN16"); break; - case 7: format = alGetEnumValue("AL_FORMAT_61CHN16"); break; - case 8: format = alGetEnumValue("AL_FORMAT_71CHN16"); break; - default: format = 0; break; + // Find the good format according to the number of channels + int format = 0; + switch (channelCount) + { + case 1: format = AL_FORMAT_MONO16; break; + case 2: format = AL_FORMAT_STEREO16; break; + case 4: format = alGetEnumValue("AL_FORMAT_QUAD16"); break; + case 6: format = alGetEnumValue("AL_FORMAT_51CHN16"); break; + case 7: format = alGetEnumValue("AL_FORMAT_61CHN16"); break; + case 8: format = alGetEnumValue("AL_FORMAT_71CHN16"); break; + default: format = 0; break; + } + + // Fixes a bug on OS X + if (format == -1) + format = 0; + + return format; + }; + + if (!audioDevice) + { + // Create a temporary audio device in case none exists yet. + // This device will not be used in this function and merely + // makes sure there is a valid OpenAL device for format + // queries if none has been created yet. + AudioDevice device; + + return getFormat(); } - // Fixes a bug on OS X - if (format == -1) - format = 0; - - return format; + return getFormat(); } From 2ef0d365691712c5a9e788799ebb51a6925bec81 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sat, 1 Apr 2017 22:10:43 +0200 Subject: [PATCH 05/18] Remove synchronization that became unnecessary since C++11. --- src/SFML/Graphics/Shader.cpp | 66 ++++++++++------------------------- src/SFML/Graphics/Texture.cpp | 17 ++++----- 2 files changed, 25 insertions(+), 58 deletions(-) diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 92b92dbf..78770a6a 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -56,28 +56,6 @@ namespace { - sf::Mutex maxTextureUnitsMutex; - sf::Mutex isAvailableMutex; - - GLint checkMaxTextureUnits() - { - GLint maxUnits = 0; - glCheck(glGetIntegerv(GLEXT_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxUnits)); - - return maxUnits; - } - - // Retrieve the maximum number of texture units available - GLint getMaxTextureUnits() - { - // TODO: Remove this lock when it becomes unnecessary in C++11 - sf::Lock lock(maxTextureUnitsMutex); - - static GLint maxUnits = checkMaxTextureUnits(); - - return maxUnits; - } - // Read the contents of a file into an array of char bool getFileContents(const std::string& filename, std::vector& buffer) { @@ -556,7 +534,15 @@ void Shader::setUniform(const std::string& name, const Texture& texture) if (it == m_textures.end()) { // New entry, make sure there are enough texture units - GLint maxUnits = getMaxTextureUnits(); + const static auto maxUnits = [] + { + // Retrieve the maximum number of texture units available + GLint maxUnits = 0; + glCheck(glGetIntegerv(GLEXT_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxUnits)); + + return maxUnits; + }(); + if (m_textures.size() + 1 >= static_cast(maxUnits)) { err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl; @@ -773,26 +759,19 @@ void Shader::bind(const Shader* shader) //////////////////////////////////////////////////////////// bool Shader::isAvailable() { - Lock lock(isAvailableMutex); - - static bool checked = false; - static bool available = false; - - if (!checked) + const static auto available = [] { - checked = true; - TransientContextLock contextLock; // Make sure that extensions are initialized sf::priv::ensureExtensionsInit(); - available = GLEXT_multitexture && - GLEXT_shading_language_100 && - GLEXT_shader_objects && - GLEXT_vertex_shader && - GLEXT_fragment_shader; - } + return GLEXT_multitexture && + GLEXT_shading_language_100 && + GLEXT_shader_objects && + GLEXT_vertex_shader && + GLEXT_fragment_shader; + }(); return available; } @@ -801,22 +780,15 @@ bool Shader::isAvailable() //////////////////////////////////////////////////////////// bool Shader::isGeometryAvailable() { - Lock lock(isAvailableMutex); - - static bool checked = false; - static bool available = false; - - if (!checked) + const static auto available = [] { - checked = true; - TransientContextLock contextLock; // Make sure that extensions are initialized sf::priv::ensureExtensionsInit(); - available = isAvailable() && GLEXT_geometry_shader4; - } + return isAvailable() && GLEXT_geometry_shader4; + }(); return available; } diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 2caba165..66f11370 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -41,7 +41,6 @@ namespace { sf::Mutex idMutex; - sf::Mutex maximumSizeMutex; // Thread-safe unique identifier generator, // is used for states cache (see RenderTarget) @@ -776,21 +775,17 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType) //////////////////////////////////////////////////////////// unsigned int Texture::getMaximumSize() { - Lock lock(maximumSizeMutex); - - static bool checked = false; - static GLint size = 0; - - if (!checked) + const static auto size = [] { - checked = true; - TransientContextLock lock; + GLint size; glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size)); - } - return static_cast(size); + return static_cast(size); + }(); + + return size; } From d6dcafbc905850f8b9d9342d67497217d75c68fb Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sat, 1 Apr 2017 22:34:41 +0200 Subject: [PATCH 06/18] Replaced function-local static variables with C++11 constructs. --- src/SFML/Audio/SoundFileFactory.cpp | 8 ++--- src/SFML/Audio/SoundFileWriterOgg.cpp | 2 +- src/SFML/Graphics/CircleShape.cpp | 2 +- src/SFML/Graphics/GLExtensions.cpp | 10 +++---- src/SFML/Graphics/RenderTarget.cpp | 12 ++++---- src/SFML/Graphics/Shader.cpp | 6 ++-- src/SFML/Graphics/Texture.cpp | 36 +++++++++-------------- src/SFML/System/Err.cpp | 2 +- src/SFML/System/Win32/ClockImpl.cpp | 34 ++++++++------------- src/SFML/Window/VideoMode.cpp | 9 +++--- src/SFML/Window/Win32/WglContext.cpp | 27 ++++++++--------- src/SFML/Window/Win32/WindowImplWin32.cpp | 2 +- 12 files changed, 64 insertions(+), 86 deletions(-) diff --git a/src/SFML/Audio/SoundFileFactory.cpp b/src/SFML/Audio/SoundFileFactory.cpp index 10b1c1e1..181e7775 100644 --- a/src/SFML/Audio/SoundFileFactory.cpp +++ b/src/SFML/Audio/SoundFileFactory.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace @@ -42,8 +43,8 @@ namespace // Register all the built-in readers and writers if not already done void ensureDefaultReadersWritersRegistered() { - static bool registered = false; - if (!registered) + static std::once_flag registered; + std::call_once(registered, [] { sf::SoundFileFactory::registerReader(); sf::SoundFileFactory::registerWriter(); @@ -51,8 +52,7 @@ namespace sf::SoundFileFactory::registerWriter(); sf::SoundFileFactory::registerReader(); sf::SoundFileFactory::registerWriter(); - registered = true; - } + }); } } diff --git a/src/SFML/Audio/SoundFileWriterOgg.cpp b/src/SFML/Audio/SoundFileWriterOgg.cpp index c661b746..a5cbf15b 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.cpp +++ b/src/SFML/Audio/SoundFileWriterOgg.cpp @@ -131,7 +131,7 @@ bool SoundFileWriterOgg::open(const std::string& filename, unsigned int sampleRa void SoundFileWriterOgg::write(const Int16* samples, Uint64 count) { // Vorbis has issues with buffers that are too large, so we ask for 64K - static const int bufferSize = 65536; + constexpr auto bufferSize = 65536; // A frame contains a sample from each channel int frameCount = static_cast(count / m_channelCount); diff --git a/src/SFML/Graphics/CircleShape.cpp b/src/SFML/Graphics/CircleShape.cpp index 8e555105..2e8b1ca3 100644 --- a/src/SFML/Graphics/CircleShape.cpp +++ b/src/SFML/Graphics/CircleShape.cpp @@ -72,7 +72,7 @@ std::size_t CircleShape::getPointCount() const //////////////////////////////////////////////////////////// Vector2f CircleShape::getPoint(std::size_t index) const { - static const float pi = 3.141592654f; + constexpr auto pi = 3.141592654f; float angle = index * 2 * pi / m_pointCount - pi / 2; float x = std::cos(angle) * m_radius; diff --git a/src/SFML/Graphics/GLExtensions.cpp b/src/SFML/Graphics/GLExtensions.cpp index 57f5bcc7..c8f41152 100644 --- a/src/SFML/Graphics/GLExtensions.cpp +++ b/src/SFML/Graphics/GLExtensions.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #if !defined(GL_MAJOR_VERSION) #define GL_MAJOR_VERSION 0x821B @@ -46,11 +47,10 @@ namespace priv void ensureExtensionsInit() { #if !defined(SFML_OPENGL_ES) - static bool initialized = false; - if (!initialized) - { - initialized = true; + static std::once_flag initialized; + std::call_once(initialized, [] + { sfogl_LoadFunctions(); // Retrieve the context version number @@ -84,7 +84,7 @@ void ensureExtensionsInit() err() << "sfml-graphics requires support for OpenGL 1.1 or greater" << std::endl; err() << "Ensure that hardware acceleration is enabled if available" << std::endl; } - } + }); #endif } diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 08009a58..146f48a2 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace { @@ -279,7 +280,7 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, } // Find the OpenGL primitive type - static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, + constexpr GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS}; GLenum mode = modes[type]; @@ -461,16 +462,13 @@ void RenderTarget::applyBlendMode(const BlendMode& mode) } else if ((mode.colorEquation != BlendMode::Add) || (mode.alphaEquation != BlendMode::Add)) { - static bool warned = false; - - if (!warned) + static std::once_flag warned; + std::call_once(warned, [] { err() << "OpenGL extension EXT_blend_minmax and/or EXT_blend_subtract unavailable" << std::endl; err() << "Selecting a blend equation not possible" << std::endl; err() << "Ensure that hardware acceleration is enabled if available" << std::endl; - - warned = true; - } + }); } m_cache.lastBlendMode = mode; diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 78770a6a..5d36e14c 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -534,7 +534,7 @@ void Shader::setUniform(const std::string& name, const Texture& texture) if (it == m_textures.end()) { // New entry, make sure there are enough texture units - const static auto maxUnits = [] + static const auto maxUnits = [] { // Retrieve the maximum number of texture units available GLint maxUnits = 0; @@ -759,7 +759,7 @@ void Shader::bind(const Shader* shader) //////////////////////////////////////////////////////////// bool Shader::isAvailable() { - const static auto available = [] + static const auto available = [] { TransientContextLock contextLock; @@ -780,7 +780,7 @@ bool Shader::isAvailable() //////////////////////////////////////////////////////////// bool Shader::isGeometryAvailable() { - const static auto available = [] + static const auto available = [] { TransientContextLock contextLock; diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 66f11370..8825d75a 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -36,6 +36,7 @@ #include #include #include +#include namespace @@ -165,29 +166,25 @@ bool Texture::create(unsigned int width, unsigned int height) // Make sure that the current texture binding will be preserved priv::TextureSaver save; - static bool textureEdgeClamp = GLEXT_texture_edge_clamp || GLEXT_EXT_texture_edge_clamp; + static const auto textureEdgeClamp = GLEXT_texture_edge_clamp || GLEXT_EXT_texture_edge_clamp; if (!m_isRepeated && !textureEdgeClamp) { - static bool warned = false; - - if (!warned) + std::once_flag warned; + std::call_once(warned, [] { err() << "OpenGL extension SGIS_texture_edge_clamp unavailable" << std::endl; err() << "Artifacts may occur along texture edges" << std::endl; err() << "Ensure that hardware acceleration is enabled if available" << std::endl; - - warned = true; - } + }); } - static bool textureSrgb = GLEXT_texture_sRGB; + static const auto textureSrgb = GLEXT_texture_sRGB; if (m_sRgb && !textureSrgb) { - static bool warned = false; - - if (!warned) + std::once_flag warned; + std::call_once(warned, [] { #ifndef SFML_OPENGL_ES err() << "OpenGL extension EXT_texture_sRGB unavailable" << std::endl; @@ -195,9 +192,7 @@ bool Texture::create(unsigned int width, unsigned int height) err() << "OpenGL ES extension EXT_sRGB unavailable" << std::endl; #endif err() << "Automatic sRGB to linear conversion disabled" << std::endl; - - warned = true; - } + }); m_sRgb = false; } @@ -640,20 +635,17 @@ void Texture::setRepeated(bool repeated) // Make sure that the current texture binding will be preserved priv::TextureSaver save; - static bool textureEdgeClamp = GLEXT_texture_edge_clamp || GLEXT_EXT_texture_edge_clamp; + static const auto textureEdgeClamp = GLEXT_texture_edge_clamp || GLEXT_EXT_texture_edge_clamp; if (!m_isRepeated && !textureEdgeClamp) { - static bool warned = false; - - if (!warned) + std::once_flag warned; + std::call_once(warned, [] { err() << "OpenGL extension SGIS_texture_edge_clamp unavailable" << std::endl; err() << "Artifacts may occur along texture edges" << std::endl; err() << "Ensure that hardware acceleration is enabled if available" << std::endl; - - warned = true; - } + }); } glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); @@ -775,7 +767,7 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType) //////////////////////////////////////////////////////////// unsigned int Texture::getMaximumSize() { - const static auto size = [] + static const auto size = [] { TransientContextLock lock; diff --git a/src/SFML/System/Err.cpp b/src/SFML/System/Err.cpp index 5d2084ec..51be9aa3 100644 --- a/src/SFML/System/Err.cpp +++ b/src/SFML/System/Err.cpp @@ -41,7 +41,7 @@ public: DefaultErrStreamBuf() { // Allocate the write buffer - static const int size = 64; + constexpr auto size = 64; char* buffer = new char[size]; setp(buffer, buffer + size); } diff --git a/src/SFML/System/Win32/ClockImpl.cpp b/src/SFML/System/Win32/ClockImpl.cpp index 8098a7d4..c81288d2 100644 --- a/src/SFML/System/Win32/ClockImpl.cpp +++ b/src/SFML/System/Win32/ClockImpl.cpp @@ -30,25 +30,6 @@ #include #include - -namespace -{ - sf::Mutex oldWindowsMutex; - - LARGE_INTEGER getFrequency() - { - LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); - return frequency; - } - - bool isWindowsXpOrOlder() - { - // Windows XP was the last 5.x version of Windows - return static_cast(LOBYTE(LOWORD(GetVersion()))) < 6; - } -} - namespace sf { namespace priv @@ -58,15 +39,26 @@ Time ClockImpl::getCurrentTime() { // Get the frequency of the performance counter // (it is constant across the program lifetime) - static LARGE_INTEGER frequency = getFrequency(); + static const auto frequency = [] + { + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + return frequency; + }(); // Detect if we are on Windows XP or older - static bool oldWindows = isWindowsXpOrOlder(); + static const auto oldWindows = [] + { + // Windows XP was the last 5.x version of Windows + return static_cast(LOBYTE(LOWORD(GetVersion()))) < 6; + }(); LARGE_INTEGER time; if (oldWindows) { + static sf::Mutex oldWindowsMutex; + // Acquire a lock (CRITICAL_SECTION) to prevent travelling back in time Lock lock(oldWindowsMutex); diff --git a/src/SFML/Window/VideoMode.cpp b/src/SFML/Window/VideoMode.cpp index 01103892..968919c6 100644 --- a/src/SFML/Window/VideoMode.cpp +++ b/src/SFML/Window/VideoMode.cpp @@ -64,14 +64,13 @@ VideoMode VideoMode::getDesktopMode() //////////////////////////////////////////////////////////// const std::vector& VideoMode::getFullscreenModes() { - static std::vector modes; - // Populate the array on first call - if (modes.empty()) + static const auto modes = [] { - modes = priv::VideoModeImpl::getFullscreenModes(); + auto modes = priv::VideoModeImpl::getFullscreenModes(); std::sort(modes.begin(), modes.end(), std::greater()); - } + return modes; + }(); return modes; } diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index 3e07c48a..c2a813f7 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace @@ -51,15 +52,13 @@ namespace priv //////////////////////////////////////////////////////////// void ensureExtensionsInit(HDC deviceContext) { - static bool initialized = false; - if (!initialized) + std::once_flag initialized; + std::call_once(initialized, [deviceContext] { - initialized = true; - // We don't check the return value since the extension // flags are cleared even if loading fails sfwgl_LoadFunctions(deviceContext); - } + }); } @@ -200,10 +199,11 @@ GlFunctionPointer WglContext::getFunction(const char* name) return address; } - static HMODULE module = NULL; - - if (!module) - module = GetModuleHandleA("OpenGL32.dll"); + static const auto module = [] + { + return GetModuleHandleA("OpenGL32.dll"); + }(); + if (module) return reinterpret_cast(GetProcAddress(module, reinterpret_cast(name))); @@ -251,15 +251,12 @@ void WglContext::setVerticalSyncEnabled(bool enabled) } else { - static bool warned = false; - - if (!warned) + std::once_flag warned; + std::call_once(warned, [] { // wglSwapIntervalEXT not supported err() << "Setting vertical sync not supported" << std::endl; - - warned = true; - } + }); } } diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index f8669b21..f21a85b3 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -984,7 +984,7 @@ Keyboard::Key WindowImplWin32::virtualKeyCodeToSF(WPARAM key, LPARAM flags) // Check the scancode to distinguish between left and right shift case VK_SHIFT: { - static UINT lShift = MapVirtualKeyW(VK_LSHIFT, MAPVK_VK_TO_VSC); + static const auto lShift = MapVirtualKeyW(VK_LSHIFT, MAPVK_VK_TO_VSC); UINT scancode = static_cast((flags & (0xFF << 16)) >> 16); return scancode == lShift ? Keyboard::LShift : Keyboard::RShift; } From a4acac813e30082a551646aaa74b28c59e97b209 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sun, 2 Apr 2017 01:12:29 +0200 Subject: [PATCH 07/18] Removed all manual memory management. --- examples/shader/Shader.cpp | 17 +++---- include/SFML/Audio/InputSoundFile.hpp | 15 +++--- include/SFML/Audio/OutputSoundFile.hpp | 3 +- include/SFML/Audio/SoundFileFactory.hpp | 13 ++--- include/SFML/Audio/SoundFileFactory.inl | 4 +- include/SFML/Graphics/Font.hpp | 7 +-- include/SFML/Graphics/Image.hpp | 8 +-- include/SFML/Graphics/RenderTexture.hpp | 5 +- include/SFML/Network/SocketSelector.hpp | 3 +- include/SFML/System/FileInputStream.hpp | 3 +- include/SFML/System/Mutex.hpp | 3 +- include/SFML/System/Thread.hpp | 5 +- include/SFML/System/Thread.inl | 9 ++-- include/SFML/System/ThreadLocal.hpp | 3 +- include/SFML/Window/Context.hpp | 3 +- include/SFML/Window/Window.hpp | 11 ++-- src/SFML/Audio/AlResource.cpp | 7 +-- src/SFML/Audio/InputSoundFile.cpp | 34 ++++++------- src/SFML/Audio/OutputSoundFile.cpp | 8 ++- src/SFML/Audio/SoundFileFactory.cpp | 8 +-- src/SFML/Graphics/Font.cpp | 43 ++++------------ src/SFML/Graphics/Image.cpp | 22 ++------ src/SFML/Graphics/RenderTexture.cpp | 16 ++---- .../Graphics/RenderTextureImplDefault.cpp | 11 +--- .../Graphics/RenderTextureImplDefault.hpp | 13 ++--- src/SFML/Graphics/RenderTextureImplFBO.cpp | 6 +-- src/SFML/Graphics/RenderTextureImplFBO.hpp | 7 +-- src/SFML/Network/SocketSelector.cpp | 9 ++-- src/SFML/System/Err.cpp | 10 ++-- src/SFML/System/FileInputStream.cpp | 9 +--- src/SFML/System/Mutex.cpp | 7 +-- src/SFML/System/Thread.cpp | 9 ++-- src/SFML/System/ThreadLocal.cpp | 7 +-- src/SFML/Window/Context.cpp | 1 - src/SFML/Window/GlContext.cpp | 50 +++++++------------ src/SFML/Window/GlContext.hpp | 7 +-- src/SFML/Window/Window.cpp | 20 +++----- src/SFML/Window/WindowImpl.cpp | 8 +-- src/SFML/Window/WindowImpl.hpp | 6 ++- 39 files changed, 163 insertions(+), 267 deletions(-) diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index 8a81fde3..0b8fd4f1 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -5,6 +5,7 @@ #include "Effect.hpp" #include #include +#include const sf::Font* Effect::s_font = NULL; @@ -357,12 +358,12 @@ int main() Effect::setFont(font); // Create the effects - std::vector effects; - effects.push_back(new Pixelate); - effects.push_back(new WaveBlur); - effects.push_back(new StormBlink); - effects.push_back(new Edge); - effects.push_back(new Geometry); + std::vector> effects; + effects.push_back(std::make_unique()); + effects.push_back(std::make_unique()); + effects.push_back(std::make_unique()); + effects.push_back(std::make_unique()); + effects.push_back(std::make_unique()); std::size_t current = 0; // Initialize them @@ -452,9 +453,5 @@ int main() window.display(); } - // delete the effects - for (std::size_t i = 0; i < effects.size(); ++i) - delete effects[i]; - return EXIT_SUCCESS; } diff --git a/include/SFML/Audio/InputSoundFile.hpp b/include/SFML/Audio/InputSoundFile.hpp index 031c85f4..9ef1d97a 100644 --- a/include/SFML/Audio/InputSoundFile.hpp +++ b/include/SFML/Audio/InputSoundFile.hpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace sf @@ -217,13 +218,13 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - SoundFileReader* m_reader; ///< Reader that handles I/O on the file's format - InputStream* m_stream; ///< Input stream used to access the file's data - bool m_streamOwned; ///< Is the stream internal or external? - Uint64 m_sampleOffset; ///< Sample Read Position - Uint64 m_sampleCount; ///< Total number of samples in the file - unsigned int m_channelCount; ///< Number of channels of the sound - unsigned int m_sampleRate; ///< Number of samples per second + std::unique_ptr m_reader; ///< Reader that handles I/O on the file's format + std::unique_ptr m_ownedStream; ///< The stream we own if any + InputStream* m_stream; ///< Input stream used to access the file's data + Uint64 m_sampleOffset; ///< Sample Read Position + Uint64 m_sampleCount; ///< Total number of samples in the file + unsigned int m_channelCount; ///< Number of channels of the sound + unsigned int m_sampleRate; ///< Number of samples per second }; } // namespace sf diff --git a/include/SFML/Audio/OutputSoundFile.hpp b/include/SFML/Audio/OutputSoundFile.hpp index 325b38f0..c2044060 100644 --- a/include/SFML/Audio/OutputSoundFile.hpp +++ b/include/SFML/Audio/OutputSoundFile.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace sf @@ -93,7 +94,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - SoundFileWriter* m_writer; ///< Writer that handles I/O on the file's format + std::unique_ptr m_writer; ///< Writer that handles I/O on the file's format }; } // namespace sf diff --git a/include/SFML/Audio/SoundFileFactory.hpp b/include/SFML/Audio/SoundFileFactory.hpp index b4eadf0f..08d4cf5a 100644 --- a/include/SFML/Audio/SoundFileFactory.hpp +++ b/include/SFML/Audio/SoundFileFactory.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace sf @@ -95,7 +96,7 @@ public: /// \see createReaderFromMemory, createReaderFromStream /// //////////////////////////////////////////////////////////// - static SoundFileReader* createReaderFromFilename(const std::string& filename); + static std::unique_ptr createReaderFromFilename(const std::string& filename); //////////////////////////////////////////////////////////// /// \brief Instantiate the right codec for the given file in memory @@ -110,7 +111,7 @@ public: /// \see createReaderFromFilename, createReaderFromStream /// //////////////////////////////////////////////////////////// - static SoundFileReader* createReaderFromMemory(const void* data, std::size_t sizeInBytes); + static std::unique_ptr createReaderFromMemory(const void* data, std::size_t sizeInBytes); //////////////////////////////////////////////////////////// /// \brief Instantiate the right codec for the given file in stream @@ -124,7 +125,7 @@ public: /// \see createReaderFromFilename, createReaderFromMemory /// //////////////////////////////////////////////////////////// - static SoundFileReader* createReaderFromStream(InputStream& stream); + static std::unique_ptr createReaderFromStream(InputStream& stream); //////////////////////////////////////////////////////////// /// \brief Instantiate the right writer for the given file on disk @@ -136,7 +137,7 @@ public: /// \return A new sound file writer that can write given file, or null if no writer can handle it /// //////////////////////////////////////////////////////////// - static SoundFileWriter* createWriterFromFilename(const std::string& filename); + static std::unique_ptr createWriterFromFilename(const std::string& filename); private: @@ -146,14 +147,14 @@ private: struct ReaderFactory { bool (*check)(InputStream&); - SoundFileReader* (*create)(); + std::unique_ptr (*create)(); }; typedef std::vector ReaderFactoryArray; struct WriterFactory { bool (*check)(const std::string&); - SoundFileWriter* (*create)(); + std::unique_ptr (*create)(); }; typedef std::vector WriterFactoryArray; diff --git a/include/SFML/Audio/SoundFileFactory.inl b/include/SFML/Audio/SoundFileFactory.inl index a552ba87..3fb84726 100644 --- a/include/SFML/Audio/SoundFileFactory.inl +++ b/include/SFML/Audio/SoundFileFactory.inl @@ -31,8 +31,8 @@ namespace sf { namespace priv { - template SoundFileReader* createReader() {return new T;} - template SoundFileWriter* createWriter() {return new T;} + template std::unique_ptr createReader() {return std::make_unique();} + template std::unique_ptr createWriter() {return std::make_unique();} } //////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index 9451f08c..18373855 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -37,6 +37,7 @@ #include #include #include +#include namespace sf @@ -348,14 +349,14 @@ private: //////////////////////////////////////////////////////////// void* m_library; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details) void* m_face; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details) - void* m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details) + std::shared_ptr m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details) void* m_stroker; ///< Pointer to the stroker (it is typeless to avoid exposing implementation details) - int* m_refCount; ///< Reference counter used by implicit sharing + std::shared_ptr m_refCount; ///< Reference counter used by implicit sharing Info m_info; ///< Information about the font mutable PageTable m_pages; ///< Table containing the glyphs pages by character size mutable std::vector m_pixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture #ifdef SFML_SYSTEM_ANDROID - void* m_stream; ///< Asset file streamer (if loaded from file) + std::shared_ptr m_stream; ///< Asset file streamer (if loaded from file) #endif }; diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index a9010c0d..a2127d86 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -33,7 +33,7 @@ #include #include #include - +#include namespace sf { @@ -263,10 +263,10 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Vector2u m_size; ///< Image size - std::vector m_pixels; ///< Pixels of the image + Vector2u m_size; ///< Image size + std::vector m_pixels; ///< Pixels of the image #ifdef SFML_SYSTEM_ANDROID - void* m_stream; ///< Asset file streamer (if loaded from file) + std::shared_ptr m_stream; ///< Asset file streamer (if loaded from file) #endif }; diff --git a/include/SFML/Graphics/RenderTexture.hpp b/include/SFML/Graphics/RenderTexture.hpp index 52d53bd1..040317a3 100644 --- a/include/SFML/Graphics/RenderTexture.hpp +++ b/include/SFML/Graphics/RenderTexture.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace sf @@ -207,8 +208,8 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - priv::RenderTextureImpl* m_impl; ///< Platform/hardware specific implementation - Texture m_texture; ///< Target texture to draw on + std::unique_ptr m_impl; ///< Platform/hardware specific implementation + Texture m_texture; ///< Target texture to draw on }; } // namespace sf diff --git a/include/SFML/Network/SocketSelector.hpp b/include/SFML/Network/SocketSelector.hpp index 92dcbad9..1936fb54 100644 --- a/include/SFML/Network/SocketSelector.hpp +++ b/include/SFML/Network/SocketSelector.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include namespace sf @@ -158,7 +159,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - SocketSelectorImpl* m_impl; ///< Opaque pointer to the implementation (which requires OS-specific types) + std::unique_ptr m_impl; ///< Opaque pointer to the implementation (which requires OS-specific types) }; } // namespace sf diff --git a/include/SFML/System/FileInputStream.hpp b/include/SFML/System/FileInputStream.hpp index b1a8c62c..c931dd80 100644 --- a/include/SFML/System/FileInputStream.hpp +++ b/include/SFML/System/FileInputStream.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #ifdef ANDROID namespace sf @@ -123,7 +124,7 @@ private: // Member data //////////////////////////////////////////////////////////// #ifdef ANDROID - priv::ResourceStream* m_file; + std::unique_ptr m_file; #else std::FILE* m_file; ///< stdio file stream #endif diff --git a/include/SFML/System/Mutex.hpp b/include/SFML/System/Mutex.hpp index 18349e42..7ac8e8ad 100644 --- a/include/SFML/System/Mutex.hpp +++ b/include/SFML/System/Mutex.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include namespace sf @@ -85,7 +86,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - priv::MutexImpl* m_mutexImpl; ///< OS-specific implementation + std::shared_ptr m_mutexImpl; ///< OS-specific implementation }; } // namespace sf diff --git a/include/SFML/System/Thread.hpp b/include/SFML/System/Thread.hpp index 65c91271..45c5d62f 100644 --- a/include/SFML/System/Thread.hpp +++ b/include/SFML/System/Thread.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace sf @@ -186,8 +187,8 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - priv::ThreadImpl* m_impl; ///< OS-specific implementation of the thread - priv::ThreadFunc* m_entryPoint; ///< Abstraction of the function to run + std::shared_ptr m_impl; ///< OS-specific implementation of the thread + std::shared_ptr m_entryPoint; ///< Abstraction of the function to run }; #include diff --git a/include/SFML/System/Thread.inl b/include/SFML/System/Thread.inl index b707aa30..fd3602fe 100644 --- a/include/SFML/System/Thread.inl +++ b/include/SFML/System/Thread.inl @@ -66,8 +66,7 @@ struct ThreadMemberFunc : ThreadFunc //////////////////////////////////////////////////////////// template Thread::Thread(F functor) : -m_impl (NULL), -m_entryPoint(new priv::ThreadFunctor(functor)) +m_entryPoint(std::make_shared>(functor)) { } @@ -75,8 +74,7 @@ m_entryPoint(new priv::ThreadFunctor(functor)) //////////////////////////////////////////////////////////// template Thread::Thread(F function, A argument) : -m_impl (NULL), -m_entryPoint(new priv::ThreadFunctorWithArg(function, argument)) +m_entryPoint(std::make_shared>(function, argument)) { } @@ -84,7 +82,6 @@ m_entryPoint(new priv::ThreadFunctorWithArg(function, argument)) //////////////////////////////////////////////////////////// template Thread::Thread(void(C::*function)(), C* object) : -m_impl (NULL), -m_entryPoint(new priv::ThreadMemberFunc(function, object)) +m_entryPoint(std::make_shared>(function, object)) { } diff --git a/include/SFML/System/ThreadLocal.hpp b/include/SFML/System/ThreadLocal.hpp index 6975e524..160abdfd 100644 --- a/include/SFML/System/ThreadLocal.hpp +++ b/include/SFML/System/ThreadLocal.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace sf @@ -83,7 +84,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - priv::ThreadLocalImpl* m_impl; ///< Pointer to the OS specific implementation + std::unique_ptr m_impl; ///< Pointer to the OS specific implementation }; } // namespace sf diff --git a/include/SFML/Window/Context.hpp b/include/SFML/Window/Context.hpp index 9e1eedd4..53e6177b 100644 --- a/include/SFML/Window/Context.hpp +++ b/include/SFML/Window/Context.hpp @@ -32,6 +32,7 @@ #include #include #include +#include namespace sf @@ -135,7 +136,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - priv::GlContext* m_context; ///< Internal OpenGL context + std::unique_ptr m_context; ///< Internal OpenGL context }; } // namespace sf diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index 7135fdfe..5b0824f2 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -38,6 +38,7 @@ #include #include #include +#include namespace sf @@ -522,11 +523,11 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - priv::WindowImpl* m_impl; ///< Platform-specific implementation of the window - priv::GlContext* m_context; ///< Platform-specific implementation of the OpenGL context - Clock m_clock; ///< Clock for measuring the elapsed time between frames - Time m_frameTimeLimit; ///< Current framerate limit - Vector2u m_size; ///< Current size of the window + std::unique_ptr m_impl; ///< Platform-specific implementation of the window + std::unique_ptr m_context; ///< Platform-specific implementation of the OpenGL context + Clock m_clock; ///< Clock for measuring the elapsed time between frames + Time m_frameTimeLimit; ///< Current framerate limit + Vector2u m_size; ///< Current size of the window }; } // namespace sf diff --git a/src/SFML/Audio/AlResource.cpp b/src/SFML/Audio/AlResource.cpp index df50be0a..6dd1d207 100644 --- a/src/SFML/Audio/AlResource.cpp +++ b/src/SFML/Audio/AlResource.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace @@ -40,7 +41,7 @@ namespace // The audio device is instantiated on demand rather than at global startup, // which solves a lot of weird crashes and errors. // It is destroyed when it is no longer needed. - sf::priv::AudioDevice* globalDevice; + std::unique_ptr globalDevice; } @@ -54,7 +55,7 @@ AlResource::AlResource() // If this is the very first resource, trigger the global device initialization if (count == 0) - globalDevice = new priv::AudioDevice; + globalDevice = std::make_unique(); // Increment the resources counter count++; @@ -72,7 +73,7 @@ AlResource::~AlResource() // If there's no more resource alive, we can destroy the device if (count == 0) - delete globalDevice; + globalDevice.reset(); } } // namespace sf diff --git a/src/SFML/Audio/InputSoundFile.cpp b/src/SFML/Audio/InputSoundFile.cpp index 43a3388f..c75e9cc4 100644 --- a/src/SFML/Audio/InputSoundFile.cpp +++ b/src/SFML/Audio/InputSoundFile.cpp @@ -38,10 +38,8 @@ namespace sf { //////////////////////////////////////////////////////////// InputSoundFile::InputSoundFile() : -m_reader (NULL), -m_stream (NULL), -m_streamOwned (false), -m_sampleOffset (0), +m_stream (nullptr), +m_sampleOffset(0), m_sampleCount (0), m_channelCount(0), m_sampleRate (0) @@ -69,9 +67,7 @@ bool InputSoundFile::openFromFile(const std::string& filename) return false; // Wrap the file into a stream - FileInputStream* file = new FileInputStream; - m_stream = file; - m_streamOwned = true; + auto file = std::make_unique(); // Open it if (!file->open(filename)) @@ -93,6 +89,9 @@ bool InputSoundFile::openFromFile(const std::string& filename) m_channelCount = info.channelCount; m_sampleRate = info.sampleRate; + m_ownedStream = std::move(file); + m_stream = m_ownedStream.get(); + return true; } @@ -109,9 +108,7 @@ bool InputSoundFile::openFromMemory(const void* data, std::size_t sizeInBytes) return false; // Wrap the memory file into a stream - MemoryInputStream* memory = new MemoryInputStream; - m_stream = memory; - m_streamOwned = true; + auto memory = std::make_unique(); // Open it memory->open(data, sizeInBytes); @@ -129,6 +126,9 @@ bool InputSoundFile::openFromMemory(const void* data, std::size_t sizeInBytes) m_channelCount = info.channelCount; m_sampleRate = info.sampleRate; + m_ownedStream = std::move(memory); + m_stream = m_ownedStream.get(); + return true; } @@ -146,7 +146,6 @@ bool InputSoundFile::openFromStream(InputStream& stream) // store the stream m_stream = &stream; - m_streamOwned = false; // Don't forget to reset the stream to its beginning before re-opening it if (stream.seek(0) != 0) @@ -257,16 +256,11 @@ Uint64 InputSoundFile::read(Int16* samples, Uint64 maxCount) void InputSoundFile::close() { // Destroy the reader - delete m_reader; - m_reader = NULL; + m_reader.reset(); - // Destroy the stream if we own it - if (m_streamOwned) - { - delete m_stream; - m_streamOwned = false; - } - m_stream = NULL; + m_ownedStream.reset(); + + m_stream = nullptr; m_sampleOffset = 0; // Reset the sound file attributes diff --git a/src/SFML/Audio/OutputSoundFile.cpp b/src/SFML/Audio/OutputSoundFile.cpp index 870e622e..2f5a340d 100644 --- a/src/SFML/Audio/OutputSoundFile.cpp +++ b/src/SFML/Audio/OutputSoundFile.cpp @@ -33,8 +33,7 @@ namespace sf { //////////////////////////////////////////////////////////// -OutputSoundFile::OutputSoundFile() : -m_writer(NULL) +OutputSoundFile::OutputSoundFile() { } @@ -80,9 +79,8 @@ void OutputSoundFile::write(const Int16* samples, Uint64 count) //////////////////////////////////////////////////////////// void OutputSoundFile::close() { - // Destroy the reader - delete m_writer; - m_writer = NULL; + // Destroy the writer + m_writer.reset(); } } // namespace sf diff --git a/src/SFML/Audio/SoundFileFactory.cpp b/src/SFML/Audio/SoundFileFactory.cpp index 181e7775..d2b1fc84 100644 --- a/src/SFML/Audio/SoundFileFactory.cpp +++ b/src/SFML/Audio/SoundFileFactory.cpp @@ -63,7 +63,7 @@ SoundFileFactory::WriterFactoryArray SoundFileFactory::s_writers; //////////////////////////////////////////////////////////// -SoundFileReader* SoundFileFactory::createReaderFromFilename(const std::string& filename) +std::unique_ptr SoundFileFactory::createReaderFromFilename(const std::string& filename) { // Register the built-in readers/writers on first call ensureDefaultReadersWritersRegistered(); @@ -90,7 +90,7 @@ SoundFileReader* SoundFileFactory::createReaderFromFilename(const std::string& f //////////////////////////////////////////////////////////// -SoundFileReader* SoundFileFactory::createReaderFromMemory(const void* data, std::size_t sizeInBytes) +std::unique_ptr SoundFileFactory::createReaderFromMemory(const void* data, std::size_t sizeInBytes) { // Register the built-in readers/writers on first call ensureDefaultReadersWritersRegistered(); @@ -114,7 +114,7 @@ SoundFileReader* SoundFileFactory::createReaderFromMemory(const void* data, std: //////////////////////////////////////////////////////////// -SoundFileReader* SoundFileFactory::createReaderFromStream(InputStream& stream) +std::unique_ptr SoundFileFactory::createReaderFromStream(InputStream& stream) { // Register the built-in readers/writers on first call ensureDefaultReadersWritersRegistered(); @@ -134,7 +134,7 @@ SoundFileReader* SoundFileFactory::createReaderFromStream(InputStream& stream) //////////////////////////////////////////////////////////// -SoundFileWriter* SoundFileFactory::createWriterFromFilename(const std::string& filename) +std::unique_ptr SoundFileFactory::createWriterFromFilename(const std::string& filename) { // Register the built-in readers/writers on first call ensureDefaultReadersWritersRegistered(); diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index bf182333..4829a526 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -70,14 +70,9 @@ namespace sf Font::Font() : m_library (NULL), m_face (NULL), -m_streamRec(NULL), m_stroker (NULL), -m_refCount (NULL), m_info () { - #ifdef SFML_SYSTEM_ANDROID - m_stream = NULL; - #endif } @@ -92,10 +87,6 @@ m_info (copy.m_info), m_pages (copy.m_pages), m_pixelBuffer(copy.m_pixelBuffer) { - #ifdef SFML_SYSTEM_ANDROID - m_stream = NULL; - #endif - // Note: as FreeType doesn't provide functions for copying/cloning, // we must share all the FreeType pointers @@ -108,13 +99,6 @@ m_pixelBuffer(copy.m_pixelBuffer) Font::~Font() { cleanup(); - - #ifdef SFML_SYSTEM_ANDROID - - if (m_stream) - delete (priv::ResourceStream*)m_stream; - - #endif } @@ -125,7 +109,7 @@ bool Font::loadFromFile(const std::string& filename) // Cleanup the previous resources cleanup(); - m_refCount = new int(1); + m_refCount = std::make_shared(1); // Initialize FreeType // Note: we initialize FreeType for every font instance in order to avoid having a single @@ -173,11 +157,8 @@ bool Font::loadFromFile(const std::string& filename) #else - if (m_stream) - delete (priv::ResourceStream*)m_stream; - - m_stream = new priv::ResourceStream(filename); - return loadFromStream(*(priv::ResourceStream*)m_stream); + m_stream = std::make_shared(filename); + return loadFromStream(*std::static_pointer_cast(m_stream)); #endif } @@ -188,7 +169,7 @@ bool Font::loadFromMemory(const void* data, std::size_t sizeInBytes) { // Cleanup the previous resources cleanup(); - m_refCount = new int(1); + m_refCount = std::make_shared(1); // Initialize FreeType // Note: we initialize FreeType for every font instance in order to avoid having a single @@ -241,7 +222,7 @@ bool Font::loadFromStream(InputStream& stream) { // Cleanup the previous resources cleanup(); - m_refCount = new int(1); + m_refCount = std::make_shared(1); // Initialize FreeType // Note: we initialize FreeType for every font instance in order to avoid having a single @@ -258,8 +239,8 @@ bool Font::loadFromStream(InputStream& stream) stream.seek(0); // Prepare a wrapper for our stream, that we'll pass to FreeType callbacks - FT_StreamRec* rec = new FT_StreamRec; - std::memset(rec, 0, sizeof(*rec)); + auto rec = std::make_shared(); + std::memset(rec.get(), 0, sizeof(FT_StreamRec)); rec->base = NULL; rec->size = static_cast(stream.getSize()); rec->pos = 0; @@ -270,7 +251,7 @@ bool Font::loadFromStream(InputStream& stream) // Setup the FreeType callbacks that will read our stream FT_Open_Args args; args.flags = FT_OPEN_STREAM; - args.stream = rec; + args.stream = rec.get(); args.driver = 0; // Load the new font face from the specified stream @@ -278,7 +259,6 @@ bool Font::loadFromStream(InputStream& stream) if (FT_Open_Face(static_cast(m_library), &args, 0, &face) != 0) { err() << "Failed to load font from stream (failed to create the font face)" << std::endl; - delete rec; return false; } @@ -296,7 +276,6 @@ bool Font::loadFromStream(InputStream& stream) { err() << "Failed to load font from stream (failed to set the Unicode character set)" << std::endl; FT_Done_Face(face); - delete rec; return false; } @@ -477,7 +456,7 @@ void Font::cleanup() if (*m_refCount == 0) { // Delete the reference counter - delete m_refCount; + m_refCount.reset(); // Destroy the stroker if (m_stroker) @@ -488,8 +467,7 @@ void Font::cleanup() FT_Done_Face(static_cast(m_face)); // Destroy the stream rec instance, if any (must be done after FT_Done_Face!) - if (m_streamRec) - delete static_cast(m_streamRec); + m_streamRec.reset(); // Close the library if (m_library) @@ -502,7 +480,6 @@ void Font::cleanup() m_face = NULL; m_stroker = NULL; m_streamRec = NULL; - m_refCount = NULL; m_pages.clear(); std::vector().swap(m_pixelBuffer); } diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 8dae99b0..8fc77a1b 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -41,24 +41,11 @@ namespace sf Image::Image() : m_size(0, 0) { - #ifdef SFML_SYSTEM_ANDROID - - m_stream = NULL; - - #endif } //////////////////////////////////////////////////////////// -Image::~Image() -{ - #ifdef SFML_SYSTEM_ANDROID - - if (m_stream) - delete (priv::ResourceStream*)m_stream; - - #endif -} +Image::~Image() = default; //////////////////////////////////////////////////////////// @@ -135,11 +122,8 @@ bool Image::loadFromFile(const std::string& filename) #else - if (m_stream) - delete (priv::ResourceStream*)m_stream; - - m_stream = new priv::ResourceStream(filename); - return loadFromStream(*(priv::ResourceStream*)m_stream); + m_stream = std::make_shared(filename); + return loadFromStream(*std::static_pointer_cast(m_stream)); #endif } diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index 12e8edf6..cf4cf50c 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -34,18 +34,11 @@ namespace sf { //////////////////////////////////////////////////////////// -RenderTexture::RenderTexture() : -m_impl(NULL) -{ - -} +RenderTexture::RenderTexture() = default; //////////////////////////////////////////////////////////// -RenderTexture::~RenderTexture() -{ - delete m_impl; -} +RenderTexture::~RenderTexture() = default; //////////////////////////////////////////////////////////// @@ -62,11 +55,10 @@ bool RenderTexture::create(unsigned int width, unsigned int height, bool depthBu setSmooth(false); // Create the implementation - delete m_impl; if (priv::RenderTextureImplFBO::isAvailable()) { // Use frame-buffer object (FBO) - m_impl = new priv::RenderTextureImplFBO; + m_impl = std::make_unique(); // Mark the texture as being a framebuffer object attachment m_texture.m_fboAttachment = true; @@ -74,7 +66,7 @@ bool RenderTexture::create(unsigned int width, unsigned int height, bool depthBu else { // Use default implementation - m_impl = new priv::RenderTextureImplDefault; + m_impl = std::make_unique(); } // Initialize the render texture diff --git a/src/SFML/Graphics/RenderTextureImplDefault.cpp b/src/SFML/Graphics/RenderTextureImplDefault.cpp index c52679dc..1d011eae 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.cpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.cpp @@ -38,7 +38,6 @@ namespace priv { //////////////////////////////////////////////////////////// RenderTextureImplDefault::RenderTextureImplDefault() : -m_context(0), m_width (0), m_height (0) { @@ -46,14 +45,6 @@ m_height (0) } -//////////////////////////////////////////////////////////// -RenderTextureImplDefault::~RenderTextureImplDefault() -{ - // Destroy the context - delete m_context; -} - - //////////////////////////////////////////////////////////// bool RenderTextureImplDefault::create(unsigned int width, unsigned int height, unsigned int, bool depthBuffer) { @@ -62,7 +53,7 @@ bool RenderTextureImplDefault::create(unsigned int width, unsigned int height, u m_height = height; // Create the in-memory OpenGL context - m_context = new Context(ContextSettings(depthBuffer ? 32 : 0), width, height); + m_context = std::make_unique(ContextSettings(depthBuffer ? 32 : 0), width, height); return true; } diff --git a/src/SFML/Graphics/RenderTextureImplDefault.hpp b/src/SFML/Graphics/RenderTextureImplDefault.hpp index 803b18f9..8d2a8b47 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.hpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace sf @@ -52,12 +53,6 @@ public: //////////////////////////////////////////////////////////// RenderTextureImplDefault(); - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - //////////////////////////////////////////////////////////// - ~RenderTextureImplDefault(); - private: //////////////////////////////////////////////////////////// @@ -94,9 +89,9 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Context* m_context; ///< P-Buffer based context - unsigned int m_width; ///< Width of the P-Buffer - unsigned int m_height; ///< Height of the P-Buffer + std::unique_ptr m_context; ///< P-Buffer based context + unsigned int m_width; ///< Width of the P-Buffer + unsigned int m_height; ///< Height of the P-Buffer }; } // namespace priv diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index 58dcb464..ef332a30 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -37,7 +37,6 @@ namespace priv { //////////////////////////////////////////////////////////// RenderTextureImplFBO::RenderTextureImplFBO() : -m_context (NULL), m_frameBuffer(0), m_depthBuffer(0) { @@ -63,9 +62,6 @@ RenderTextureImplFBO::~RenderTextureImplFBO() GLuint frameBuffer = static_cast(m_frameBuffer); glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer)); } - - // Delete the context - delete m_context; } @@ -85,7 +81,7 @@ bool RenderTextureImplFBO::isAvailable() bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer) { // Create the context - m_context = new Context; + m_context = std::make_unique(); // Create the framebuffer object GLuint frameBuffer = 0; diff --git a/src/SFML/Graphics/RenderTextureImplFBO.hpp b/src/SFML/Graphics/RenderTextureImplFBO.hpp index c987281f..321a9878 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.hpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.hpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace sf @@ -102,9 +103,9 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Context* m_context; ///< Needs a separate OpenGL context for not messing up the other ones - unsigned int m_frameBuffer; ///< OpenGL frame buffer object - unsigned int m_depthBuffer; ///< Optional depth buffer attached to the frame buffer + std::unique_ptr m_context; ///< Needs a separate OpenGL context for not messing up the other ones + unsigned int m_frameBuffer; ///< OpenGL frame buffer object + unsigned int m_depthBuffer; ///< Optional depth buffer attached to the frame buffer }; } // namespace priv diff --git a/src/SFML/Network/SocketSelector.cpp b/src/SFML/Network/SocketSelector.cpp index d7c9c564..9159391a 100644 --- a/src/SFML/Network/SocketSelector.cpp +++ b/src/SFML/Network/SocketSelector.cpp @@ -51,7 +51,7 @@ struct SocketSelector::SocketSelectorImpl //////////////////////////////////////////////////////////// SocketSelector::SocketSelector() : -m_impl(new SocketSelectorImpl) +m_impl(std::make_unique()) { clear(); } @@ -59,17 +59,14 @@ m_impl(new SocketSelectorImpl) //////////////////////////////////////////////////////////// SocketSelector::SocketSelector(const SocketSelector& copy) : -m_impl(new SocketSelectorImpl(*copy.m_impl)) +m_impl(std::make_unique(*copy.m_impl)) { } //////////////////////////////////////////////////////////// -SocketSelector::~SocketSelector() -{ - delete m_impl; -} +SocketSelector::~SocketSelector() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/System/Err.cpp b/src/SFML/System/Err.cpp index 51be9aa3..d4463251 100644 --- a/src/SFML/System/Err.cpp +++ b/src/SFML/System/Err.cpp @@ -40,19 +40,13 @@ public: DefaultErrStreamBuf() { - // Allocate the write buffer - constexpr auto size = 64; - char* buffer = new char[size]; - setp(buffer, buffer + size); + setp(m_buffer, m_buffer + sizeof(m_buffer)); } ~DefaultErrStreamBuf() { // Synchronize sync(); - - // Delete the write buffer - delete[] pbase(); } private: @@ -92,6 +86,8 @@ private: return 0; } + + char m_buffer[64]; }; } diff --git a/src/SFML/System/FileInputStream.cpp b/src/SFML/System/FileInputStream.cpp index e6f1c838..924b6c43 100644 --- a/src/SFML/System/FileInputStream.cpp +++ b/src/SFML/System/FileInputStream.cpp @@ -44,10 +44,7 @@ FileInputStream::FileInputStream() //////////////////////////////////////////////////////////// FileInputStream::~FileInputStream() { -#ifdef ANDROID - if (m_file) - delete m_file; -#else +#ifndef ANDROID if (m_file) std::fclose(m_file); #endif @@ -58,9 +55,7 @@ FileInputStream::~FileInputStream() bool FileInputStream::open(const std::string& filename) { #ifdef ANDROID - if (m_file) - delete m_file; - m_file = new priv::ResourceStream(filename); + m_file = std::make_unique(filename); return m_file->tell() != -1; #else if (m_file) diff --git a/src/SFML/System/Mutex.cpp b/src/SFML/System/Mutex.cpp index 36d48ee6..e204ae04 100644 --- a/src/SFML/System/Mutex.cpp +++ b/src/SFML/System/Mutex.cpp @@ -39,15 +39,12 @@ namespace sf //////////////////////////////////////////////////////////// Mutex::Mutex() { - m_mutexImpl = new priv::MutexImpl; + m_mutexImpl = std::make_shared(); } //////////////////////////////////////////////////////////// -Mutex::~Mutex() -{ - delete m_mutexImpl; -} +Mutex::~Mutex() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/System/Thread.cpp b/src/SFML/System/Thread.cpp index 3a2c0f90..c708fdc0 100644 --- a/src/SFML/System/Thread.cpp +++ b/src/SFML/System/Thread.cpp @@ -41,7 +41,6 @@ namespace sf Thread::~Thread() { wait(); - delete m_entryPoint; } @@ -49,7 +48,7 @@ Thread::~Thread() void Thread::launch() { wait(); - m_impl = new priv::ThreadImpl(this); + m_impl = std::make_shared(this); } @@ -59,8 +58,7 @@ void Thread::wait() if (m_impl) { m_impl->wait(); - delete m_impl; - m_impl = NULL; + m_impl.reset(); } } @@ -71,8 +69,7 @@ void Thread::terminate() if (m_impl) { m_impl->terminate(); - delete m_impl; - m_impl = NULL; + m_impl.reset(); } } diff --git a/src/SFML/System/ThreadLocal.cpp b/src/SFML/System/ThreadLocal.cpp index 01e3a352..6a3cc8c7 100644 --- a/src/SFML/System/ThreadLocal.cpp +++ b/src/SFML/System/ThreadLocal.cpp @@ -39,16 +39,13 @@ namespace sf //////////////////////////////////////////////////////////// ThreadLocal::ThreadLocal(void* value) { - m_impl = new priv::ThreadLocalImpl; + m_impl = std::make_unique(); setValue(value); } //////////////////////////////////////////////////////////// -ThreadLocal::~ThreadLocal() -{ - delete m_impl; -} +ThreadLocal::~ThreadLocal() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/Context.cpp b/src/SFML/Window/Context.cpp index 321dc2cc..05bddfc0 100644 --- a/src/SFML/Window/Context.cpp +++ b/src/SFML/Window/Context.cpp @@ -50,7 +50,6 @@ Context::Context() Context::~Context() { setActive(false); - delete m_context; } diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 396d366b..1dbbde33 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -143,7 +143,7 @@ namespace sf::ThreadLocalPtr currentContext(NULL); // The hidden, inactive context that will be shared with all other contexts - ContextType* sharedContext = NULL; + std::unique_ptr sharedContext; // This structure contains all the state necessary to // track TransientContext usage @@ -155,17 +155,15 @@ namespace //////////////////////////////////////////////////////////// TransientContext() : referenceCount (0), - context (0), - sharedContextLock(0), useSharedContext (false) { if (resourceCount == 0) { - context = new sf::Context; + context = std::make_unique(); } else if (!currentContext) { - sharedContextLock = new sf::Lock(mutex); + sharedContextLock = std::make_unique(mutex); useSharedContext = true; sharedContext->setActive(true); } @@ -179,23 +177,20 @@ namespace { if (useSharedContext) sharedContext->setActive(false); - - delete sharedContextLock; - delete context; } /////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// unsigned int referenceCount; - sf::Context* context; - sf::Lock* sharedContextLock; + std::unique_ptr context; + std::unique_ptr sharedContextLock; bool useSharedContext; }; // This per-thread variable tracks if and how a transient // context is currently being used on the current thread - sf::ThreadLocalPtr transientContext(NULL); + thread_local std::unique_ptr transientContext; // Supported OpenGL extensions std::vector extensions; @@ -224,7 +219,7 @@ void GlContext::initResource() } // Create the shared context - sharedContext = new ContextType(NULL); + sharedContext = std::make_unique(nullptr); sharedContext->initialize(ContextSettings()); // Load our extensions vector @@ -294,12 +289,8 @@ void GlContext::cleanupResource() // If there's no more resource alive, we can trigger the global context cleanup if (resourceCount == 0) { - if (!sharedContext) - return; - // Destroy the shared context - delete sharedContext; - sharedContext = NULL; + sharedContext.reset(); } } @@ -313,7 +304,7 @@ void GlContext::acquireTransientContext() // If this is the first TransientContextLock on this thread // construct the state object if (!transientContext) - transientContext = new TransientContext; + transientContext = std::make_unique(); // Increase the reference count transientContext->referenceCount++; @@ -335,22 +326,19 @@ void GlContext::releaseTransientContext() // If this is the last TransientContextLock that is released // destroy the state object if (transientContext->referenceCount == 0) - { - delete transientContext; - transientContext = NULL; - } + transientContext.reset(); } //////////////////////////////////////////////////////////// -GlContext* GlContext::create() +std::unique_ptr GlContext::create() { // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != NULL); Lock lock(mutex); - GlContext* context = NULL; + std::unique_ptr context; // We don't use acquireTransientContext here since we have // to ensure we have exclusive access to the shared context @@ -359,7 +347,7 @@ GlContext* GlContext::create() sharedContext->setActive(true); // Create the context - context = new ContextType(sharedContext); + context = std::make_unique(sharedContext.get()); sharedContext->setActive(false); } @@ -371,14 +359,14 @@ GlContext* GlContext::create() //////////////////////////////////////////////////////////// -GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel) +std::unique_ptr GlContext::create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel) { // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != NULL); Lock lock(mutex); - GlContext* context = NULL; + std::unique_ptr context; // We don't use acquireTransientContext here since we have // to ensure we have exclusive access to the shared context @@ -387,7 +375,7 @@ GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl* sharedContext->setActive(true); // Create the context - context = new ContextType(sharedContext, settings, owner, bitsPerPixel); + context = std::make_unique(sharedContext.get(), settings, owner, bitsPerPixel); sharedContext->setActive(false); } @@ -400,14 +388,14 @@ GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl* //////////////////////////////////////////////////////////// -GlContext* GlContext::create(const ContextSettings& settings, unsigned int width, unsigned int height) +std::unique_ptr GlContext::create(const ContextSettings& settings, unsigned int width, unsigned int height) { // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != NULL); Lock lock(mutex); - GlContext* context = NULL; + std::unique_ptr context; // We don't use acquireTransientContext here since we have // to ensure we have exclusive access to the shared context @@ -416,7 +404,7 @@ GlContext* GlContext::create(const ContextSettings& settings, unsigned int width sharedContext->setActive(true); // Create the context - context = new ContextType(sharedContext, settings, width, height); + context = std::make_unique(sharedContext.get(), settings, width, height); sharedContext->setActive(false); } diff --git a/src/SFML/Window/GlContext.hpp b/src/SFML/Window/GlContext.hpp index 22efa626..5ae647cc 100644 --- a/src/SFML/Window/GlContext.hpp +++ b/src/SFML/Window/GlContext.hpp @@ -32,6 +32,7 @@ #include #include #include +#include namespace sf @@ -90,7 +91,7 @@ public: /// \return Pointer to the created context (don't forget to delete it) /// //////////////////////////////////////////////////////////// - static GlContext* create(); + static std::unique_ptr create(); //////////////////////////////////////////////////////////// /// \brief Create a new context attached to a window @@ -105,7 +106,7 @@ public: /// \return Pointer to the created context /// //////////////////////////////////////////////////////////// - static GlContext* create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel); + static std::unique_ptr create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel); //////////////////////////////////////////////////////////// /// \brief Create a new context that embeds its own rendering target @@ -120,7 +121,7 @@ public: /// \return Pointer to the created context /// //////////////////////////////////////////////////////////// - static GlContext* create(const ContextSettings& settings, unsigned int width, unsigned int height); + static std::unique_ptr create(const ContextSettings& settings, unsigned int width, unsigned int height); public: //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 6618e5bb..1657dc99 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -42,8 +42,6 @@ namespace sf { //////////////////////////////////////////////////////////// Window::Window() : -m_impl (NULL), -m_context (NULL), m_frameTimeLimit(Time::Zero), m_size (0, 0) { @@ -53,8 +51,6 @@ m_size (0, 0) //////////////////////////////////////////////////////////// Window::Window(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) : -m_impl (NULL), -m_context (NULL), m_frameTimeLimit(Time::Zero), m_size (0, 0) { @@ -64,8 +60,6 @@ m_size (0, 0) //////////////////////////////////////////////////////////// Window::Window(WindowHandle handle, const ContextSettings& settings) : -m_impl (NULL), -m_context (NULL), m_frameTimeLimit(Time::Zero), m_size (0, 0) { @@ -124,7 +118,7 @@ void Window::create(VideoMode mode, const String& title, Uint32 style, const Con m_impl = priv::WindowImpl::create(mode, title, style, settings); // Recreate the context - m_context = priv::GlContext::create(settings, m_impl, mode.bitsPerPixel); + m_context = priv::GlContext::create(settings, m_impl.get(), mode.bitsPerPixel); // Perform common initializations initialize(); @@ -141,7 +135,7 @@ void Window::create(WindowHandle handle, const ContextSettings& settings) m_impl = priv::WindowImpl::create(handle); // Recreate the context - m_context = priv::GlContext::create(settings, m_impl, VideoMode::getDesktopMode().bitsPerPixel); + m_context = priv::GlContext::create(settings, m_impl.get(), VideoMode::getDesktopMode().bitsPerPixel); // Perform common initializations initialize(); @@ -151,13 +145,11 @@ void Window::create(WindowHandle handle, const ContextSettings& settings) //////////////////////////////////////////////////////////// void Window::close() { - // Delete the context - delete m_context; - m_context = NULL; + // Reset the context + m_context.reset(); - // Delete the window implementation - delete m_impl; - m_impl = NULL; + // Reset the window implementation + m_impl.reset(); // Update the fullscreen window if (this == fullscreenWindow) diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index f258aca5..4df62b69 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -66,16 +66,16 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -WindowImpl* WindowImpl::create(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) +std::unique_ptr WindowImpl::create(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) { - return new WindowImplType(mode, title, style, settings); + return std::make_unique(mode, title, style, settings); } //////////////////////////////////////////////////////////// -WindowImpl* WindowImpl::create(WindowHandle handle) +std::unique_ptr WindowImpl::create(WindowHandle handle) { - return new WindowImplType(handle); + return std::make_unique(handle); } diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 96f4436e..919e78d3 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -41,6 +41,8 @@ #include #include #include +#include + namespace sf { @@ -67,7 +69,7 @@ public: /// \return Pointer to the created window (don't forget to delete it) /// //////////////////////////////////////////////////////////// - static WindowImpl* create(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings); + static std::unique_ptr create(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings); //////////////////////////////////////////////////////////// /// \brief Create a new window depending on to the current OS @@ -77,7 +79,7 @@ public: /// \return Pointer to the created window (don't forget to delete it) /// //////////////////////////////////////////////////////////// - static WindowImpl* create(WindowHandle handle); + static std::unique_ptr create(WindowHandle handle); public: From c3567a477601612ef3a60139a8b4d6bf798bea19 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sun, 2 Apr 2017 02:43:40 +0200 Subject: [PATCH 08/18] Removed SFML threading facilities. --- examples/voip/Server.cpp | 7 +- include/SFML/Audio/Music.hpp | 4 +- include/SFML/Audio/SoundRecorder.hpp | 4 +- include/SFML/Audio/SoundStream.hpp | 26 +- include/SFML/System.hpp | 5 - include/SFML/System/Lock.hpp | 139 --------- include/SFML/System/Mutex.hpp | 149 --------- include/SFML/System/Thread.hpp | 283 ------------------ include/SFML/System/Thread.inl | 87 ------ include/SFML/System/ThreadLocal.hpp | 104 ------- include/SFML/System/ThreadLocalPtr.hpp | 158 ---------- include/SFML/System/ThreadLocalPtr.inl | 77 ----- src/SFML/Audio/AlResource.cpp | 9 +- src/SFML/Audio/Music.cpp | 5 +- src/SFML/Audio/SoundRecorder.cpp | 19 +- src/SFML/Audio/SoundStream.cpp | 40 +-- src/SFML/Graphics/Shader.cpp | 2 - src/SFML/Graphics/Texture.cpp | 6 +- src/SFML/Main/MainAndroid.cpp | 32 +- src/SFML/System/Android/Activity.hpp | 4 +- src/SFML/System/Android/ResourceStream.cpp | 4 +- src/SFML/System/CMakeLists.txt | 23 -- src/SFML/System/Lock.cpp | 48 --- src/SFML/System/Mutex.cpp | 63 ---- src/SFML/System/Thread.cpp | 83 ----- src/SFML/System/ThreadLocal.cpp | 64 ---- src/SFML/System/Unix/MutexImpl.cpp | 69 ----- src/SFML/System/Unix/MutexImpl.hpp | 83 ----- src/SFML/System/Unix/ThreadImpl.cpp | 94 ------ src/SFML/System/Unix/ThreadImpl.hpp | 93 ------ src/SFML/System/Unix/ThreadLocalImpl.cpp | 65 ---- src/SFML/System/Unix/ThreadLocalImpl.hpp | 87 ------ src/SFML/System/Win32/ClockImpl.cpp | 9 +- src/SFML/System/Win32/MutexImpl.cpp | 64 ---- src/SFML/System/Win32/MutexImpl.hpp | 83 ----- src/SFML/System/Win32/ThreadImpl.cpp | 93 ------ src/SFML/System/Win32/ThreadImpl.hpp | 109 ------- src/SFML/System/Win32/ThreadLocalImpl.cpp | 64 ---- src/SFML/System/Win32/ThreadLocalImpl.hpp | 87 ------ src/SFML/Window/Android/InputImpl.cpp | 12 +- src/SFML/Window/Android/VideoModeImpl.cpp | 4 +- src/SFML/Window/Android/WindowImplAndroid.cpp | 12 +- src/SFML/Window/Context.cpp | 3 +- src/SFML/Window/EglContext.cpp | 7 +- src/SFML/Window/GlContext.cpp | 32 +- src/SFML/Window/Unix/Display.cpp | 9 +- src/SFML/Window/Unix/GlxContext.cpp | 11 +- src/SFML/Window/Unix/WindowImplX11.cpp | 11 +- src/SFML/Window/Win32/WglContext.cpp | 13 +- 49 files changed, 143 insertions(+), 2416 deletions(-) delete mode 100644 include/SFML/System/Lock.hpp delete mode 100644 include/SFML/System/Mutex.hpp delete mode 100644 include/SFML/System/Thread.hpp delete mode 100644 include/SFML/System/Thread.inl delete mode 100644 include/SFML/System/ThreadLocal.hpp delete mode 100644 include/SFML/System/ThreadLocalPtr.hpp delete mode 100644 include/SFML/System/ThreadLocalPtr.inl delete mode 100644 src/SFML/System/Lock.cpp delete mode 100644 src/SFML/System/Mutex.cpp delete mode 100644 src/SFML/System/Thread.cpp delete mode 100644 src/SFML/System/ThreadLocal.cpp delete mode 100644 src/SFML/System/Unix/MutexImpl.cpp delete mode 100644 src/SFML/System/Unix/MutexImpl.hpp delete mode 100644 src/SFML/System/Unix/ThreadImpl.cpp delete mode 100644 src/SFML/System/Unix/ThreadImpl.hpp delete mode 100644 src/SFML/System/Unix/ThreadLocalImpl.cpp delete mode 100644 src/SFML/System/Unix/ThreadLocalImpl.hpp delete mode 100644 src/SFML/System/Win32/MutexImpl.cpp delete mode 100644 src/SFML/System/Win32/MutexImpl.hpp delete mode 100644 src/SFML/System/Win32/ThreadImpl.cpp delete mode 100644 src/SFML/System/Win32/ThreadImpl.hpp delete mode 100644 src/SFML/System/Win32/ThreadLocalImpl.cpp delete mode 100644 src/SFML/System/Win32/ThreadLocalImpl.hpp diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index 0875bf95..4730cb83 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -7,6 +7,7 @@ #include #include #include +#include const sf::Uint8 audioData = 1; @@ -83,7 +84,7 @@ private: // Copy samples into a local buffer to avoid synchronization problems // (don't forget that we run in two separate threads) { - sf::Lock lock(m_mutex); + std::lock_guard lock(m_mutex); m_tempBuffer.assign(m_samples.begin() + m_offset, m_samples.end()); } @@ -132,7 +133,7 @@ private: // Don't forget that the other thread can access the sample array at any time // (so we protect any operation on it with the mutex) { - sf::Lock lock(m_mutex); + std::lock_guard lock(m_mutex); std::copy(samples, samples + sampleCount, std::back_inserter(m_samples)); } } @@ -156,7 +157,7 @@ private: //////////////////////////////////////////////////////////// sf::TcpListener m_listener; sf::TcpSocket m_client; - sf::Mutex m_mutex; + std::mutex m_mutex; std::vector m_samples; std::vector m_tempBuffer; std::size_t m_offset; diff --git a/include/SFML/Audio/Music.hpp b/include/SFML/Audio/Music.hpp index 5e272655..cf2fe0cd 100644 --- a/include/SFML/Audio/Music.hpp +++ b/include/SFML/Audio/Music.hpp @@ -31,10 +31,10 @@ #include #include #include -#include #include #include #include +#include namespace sf @@ -170,7 +170,7 @@ private: //////////////////////////////////////////////////////////// InputSoundFile m_file; ///< The streamed music file std::vector m_samples; ///< Temporary buffer of samples - Mutex m_mutex; ///< Mutex protecting the data + std::mutex m_mutex; ///< Mutex protecting the data }; } // namespace sf diff --git a/include/SFML/Audio/SoundRecorder.hpp b/include/SFML/Audio/SoundRecorder.hpp index 33c80b1f..eddc9ab0 100644 --- a/include/SFML/Audio/SoundRecorder.hpp +++ b/include/SFML/Audio/SoundRecorder.hpp @@ -30,10 +30,10 @@ //////////////////////////////////////////////////////////// #include #include -#include #include #include #include +#include namespace sf @@ -285,7 +285,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Thread m_thread; ///< Thread running the background recording task + std::thread m_thread; ///< Thread running the background recording task std::vector m_samples; ///< Buffer to store captured samples unsigned int m_sampleRate; ///< Sample rate Time m_processingInterval; ///< Time period between calls to onProcessSamples diff --git a/include/SFML/Audio/SoundStream.hpp b/include/SFML/Audio/SoundStream.hpp index bd621727..70a094a2 100644 --- a/include/SFML/Audio/SoundStream.hpp +++ b/include/SFML/Audio/SoundStream.hpp @@ -30,10 +30,10 @@ //////////////////////////////////////////////////////////// #include #include -#include #include -#include #include +#include +#include namespace sf @@ -289,17 +289,17 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Thread m_thread; ///< Thread running the background tasks - mutable Mutex m_threadMutex; ///< Thread mutex - Status m_threadStartState; ///< State the thread starts in (Playing, Paused, Stopped) - bool m_isStreaming; ///< Streaming state (true = playing, false = stopped) - unsigned int m_buffers[BufferCount]; ///< Sound buffers used to store temporary audio data - unsigned int m_channelCount; ///< Number of channels (1 = mono, 2 = stereo, ...) - unsigned int m_sampleRate; ///< Frequency (samples / second) - Uint32 m_format; ///< Format of the internal sound buffers - bool m_loop; ///< Loop flag (true to loop, false to play once) - Uint64 m_samplesProcessed; ///< Number of buffers processed since beginning of the stream - bool m_endBuffers[BufferCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation + std::thread m_thread; ///< Thread running the background tasks + mutable std::mutex m_threadMutex; ///< Thread mutex + Status m_threadStartState; ///< State the thread starts in (Playing, Paused, Stopped) + bool m_isStreaming; ///< Streaming state (true = playing, false = stopped) + unsigned int m_buffers[BufferCount]; ///< Sound buffers used to store temporary audio data + unsigned int m_channelCount; ///< Number of channels (1 = mono, 2 = stereo, ...) + unsigned int m_sampleRate; ///< Frequency (samples / second) + Uint32 m_format; ///< Format of the internal sound buffers + bool m_loop; ///< Loop flag (true to loop, false to play once) + Uint64 m_samplesProcessed; ///< Number of buffers processed since beginning of the stream + bool m_endBuffers[BufferCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation }; } // namespace sf diff --git a/include/SFML/System.hpp b/include/SFML/System.hpp index 5f18f766..98cf8486 100644 --- a/include/SFML/System.hpp +++ b/include/SFML/System.hpp @@ -34,15 +34,10 @@ #include #include #include -#include #include -#include #include #include #include -#include -#include -#include #include #include #include diff --git a/include/SFML/System/Lock.hpp b/include/SFML/System/Lock.hpp deleted file mode 100644 index eb420a8e..00000000 --- a/include/SFML/System/Lock.hpp +++ /dev/null @@ -1,139 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_LOCK_HPP -#define SFML_LOCK_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -class Mutex; - -//////////////////////////////////////////////////////////// -/// \brief Automatic wrapper for locking and unlocking mutexes -/// -//////////////////////////////////////////////////////////// -class SFML_SYSTEM_API Lock : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Construct the lock with a target mutex - /// - /// The mutex passed to sf::Lock is automatically locked. - /// - /// \param mutex Mutex to lock - /// - //////////////////////////////////////////////////////////// - explicit Lock(Mutex& mutex); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - /// The destructor of sf::Lock automatically unlocks its mutex. - /// - //////////////////////////////////////////////////////////// - ~Lock(); - -private: - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - Mutex& m_mutex; ///< Mutex to lock / unlock -}; - -} // namespace sf - - -#endif // SFML_LOCK_HPP - - -//////////////////////////////////////////////////////////// -/// \class sf::Lock -/// \ingroup system -/// -/// sf::Lock is a RAII wrapper for sf::Mutex. By unlocking -/// it in its destructor, it ensures that the mutex will -/// always be released when the current scope (most likely -/// a function) ends. -/// This is even more important when an exception or an early -/// return statement can interrupt the execution flow of the -/// function. -/// -/// For maximum robustness, sf::Lock should always be used -/// to lock/unlock a mutex. -/// -/// Usage example: -/// \code -/// sf::Mutex mutex; -/// -/// void function() -/// { -/// sf::Lock lock(mutex); // mutex is now locked -/// -/// functionThatMayThrowAnException(); // mutex is unlocked if this function throws -/// -/// if (someCondition) -/// return; // mutex is unlocked -/// -/// } // mutex is unlocked -/// \endcode -/// -/// Because the mutex is not explicitly unlocked in the code, -/// it may remain locked longer than needed. If the region -/// of the code that needs to be protected by the mutex is -/// not the entire function, a good practice is to create a -/// smaller, inner scope so that the lock is limited to this -/// part of the code. -/// -/// \code -/// sf::Mutex mutex; -/// -/// void function() -/// { -/// { -/// sf::Lock lock(mutex); -/// codeThatRequiresProtection(); -/// -/// } // mutex is unlocked here -/// -/// codeThatDoesntCareAboutTheMutex(); -/// } -/// \endcode -/// -/// Having a mutex locked longer than required is a bad practice -/// which can lead to bad performances. Don't forget that when -/// a mutex is locked, other threads may be waiting doing nothing -/// until it is released. -/// -/// \see sf::Mutex -/// -//////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Mutex.hpp b/include/SFML/System/Mutex.hpp deleted file mode 100644 index 7ac8e8ad..00000000 --- a/include/SFML/System/Mutex.hpp +++ /dev/null @@ -1,149 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_MUTEX_HPP -#define SFML_MUTEX_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include - - -namespace sf -{ -namespace priv -{ - class MutexImpl; -} - -//////////////////////////////////////////////////////////// -/// \brief Blocks concurrent access to shared resources -/// from multiple threads -/// -//////////////////////////////////////////////////////////// -class SFML_SYSTEM_API Mutex : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - //////////////////////////////////////////////////////////// - Mutex(); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - //////////////////////////////////////////////////////////// - ~Mutex(); - - //////////////////////////////////////////////////////////// - /// \brief Lock the mutex - /// - /// If the mutex is already locked in another thread, - /// this call will block the execution until the mutex - /// is released. - /// - /// \see unlock - /// - //////////////////////////////////////////////////////////// - void lock(); - - //////////////////////////////////////////////////////////// - /// \brief Unlock the mutex - /// - /// \see lock - /// - //////////////////////////////////////////////////////////// - void unlock(); - -private: - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - std::shared_ptr m_mutexImpl; ///< OS-specific implementation -}; - -} // namespace sf - - -#endif // SFML_MUTEX_HPP - - -//////////////////////////////////////////////////////////// -/// \class sf::Mutex -/// \ingroup system -/// -/// Mutex stands for "MUTual EXclusion". A mutex is a -/// synchronization object, used when multiple threads are involved. -/// -/// When you want to protect a part of the code from being accessed -/// simultaneously by multiple threads, you typically use a -/// mutex. When a thread is locked by a mutex, any other thread -/// trying to lock it will be blocked until the mutex is released -/// by the thread that locked it. This way, you can allow only -/// one thread at a time to access a critical region of your code. -/// -/// Usage example: -/// \code -/// Database database; // this is a critical resource that needs some protection -/// sf::Mutex mutex; -/// -/// void thread1() -/// { -/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread2 -/// database.write(...); -/// mutex.unlock(); // if thread2 was waiting, it will now be unblocked -/// } -/// -/// void thread2() -/// { -/// mutex.lock(); // this call will block the thread if the mutex is already locked by thread1 -/// database.write(...); -/// mutex.unlock(); // if thread1 was waiting, it will now be unblocked -/// } -/// \endcode -/// -/// Be very careful with mutexes. A bad usage can lead to bad problems, -/// like deadlocks (two threads are waiting for each other and the -/// application is globally stuck). -/// -/// To make the usage of mutexes more robust, particularly in -/// environments where exceptions can be thrown, you should -/// use the helper class sf::Lock to lock/unlock mutexes. -/// -/// SFML mutexes are recursive, which means that you can lock -/// a mutex multiple times in the same thread without creating -/// a deadlock. In this case, the first call to lock() behaves -/// as usual, and the following ones have no effect. -/// However, you must call unlock() exactly as many times as you -/// called lock(). If you don't, the mutex won't be released. -/// -/// \see sf::Lock -/// -//////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Thread.hpp b/include/SFML/System/Thread.hpp deleted file mode 100644 index 45c5d62f..00000000 --- a/include/SFML/System/Thread.hpp +++ /dev/null @@ -1,283 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREAD_HPP -#define SFML_THREAD_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include -#include - - -namespace sf -{ -namespace priv -{ - class ThreadImpl; - struct ThreadFunc; -} - -//////////////////////////////////////////////////////////// -/// \brief Utility class to manipulate threads -/// -//////////////////////////////////////////////////////////// -class SFML_SYSTEM_API Thread : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Construct the thread from a functor with no argument - /// - /// This constructor works for function objects, as well - /// as free functions. - /// - /// Use this constructor for this kind of function: - /// \code - /// void function(); - /// - /// // --- or ---- - /// - /// struct Functor - /// { - /// void operator()(); - /// }; - /// \endcode - /// Note: this does *not* run the thread, use launch(). - /// - /// \param function Functor or free function to use as the entry point of the thread - /// - //////////////////////////////////////////////////////////// - template - Thread(F function); - - //////////////////////////////////////////////////////////// - /// \brief Construct the thread from a functor with an argument - /// - /// This constructor works for function objects, as well - /// as free functions. - /// It is a template, which means that the argument can - /// have any type (int, std::string, void*, Toto, ...). - /// - /// Use this constructor for this kind of function: - /// \code - /// void function(int arg); - /// - /// // --- or ---- - /// - /// struct Functor - /// { - /// void operator()(std::string arg); - /// }; - /// \endcode - /// Note: this does *not* run the thread, use launch(). - /// - /// \param function Functor or free function to use as the entry point of the thread - /// \param argument argument to forward to the function - /// - //////////////////////////////////////////////////////////// - template - Thread(F function, A argument); - - //////////////////////////////////////////////////////////// - /// \brief Construct the thread from a member function and an object - /// - /// This constructor is a template, which means that you can - /// use it with any class. - /// Use this constructor for this kind of function: - /// \code - /// class MyClass - /// { - /// public: - /// - /// void function(); - /// }; - /// \endcode - /// Note: this does *not* run the thread, use launch(). - /// - /// \param function Entry point of the thread - /// \param object Pointer to the object to use - /// - //////////////////////////////////////////////////////////// - template - Thread(void(C::*function)(), C* object); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - /// This destructor calls wait(), so that the internal thread - /// cannot survive after its sf::Thread instance is destroyed. - /// - //////////////////////////////////////////////////////////// - ~Thread(); - - //////////////////////////////////////////////////////////// - /// \brief Run the thread - /// - /// This function starts the entry point passed to the - /// thread's constructor, and returns immediately. - /// After this function returns, the thread's function is - /// running in parallel to the calling code. - /// - //////////////////////////////////////////////////////////// - void launch(); - - //////////////////////////////////////////////////////////// - /// \brief Wait until the thread finishes - /// - /// This function will block the execution until the - /// thread's function ends. - /// Warning: if the thread function never ends, the calling - /// thread will block forever. - /// If this function is called from its owner thread, it - /// returns without doing anything. - /// - //////////////////////////////////////////////////////////// - void wait(); - - //////////////////////////////////////////////////////////// - /// \brief Terminate the thread - /// - /// This function immediately stops the thread, without waiting - /// for its function to finish. - /// Terminating a thread with this function is not safe, - /// and can lead to local variables not being destroyed - /// on some operating systems. You should rather try to make - /// the thread function terminate by itself. - /// - //////////////////////////////////////////////////////////// - void terminate(); - -private: - - friend class priv::ThreadImpl; - - //////////////////////////////////////////////////////////// - /// \brief Internal entry point of the thread - /// - /// This function is called by the thread implementation. - /// - //////////////////////////////////////////////////////////// - void run(); - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - std::shared_ptr m_impl; ///< OS-specific implementation of the thread - std::shared_ptr m_entryPoint; ///< Abstraction of the function to run -}; - -#include - -} // namespace sf - -#endif // SFML_THREAD_HPP - - -//////////////////////////////////////////////////////////// -/// \class sf::Thread -/// \ingroup system -/// -/// Threads provide a way to run multiple parts of the code -/// in parallel. When you launch a new thread, the execution -/// is split and both the new thread and the caller run -/// in parallel. -/// -/// To use a sf::Thread, you construct it directly with the -/// function to execute as the entry point of the thread. -/// sf::Thread has multiple template constructors, which means -/// that you can use several types of entry points: -/// \li non-member functions with no argument -/// \li non-member functions with one argument of any type -/// \li functors with no argument (this one is particularly useful for compatibility with boost/std::%bind) -/// \li functors with one argument of any type -/// \li member functions from any class with no argument -/// -/// The function argument, if any, is copied in the sf::Thread -/// instance, as well as the functor (if the corresponding -/// constructor is used). Class instances, however, are passed -/// by pointer so you must make sure that the object won't be -/// destroyed while the thread is still using it. -/// -/// The thread ends when its function is terminated. If the -/// owner sf::Thread instance is destroyed before the -/// thread is finished, the destructor will wait (see wait()) -/// -/// Usage examples: -/// \code -/// // example 1: non member function with one argument -/// -/// void threadFunc(int argument) -/// { -/// ... -/// } -/// -/// sf::Thread thread(&threadFunc, 5); -/// thread.launch(); // start the thread (internally calls threadFunc(5)) -/// \endcode -/// -/// \code -/// // example 2: member function -/// -/// class Task -/// { -/// public: -/// void run() -/// { -/// ... -/// } -/// }; -/// -/// Task task; -/// sf::Thread thread(&Task::run, &task); -/// thread.launch(); // start the thread (internally calls task.run()) -/// \endcode -/// -/// \code -/// // example 3: functor -/// -/// struct Task -/// { -/// void operator()() -/// { -/// ... -/// } -/// }; -/// -/// sf::Thread thread(Task()); -/// thread.launch(); // start the thread (internally calls operator() on the Task instance) -/// \endcode -/// -/// Creating parallel threads of execution can be dangerous: -/// all threads inside the same process share the same memory space, -/// which means that you may end up accessing the same variable -/// from multiple threads at the same time. To prevent this -/// kind of situations, you can use mutexes (see sf::Mutex). -/// -/// \see sf::Mutex -/// -//////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Thread.inl b/include/SFML/System/Thread.inl deleted file mode 100644 index fd3602fe..00000000 --- a/include/SFML/System/Thread.inl +++ /dev/null @@ -1,87 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -namespace priv -{ -// Base class for abstract thread functions -struct ThreadFunc -{ - virtual ~ThreadFunc() {} - virtual void run() = 0; -}; - -// Specialization using a functor (including free functions) with no argument -template -struct ThreadFunctor : ThreadFunc -{ - ThreadFunctor(T functor) : m_functor(functor) {} - virtual void run() {m_functor();} - T m_functor; -}; - -// Specialization using a functor (including free functions) with one argument -template -struct ThreadFunctorWithArg : ThreadFunc -{ - ThreadFunctorWithArg(F function, A arg) : m_function(function), m_arg(arg) {} - virtual void run() {m_function(m_arg);} - F m_function; - A m_arg; -}; - -// Specialization using a member function -template -struct ThreadMemberFunc : ThreadFunc -{ - ThreadMemberFunc(void(C::*function)(), C* object) : m_function(function), m_object(object) {} - virtual void run() {(m_object->*m_function)();} - void(C::*m_function)(); - C* m_object; -}; - -} // namespace priv - - -//////////////////////////////////////////////////////////// -template -Thread::Thread(F functor) : -m_entryPoint(std::make_shared>(functor)) -{ -} - - -//////////////////////////////////////////////////////////// -template -Thread::Thread(F function, A argument) : -m_entryPoint(std::make_shared>(function, argument)) -{ -} - - -//////////////////////////////////////////////////////////// -template -Thread::Thread(void(C::*function)(), C* object) : -m_entryPoint(std::make_shared>(function, object)) -{ -} diff --git a/include/SFML/System/ThreadLocal.hpp b/include/SFML/System/ThreadLocal.hpp deleted file mode 100644 index 160abdfd..00000000 --- a/include/SFML/System/ThreadLocal.hpp +++ /dev/null @@ -1,104 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREADLOCAL_HPP -#define SFML_THREADLOCAL_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include -#include - - -namespace sf -{ -namespace priv -{ - class ThreadLocalImpl; -} - -//////////////////////////////////////////////////////////// -/// \brief Defines variables with thread-local storage -/// -//////////////////////////////////////////////////////////// -class SFML_SYSTEM_API ThreadLocal : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - /// \param value Optional value to initialize the variable - /// - //////////////////////////////////////////////////////////// - ThreadLocal(void* value = NULL); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - //////////////////////////////////////////////////////////// - ~ThreadLocal(); - - //////////////////////////////////////////////////////////// - /// \brief Set the thread-specific value of the variable - /// - /// \param value Value of the variable for the current thread - /// - //////////////////////////////////////////////////////////// - void setValue(void* value); - - //////////////////////////////////////////////////////////// - /// \brief Retrieve the thread-specific value of the variable - /// - /// \return Value of the variable for the current thread - /// - //////////////////////////////////////////////////////////// - void* getValue() const; - -private: - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - std::unique_ptr m_impl; ///< Pointer to the OS specific implementation -}; - -} // namespace sf - - -#endif // SFML_THREADLOCAL_HPP - - -//////////////////////////////////////////////////////////// -/// \class sf::ThreadLocal -/// \ingroup system -/// -/// This class manipulates void* parameters and thus is not -/// appropriate for strongly-typed variables. You should rather -/// use the sf::ThreadLocalPtr template class. -/// -//////////////////////////////////////////////////////////// diff --git a/include/SFML/System/ThreadLocalPtr.hpp b/include/SFML/System/ThreadLocalPtr.hpp deleted file mode 100644 index 751a9b53..00000000 --- a/include/SFML/System/ThreadLocalPtr.hpp +++ /dev/null @@ -1,158 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREADLOCALPTR_HPP -#define SFML_THREADLOCALPTR_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -namespace sf -{ -//////////////////////////////////////////////////////////// -/// \brief Pointer to a thread-local variable -/// -//////////////////////////////////////////////////////////// -template -class ThreadLocalPtr : private ThreadLocal -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - /// \param value Optional value to initialize the variable - /// - //////////////////////////////////////////////////////////// - ThreadLocalPtr(T* value = NULL); - - //////////////////////////////////////////////////////////// - /// \brief Overload of unary operator * - /// - /// Like raw pointers, applying the * operator returns a - /// reference to the pointed-to object. - /// - /// \return Reference to the thread-local variable - /// - //////////////////////////////////////////////////////////// - T& operator *() const; - - //////////////////////////////////////////////////////////// - /// \brief Overload of operator -> - /// - /// Similarly to raw pointers, applying the -> operator - /// returns the pointed-to object. - /// - /// \return Pointer to the thread-local variable - /// - //////////////////////////////////////////////////////////// - T* operator ->() const; - - //////////////////////////////////////////////////////////// - /// \brief Conversion operator to implicitly convert the - /// pointer to its raw pointer type (T*) - /// - /// \return Pointer to the actual object - /// - //////////////////////////////////////////////////////////// - operator T*() const; - - //////////////////////////////////////////////////////////// - /// \brief Assignment operator for a raw pointer parameter - /// - /// \param value Pointer to assign - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - ThreadLocalPtr& operator =(T* value); - - //////////////////////////////////////////////////////////// - /// \brief Assignment operator for a ThreadLocalPtr parameter - /// - /// \param right ThreadLocalPtr to assign - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - ThreadLocalPtr& operator =(const ThreadLocalPtr& right); -}; - -} // namespace sf - -#include - - -#endif // SFML_THREADLOCALPTR_HPP - - -//////////////////////////////////////////////////////////// -/// \class sf::ThreadLocalPtr -/// \ingroup system -/// -/// sf::ThreadLocalPtr is a type-safe wrapper for storing -/// pointers to thread-local variables. A thread-local -/// variable holds a different value for each different -/// thread, unlike normal variables that are shared. -/// -/// Its usage is completely transparent, so that it is similar -/// to manipulating the raw pointer directly (like any smart pointer). -/// -/// Usage example: -/// \code -/// MyClass object1; -/// MyClass object2; -/// sf::ThreadLocalPtr objectPtr; -/// -/// void thread1() -/// { -/// objectPtr = &object1; // doesn't impact thread2 -/// ... -/// } -/// -/// void thread2() -/// { -/// objectPtr = &object2; // doesn't impact thread1 -/// ... -/// } -/// -/// int main() -/// { -/// // Create and launch the two threads -/// sf::Thread t1(&thread1); -/// sf::Thread t2(&thread2); -/// t1.launch(); -/// t2.launch(); -/// -/// return 0; -/// } -/// \endcode -/// -/// ThreadLocalPtr is designed for internal use; however you -/// can use it if you feel like it fits well your implementation. -/// -//////////////////////////////////////////////////////////// diff --git a/include/SFML/System/ThreadLocalPtr.inl b/include/SFML/System/ThreadLocalPtr.inl deleted file mode 100644 index 5652f56e..00000000 --- a/include/SFML/System/ThreadLocalPtr.inl +++ /dev/null @@ -1,77 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - - -namespace sf -{ -//////////////////////////////////////////////////////////// -template -ThreadLocalPtr::ThreadLocalPtr(T* value) : -ThreadLocal(value) -{ -} - - -//////////////////////////////////////////////////////////// -template -T& ThreadLocalPtr::operator *() const -{ - return *static_cast(getValue()); -} - - -//////////////////////////////////////////////////////////// -template -T* ThreadLocalPtr::operator ->() const -{ - return static_cast(getValue()); -} - - -//////////////////////////////////////////////////////////// -template -ThreadLocalPtr::operator T*() const -{ - return static_cast(getValue()); -} - - -//////////////////////////////////////////////////////////// -template -ThreadLocalPtr& ThreadLocalPtr::operator =(T* value) -{ - setValue(value); - return *this; -} - - -//////////////////////////////////////////////////////////// -template -ThreadLocalPtr& ThreadLocalPtr::operator =(const ThreadLocalPtr& right) -{ - setValue(right.getValue()); - return *this; -} - -} // namespace sf diff --git a/src/SFML/Audio/AlResource.cpp b/src/SFML/Audio/AlResource.cpp index 6dd1d207..82febebf 100644 --- a/src/SFML/Audio/AlResource.cpp +++ b/src/SFML/Audio/AlResource.cpp @@ -27,16 +27,15 @@ //////////////////////////////////////////////////////////// #include #include -#include -#include #include +#include namespace { // OpenAL resources counter and its mutex unsigned int count = 0; - sf::Mutex mutex; + std::mutex mutex; // The audio device is instantiated on demand rather than at global startup, // which solves a lot of weird crashes and errors. @@ -51,7 +50,7 @@ namespace sf AlResource::AlResource() { // Protect from concurrent access - Lock lock(mutex); + std::lock_guard lock(mutex); // If this is the very first resource, trigger the global device initialization if (count == 0) @@ -66,7 +65,7 @@ AlResource::AlResource() AlResource::~AlResource() { // Protect from concurrent access - Lock lock(mutex); + std::lock_guard lock(mutex); // Decrement the resources counter count--; diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index e959cea8..3c3bae7f 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -27,7 +27,6 @@ //////////////////////////////////////////////////////////// #include #include -#include #include #include @@ -111,7 +110,7 @@ Time Music::getDuration() const //////////////////////////////////////////////////////////// bool Music::onGetData(SoundStream::Chunk& data) { - Lock lock(m_mutex); + std::lock_guard lock(m_mutex); // Fill the chunk parameters data.samples = &m_samples[0]; @@ -125,7 +124,7 @@ bool Music::onGetData(SoundStream::Chunk& data) //////////////////////////////////////////////////////////// void Music::onSeek(Time timeOffset) { - Lock lock(m_mutex); + std::lock_guard lock(m_mutex); m_file.seek(timeOffset); } diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 7105fbdf..0e41f27d 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -47,7 +47,6 @@ namespace sf { //////////////////////////////////////////////////////////// SoundRecorder::SoundRecorder() : -m_thread (&SoundRecorder::record, this), m_sampleRate (0), m_processingInterval(milliseconds(100)), m_isCapturing (false), @@ -112,7 +111,10 @@ bool SoundRecorder::start(unsigned int sampleRate) // Start the capture in a new thread, to avoid blocking the main thread m_isCapturing = true; - m_thread.launch(); + m_thread = std::thread([this] + { + record(); + }); return true; } @@ -128,7 +130,9 @@ void SoundRecorder::stop() if (m_isCapturing) { m_isCapturing = false; - m_thread.wait(); + + if (m_thread.joinable()) + m_thread.join(); // Notify derived class onStop(); @@ -182,7 +186,9 @@ bool SoundRecorder::setDevice(const std::string& name) { // Stop the capturing thread m_isCapturing = false; - m_thread.wait(); + + if (m_thread.joinable()) + m_thread.join(); // Determine the recording format ALCenum format = (m_channelCount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; @@ -203,7 +209,10 @@ bool SoundRecorder::setDevice(const std::string& name) // Start the capture in a new thread, to avoid blocking the main thread m_isCapturing = true; - m_thread.launch(); + m_thread = std::thread([this] + { + record(); + }); } return true; diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index baefc097..3d6b01e0 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #ifdef _MSC_VER #pragma warning(disable: 4355) // 'this' used in base member initializer list @@ -41,7 +40,6 @@ namespace sf { //////////////////////////////////////////////////////////// SoundStream::SoundStream() : -m_thread (&SoundStream::streamData, this), m_threadMutex (), m_threadStartState(Stopped), m_isStreaming (false), @@ -64,12 +62,13 @@ SoundStream::~SoundStream() // Request the thread to terminate { - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; } // Wait for the thread to terminate - m_thread.wait(); + if (m_thread.joinable()) + m_thread.join(); } @@ -108,7 +107,7 @@ void SoundStream::play() Status threadStartState = Stopped; { - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); isStreaming = m_isStreaming; threadStartState = m_threadStartState; @@ -118,7 +117,7 @@ void SoundStream::play() if (isStreaming && (threadStartState == Paused)) { // If the sound is paused, resume it - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_threadStartState = Playing; alCheck(alSourcePlay(m_source)); return; @@ -132,7 +131,10 @@ void SoundStream::play() // Start updating the stream in a separate thread to avoid blocking the application m_isStreaming = true; m_threadStartState = Playing; - m_thread.launch(); + m_thread = std::thread([this] + { + streamData(); + }); } @@ -141,7 +143,7 @@ void SoundStream::pause() { // Handle pause() being called before the thread has started { - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); if (!m_isStreaming) return; @@ -158,12 +160,13 @@ void SoundStream::stop() { // Request the thread to terminate { - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; } // Wait for the thread to terminate - m_thread.wait(); + if (m_thread.joinable()) + m_thread.join(); // Move to the beginning onSeek(Time::Zero); @@ -195,7 +198,7 @@ SoundStream::Status SoundStream::getStatus() const // To compensate for the lag between play() and alSourceplay() if (status == Stopped) { - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); if (m_isStreaming) status = m_threadStartState; @@ -225,7 +228,10 @@ void SoundStream::setPlayingOffset(Time timeOffset) m_isStreaming = true; m_threadStartState = oldStatus; - m_thread.launch(); + m_thread = std::thread([this] + { + streamData(); + }); } @@ -266,7 +272,7 @@ void SoundStream::streamData() bool requestStop = false; { - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); // Check if the thread was launched Stopped if (m_threadStartState == Stopped) @@ -288,7 +294,7 @@ void SoundStream::streamData() alCheck(alSourcePlay(m_source)); { - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); // Check if the thread was launched Paused if (m_threadStartState == Paused) @@ -298,7 +304,7 @@ void SoundStream::streamData() for (;;) { { - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); if (!m_isStreaming) break; } @@ -314,7 +320,7 @@ void SoundStream::streamData() else { // End streaming - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; } } @@ -358,7 +364,7 @@ void SoundStream::streamData() << "and initialize() has been called correctly" << std::endl; // Abort streaming (exit main loop) - Lock lock(m_threadMutex); + std::lock_guard lock(m_threadMutex); m_isStreaming = false; requestStop = true; break; diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 5d36e14c..bae40eee 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -33,8 +33,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 8825d75a..4c09dcf5 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -31,8 +31,6 @@ #include #include #include -#include -#include #include #include #include @@ -41,13 +39,13 @@ namespace { - sf::Mutex idMutex; + std::mutex idMutex; // Thread-safe unique identifier generator, // is used for states cache (see RenderTarget) sf::Uint64 getUniqueId() { - sf::Lock lock(idMutex); + std::lock_guard lock(idMutex); static sf::Uint64 id = 1; // start at 1, zero is "no texture" diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 595a3a26..c5a352e0 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -40,11 +40,11 @@ #include #include -#include -#include #include #include #include +#include +#include extern int main(int argc, char *argv[]); @@ -86,7 +86,7 @@ ActivityStates* retrieveStates(ANativeActivity* activity) static void initializeMain(ActivityStates* states) { // Protect from concurrent access - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Prepare and share the looper to be read later ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); @@ -102,7 +102,7 @@ static void initializeMain(ActivityStates* states) static void terminateMain(ActivityStates* states) { // Protect from concurrent access - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // The main thread has finished, we must explicitly ask the activity to finish states->mainOver = true; @@ -123,7 +123,7 @@ void* main(ActivityStates* states) terminateMain(states); { - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); states->terminated = true; } @@ -241,7 +241,7 @@ static void onResume(ANativeActivity* activity) { // Retrieve our activity states from the activity instance sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); if (states->fullscreen) goToFullscreenMode(activity); @@ -259,7 +259,7 @@ static void onPause(ANativeActivity* activity) { // Retrieve our activity states from the activity instance sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Send an event to warn people the activity has been paused sf::Event event; @@ -283,7 +283,7 @@ static void onDestroy(ANativeActivity* activity) // Send an event to warn people the activity is being destroyed { - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // If the main thread hasn't yet finished, send the event and wait for // it to finish. @@ -325,7 +325,7 @@ static void onDestroy(ANativeActivity* activity) static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window) { sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Update the activity states states->window = window; @@ -350,7 +350,7 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* window) { sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Update the activity states states->window = NULL; @@ -391,7 +391,7 @@ static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) // Attach the input queue { - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); AInputQueue_attachLooper(queue, states->looper, 1, states->processEvent, NULL); states->inputQueue = queue; @@ -407,7 +407,7 @@ static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) // Detach the input queue { - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); states->inputQueue = NULL; AInputQueue_detachLooper(queue); @@ -426,7 +426,7 @@ static void onContentRectChanged(ANativeActivity* activity, const ARect* rect) { // Retrieve our activity states from the activity instance sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity); - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Make sure the window still exists before we access the dimensions on it if (states->window != NULL) { @@ -535,8 +535,10 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_ sf::err().rdbuf(&states->logcat); // Launch the main thread - sf::Thread* thread = new sf::Thread(sf::priv::main, states); - thread->launch(); + auto thread = new std::thread([states] + { + sf::priv::main(states); + }); // Wait for the main thread to be initialized states->mutex.lock(); diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp index bd6bbc9a..772ab70e 100644 --- a/src/SFML/System/Android/Activity.hpp +++ b/src/SFML/System/Android/Activity.hpp @@ -30,7 +30,6 @@ //////////////////////////////////////////////////////////// #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include class SFML_SYSTEM_API LogcatStream : public std::streambuf { @@ -69,7 +69,7 @@ struct ActivityStates void* savedState; size_t savedStateSize; - Mutex mutex; + std::mutex mutex; void (*forwardEvent)(const Event& event); int (*processEvent)(int fd, int events, void* data); diff --git a/src/SFML/System/Android/ResourceStream.cpp b/src/SFML/System/Android/ResourceStream.cpp index 93280aa6..b6f2b390 100644 --- a/src/SFML/System/Android/ResourceStream.cpp +++ b/src/SFML/System/Android/ResourceStream.cpp @@ -28,7 +28,7 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include namespace sf @@ -41,7 +41,7 @@ ResourceStream::ResourceStream(const std::string& filename) : m_file (NULL) { ActivityStates* states = getActivity(NULL); - Lock(states->mutex); + std::lock_guard lock(states->mutex); m_file = AAssetManager_open(states->activity->assetManager, filename.c_str(), AASSET_MODE_UNKNOWN); } diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 54da9a07..dbac1081 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -10,10 +10,6 @@ set(SRC ${INCROOT}/Err.hpp ${INCROOT}/Export.hpp ${INCROOT}/InputStream.hpp - ${SRCROOT}/Lock.cpp - ${INCROOT}/Lock.hpp - ${SRCROOT}/Mutex.cpp - ${INCROOT}/Mutex.hpp ${INCROOT}/NativeActivity.hpp ${INCROOT}/NonCopyable.hpp ${SRCROOT}/Sleep.cpp @@ -21,13 +17,6 @@ set(SRC ${SRCROOT}/String.cpp ${INCROOT}/String.hpp ${INCROOT}/String.inl - ${SRCROOT}/Thread.cpp - ${INCROOT}/Thread.hpp - ${INCROOT}/Thread.inl - ${SRCROOT}/ThreadLocal.cpp - ${INCROOT}/ThreadLocal.hpp - ${INCROOT}/ThreadLocalPtr.hpp - ${INCROOT}/ThreadLocalPtr.inl ${SRCROOT}/Time.cpp ${INCROOT}/Time.hpp ${INCROOT}/Utf.hpp @@ -48,28 +37,16 @@ if(SFML_OS_WINDOWS) set(PLATFORM_SRC ${SRCROOT}/Win32/ClockImpl.cpp ${SRCROOT}/Win32/ClockImpl.hpp - ${SRCROOT}/Win32/MutexImpl.cpp - ${SRCROOT}/Win32/MutexImpl.hpp ${SRCROOT}/Win32/SleepImpl.cpp ${SRCROOT}/Win32/SleepImpl.hpp - ${SRCROOT}/Win32/ThreadImpl.cpp - ${SRCROOT}/Win32/ThreadImpl.hpp - ${SRCROOT}/Win32/ThreadLocalImpl.cpp - ${SRCROOT}/Win32/ThreadLocalImpl.hpp ) source_group("windows" FILES ${PLATFORM_SRC}) else() set(PLATFORM_SRC ${SRCROOT}/Unix/ClockImpl.cpp ${SRCROOT}/Unix/ClockImpl.hpp - ${SRCROOT}/Unix/MutexImpl.cpp - ${SRCROOT}/Unix/MutexImpl.hpp ${SRCROOT}/Unix/SleepImpl.cpp ${SRCROOT}/Unix/SleepImpl.hpp - ${SRCROOT}/Unix/ThreadImpl.cpp - ${SRCROOT}/Unix/ThreadImpl.hpp - ${SRCROOT}/Unix/ThreadLocalImpl.cpp - ${SRCROOT}/Unix/ThreadLocalImpl.hpp ) if(SFML_OS_ANDROID) diff --git a/src/SFML/System/Lock.cpp b/src/SFML/System/Lock.cpp deleted file mode 100644 index 4a371271..00000000 --- a/src/SFML/System/Lock.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -//////////////////////////////////////////////////////////// -Lock::Lock(Mutex& mutex) : -m_mutex(mutex) -{ - m_mutex.lock(); -} - - -//////////////////////////////////////////////////////////// -Lock::~Lock() -{ - m_mutex.unlock(); -} - -} // namespace sf diff --git a/src/SFML/System/Mutex.cpp b/src/SFML/System/Mutex.cpp deleted file mode 100644 index e204ae04..00000000 --- a/src/SFML/System/Mutex.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - -#if defined(SFML_SYSTEM_WINDOWS) - #include -#else - #include -#endif - - -namespace sf -{ -//////////////////////////////////////////////////////////// -Mutex::Mutex() -{ - m_mutexImpl = std::make_shared(); -} - - -//////////////////////////////////////////////////////////// -Mutex::~Mutex() = default; - - -//////////////////////////////////////////////////////////// -void Mutex::lock() -{ - m_mutexImpl->lock(); -} - - -//////////////////////////////////////////////////////////// -void Mutex::unlock() -{ - m_mutexImpl->unlock(); -} - -} // namespace sf diff --git a/src/SFML/System/Thread.cpp b/src/SFML/System/Thread.cpp deleted file mode 100644 index c708fdc0..00000000 --- a/src/SFML/System/Thread.cpp +++ /dev/null @@ -1,83 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -#if defined(SFML_SYSTEM_WINDOWS) - #include -#else - #include -#endif - - -namespace sf -{ -//////////////////////////////////////////////////////////// -Thread::~Thread() -{ - wait(); -} - - -//////////////////////////////////////////////////////////// -void Thread::launch() -{ - wait(); - m_impl = std::make_shared(this); -} - - -//////////////////////////////////////////////////////////// -void Thread::wait() -{ - if (m_impl) - { - m_impl->wait(); - m_impl.reset(); - } -} - - -//////////////////////////////////////////////////////////// -void Thread::terminate() -{ - if (m_impl) - { - m_impl->terminate(); - m_impl.reset(); - } -} - - -//////////////////////////////////////////////////////////// -void Thread::run() -{ - m_entryPoint->run(); -} - -} // namespace sf diff --git a/src/SFML/System/ThreadLocal.cpp b/src/SFML/System/ThreadLocal.cpp deleted file mode 100644 index 6a3cc8c7..00000000 --- a/src/SFML/System/ThreadLocal.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - -#if defined(SFML_SYSTEM_WINDOWS) - #include -#else - #include -#endif - - -namespace sf -{ -//////////////////////////////////////////////////////////// -ThreadLocal::ThreadLocal(void* value) -{ - m_impl = std::make_unique(); - setValue(value); -} - - -//////////////////////////////////////////////////////////// -ThreadLocal::~ThreadLocal() = default; - - -//////////////////////////////////////////////////////////// -void ThreadLocal::setValue(void* value) -{ - m_impl->setValue(value); -} - - -//////////////////////////////////////////////////////////// -void* ThreadLocal::getValue() const -{ - return m_impl->getValue(); -} - -} // namespace sf diff --git a/src/SFML/System/Unix/MutexImpl.cpp b/src/SFML/System/Unix/MutexImpl.cpp deleted file mode 100644 index 2ab46c0e..00000000 --- a/src/SFML/System/Unix/MutexImpl.cpp +++ /dev/null @@ -1,69 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -MutexImpl::MutexImpl() -{ - // Make it recursive to follow the expected behavior - pthread_mutexattr_t attributes; - pthread_mutexattr_init(&attributes); - pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE); - - pthread_mutex_init(&m_mutex, &attributes); -} - - -//////////////////////////////////////////////////////////// -MutexImpl::~MutexImpl() -{ - pthread_mutex_destroy(&m_mutex); -} - - -//////////////////////////////////////////////////////////// -void MutexImpl::lock() -{ - pthread_mutex_lock(&m_mutex); -} - - -//////////////////////////////////////////////////////////// -void MutexImpl::unlock() -{ - pthread_mutex_unlock(&m_mutex); -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Unix/MutexImpl.hpp b/src/SFML/System/Unix/MutexImpl.hpp deleted file mode 100644 index ea4c838f..00000000 --- a/src/SFML/System/Unix/MutexImpl.hpp +++ /dev/null @@ -1,83 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_MUTEXIMPL_HPP -#define SFML_MUTEXIMPL_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Unix implementation of mutexes -//////////////////////////////////////////////////////////// -class MutexImpl : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - //////////////////////////////////////////////////////////// - MutexImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - //////////////////////////////////////////////////////////// - ~MutexImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Lock the mutex - /// - //////////////////////////////////////////////////////////// - void lock(); - - //////////////////////////////////////////////////////////// - /// \brief Unlock the mutex - /// - //////////////////////////////////////////////////////////// - void unlock(); - -private: - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - pthread_mutex_t m_mutex; ///< pthread handle of the mutex -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_MUTEXIMPL_HPP diff --git a/src/SFML/System/Unix/ThreadImpl.cpp b/src/SFML/System/Unix/ThreadImpl.cpp deleted file mode 100644 index b6dd383c..00000000 --- a/src/SFML/System/Unix/ThreadImpl.cpp +++ /dev/null @@ -1,94 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -ThreadImpl::ThreadImpl(Thread* owner) : -m_isActive(true) -{ - m_isActive = pthread_create(&m_thread, NULL, &ThreadImpl::entryPoint, owner) == 0; - - if (!m_isActive) - std::cerr << "Failed to create thread" << std::endl; -} - - -//////////////////////////////////////////////////////////// -void ThreadImpl::wait() -{ - if (m_isActive) - { - assert(pthread_equal(pthread_self(), m_thread) == 0); // A thread cannot wait for itself! - pthread_join(m_thread, NULL); - } -} - - -//////////////////////////////////////////////////////////// -void ThreadImpl::terminate() -{ - if (m_isActive) - { - #ifndef SFML_SYSTEM_ANDROID - pthread_cancel(m_thread); - #else - // See http://stackoverflow.com/questions/4610086/pthread-cancel-al - pthread_kill(m_thread, SIGUSR1); - #endif - } -} - - -//////////////////////////////////////////////////////////// -void* ThreadImpl::entryPoint(void* userData) -{ - // The Thread instance is stored in the user data - Thread* owner = static_cast(userData); - - #ifndef SFML_SYSTEM_ANDROID - // Tell the thread to handle cancel requests immediately - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - #endif - - // Forward to the owner - owner->run(); - - return NULL; -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Unix/ThreadImpl.hpp b/src/SFML/System/Unix/ThreadImpl.hpp deleted file mode 100644 index 0191d5e2..00000000 --- a/src/SFML/System/Unix/ThreadImpl.hpp +++ /dev/null @@ -1,93 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREADIMPL_HPP -#define SFML_THREADIMPL_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include - - -namespace sf -{ -class Thread; - -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Unix implementation of threads -//////////////////////////////////////////////////////////// -class ThreadImpl : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor, launch the thread - /// - /// \param owner The Thread instance to run - /// - //////////////////////////////////////////////////////////// - ThreadImpl(Thread* owner); - - //////////////////////////////////////////////////////////// - /// \brief Wait until the thread finishes - /// - //////////////////////////////////////////////////////////// - void wait(); - - //////////////////////////////////////////////////////////// - /// \brief Terminate the thread - /// - //////////////////////////////////////////////////////////// - void terminate(); - -private: - - //////////////////////////////////////////////////////////// - /// \brief Global entry point for all threads - /// - /// \param userData User-defined data (contains the Thread instance) - /// - /// \return Os specific error code - /// - //////////////////////////////////////////////////////////// - static void* entryPoint(void* userData); - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - pthread_t m_thread; ///< pthread thread instance - bool m_isActive; ///< Thread state (active or inactive) -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_THREADIMPL_HPP diff --git a/src/SFML/System/Unix/ThreadLocalImpl.cpp b/src/SFML/System/Unix/ThreadLocalImpl.cpp deleted file mode 100644 index a0a157e2..00000000 --- a/src/SFML/System/Unix/ThreadLocalImpl.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -ThreadLocalImpl::ThreadLocalImpl() : -m_key(0) -{ - pthread_key_create(&m_key, NULL); -} - - -//////////////////////////////////////////////////////////// -ThreadLocalImpl::~ThreadLocalImpl() -{ - pthread_key_delete(m_key); -} - - -//////////////////////////////////////////////////////////// -void ThreadLocalImpl::setValue(void* value) -{ - pthread_setspecific(m_key, value); -} - - -//////////////////////////////////////////////////////////// -void* ThreadLocalImpl::getValue() const -{ - return pthread_getspecific(m_key); -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Unix/ThreadLocalImpl.hpp b/src/SFML/System/Unix/ThreadLocalImpl.hpp deleted file mode 100644 index b72ce65f..00000000 --- a/src/SFML/System/Unix/ThreadLocalImpl.hpp +++ /dev/null @@ -1,87 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREADLOCALIMPL_HPP -#define SFML_THREADLOCALIMPL_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Unix implementation of thread-local storage -//////////////////////////////////////////////////////////// -class ThreadLocalImpl : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor -- allocate the storage - /// - //////////////////////////////////////////////////////////// - ThreadLocalImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Destructor -- free the storage - /// - //////////////////////////////////////////////////////////// - ~ThreadLocalImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Set the thread-specific value of the variable - /// - /// \param value Value of the variable for this thread - /// - //////////////////////////////////////////////////////////// - void setValue(void* value); - - //////////////////////////////////////////////////////////// - /// \brief Retrieve the thread-specific value of the variable - /// - /// \return Value of the variable for this thread - /// - //////////////////////////////////////////////////////////// - void* getValue() const; - -private: - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - pthread_key_t m_key; ///< Index of our thread-local storage slot -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_THREADLOCALIMPL_HPP diff --git a/src/SFML/System/Win32/ClockImpl.cpp b/src/SFML/System/Win32/ClockImpl.cpp index c81288d2..b41f4e76 100644 --- a/src/SFML/System/Win32/ClockImpl.cpp +++ b/src/SFML/System/Win32/ClockImpl.cpp @@ -26,9 +26,8 @@ // Headers //////////////////////////////////////////////////////////// #include -#include -#include #include +#include namespace sf { @@ -57,10 +56,10 @@ Time ClockImpl::getCurrentTime() if (oldWindows) { - static sf::Mutex oldWindowsMutex; + static std::mutex oldWindowsMutex; - // Acquire a lock (CRITICAL_SECTION) to prevent travelling back in time - Lock lock(oldWindowsMutex); + // Acquire a lock to prevent travelling back in time + std::lock_guard lock(oldWindowsMutex); // Get the current time QueryPerformanceCounter(&time); diff --git a/src/SFML/System/Win32/MutexImpl.cpp b/src/SFML/System/Win32/MutexImpl.cpp deleted file mode 100644 index 7b47cd51..00000000 --- a/src/SFML/System/Win32/MutexImpl.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -MutexImpl::MutexImpl() -{ - InitializeCriticalSection(&m_mutex); -} - - -//////////////////////////////////////////////////////////// -MutexImpl::~MutexImpl() -{ - DeleteCriticalSection(&m_mutex); -} - - -//////////////////////////////////////////////////////////// -void MutexImpl::lock() -{ - EnterCriticalSection(&m_mutex); -} - - -//////////////////////////////////////////////////////////// -void MutexImpl::unlock() -{ - LeaveCriticalSection(&m_mutex); -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Win32/MutexImpl.hpp b/src/SFML/System/Win32/MutexImpl.hpp deleted file mode 100644 index c7174e8b..00000000 --- a/src/SFML/System/Win32/MutexImpl.hpp +++ /dev/null @@ -1,83 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_MUTEXIMPL_HPP -#define SFML_MUTEXIMPL_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Windows implementation of mutexes -//////////////////////////////////////////////////////////// -class MutexImpl : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - //////////////////////////////////////////////////////////// - MutexImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - //////////////////////////////////////////////////////////// - ~MutexImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Lock the mutex - /// - //////////////////////////////////////////////////////////// - void lock(); - - //////////////////////////////////////////////////////////// - /// \brief Unlock the mutex - /// - //////////////////////////////////////////////////////////// - void unlock(); - -private: - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - CRITICAL_SECTION m_mutex; ///< Win32 handle of the mutex -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_MUTEXIMPL_HPP diff --git a/src/SFML/System/Win32/ThreadImpl.cpp b/src/SFML/System/Win32/ThreadImpl.cpp deleted file mode 100644 index d34950ab..00000000 --- a/src/SFML/System/Win32/ThreadImpl.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -ThreadImpl::ThreadImpl(Thread* owner) -{ - m_thread = reinterpret_cast(_beginthreadex(NULL, 0, &ThreadImpl::entryPoint, owner, 0, &m_threadId)); - - if (!m_thread) - err() << "Failed to create thread" << std::endl; -} - - -//////////////////////////////////////////////////////////// -ThreadImpl::~ThreadImpl() -{ - if (m_thread) - CloseHandle(m_thread); -} - - -//////////////////////////////////////////////////////////// -void ThreadImpl::wait() -{ - if (m_thread) - { - assert(m_threadId != GetCurrentThreadId()); // A thread cannot wait for itself! - WaitForSingleObject(m_thread, INFINITE); - } -} - - -//////////////////////////////////////////////////////////// -void ThreadImpl::terminate() -{ - if (m_thread) - TerminateThread(m_thread, 0); -} - - -//////////////////////////////////////////////////////////// -unsigned int __stdcall ThreadImpl::entryPoint(void* userData) -{ - // The Thread instance is stored in the user data - Thread* owner = static_cast(userData); - - // Forward to the owner - owner->run(); - - // Optional, but it is cleaner - _endthreadex(0); - - return 0; -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Win32/ThreadImpl.hpp b/src/SFML/System/Win32/ThreadImpl.hpp deleted file mode 100644 index cfd10399..00000000 --- a/src/SFML/System/Win32/ThreadImpl.hpp +++ /dev/null @@ -1,109 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREADIMPL_HPP -#define SFML_THREADIMPL_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - -// Fix for unaligned stack with clang and GCC on Windows XP 32-bit -#if defined(SFML_SYSTEM_WINDOWS) && (defined(__clang__) || defined(__GNUC__)) - - #define ALIGN_STACK __attribute__((__force_align_arg_pointer__)) - -#else - - #define ALIGN_STACK - -#endif - - -namespace sf -{ -class Thread; - -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Windows implementation of threads -//////////////////////////////////////////////////////////// -class ThreadImpl : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor, launch the thread - /// - /// \param owner The Thread instance to run - /// - //////////////////////////////////////////////////////////// - ThreadImpl(Thread* owner); - - //////////////////////////////////////////////////////////// - /// \brief Destructor - /// - //////////////////////////////////////////////////////////// - ~ThreadImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Wait until the thread finishes - /// - //////////////////////////////////////////////////////////// - void wait(); - - //////////////////////////////////////////////////////////// - /// \brief Terminate the thread - /// - //////////////////////////////////////////////////////////// - void terminate(); - -private: - - //////////////////////////////////////////////////////////// - /// \brief Global entry point for all threads - /// - /// \param userData User-defined data (contains the Thread instance) - /// - /// \return OS specific error code - /// - //////////////////////////////////////////////////////////// - ALIGN_STACK static unsigned int __stdcall entryPoint(void* userData); - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - HANDLE m_thread; ///< Win32 thread handle - unsigned int m_threadId; ///< Win32 thread identifier -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_THREADIMPL_HPP diff --git a/src/SFML/System/Win32/ThreadLocalImpl.cpp b/src/SFML/System/Win32/ThreadLocalImpl.cpp deleted file mode 100644 index 221fffe9..00000000 --- a/src/SFML/System/Win32/ThreadLocalImpl.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -ThreadLocalImpl::ThreadLocalImpl() -{ - m_index = TlsAlloc(); -} - - -//////////////////////////////////////////////////////////// -ThreadLocalImpl::~ThreadLocalImpl() -{ - TlsFree(m_index); -} - - -//////////////////////////////////////////////////////////// -void ThreadLocalImpl::setValue(void* value) -{ - TlsSetValue(m_index, value); -} - - -//////////////////////////////////////////////////////////// -void* ThreadLocalImpl::getValue() const -{ - return TlsGetValue(m_index); -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Win32/ThreadLocalImpl.hpp b/src/SFML/System/Win32/ThreadLocalImpl.hpp deleted file mode 100644 index 458b28a5..00000000 --- a/src/SFML/System/Win32/ThreadLocalImpl.hpp +++ /dev/null @@ -1,87 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREADLOCALIMPL_HPP -#define SFML_THREADLOCALIMPL_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Windows implementation of thread-local storage -//////////////////////////////////////////////////////////// -class ThreadLocalImpl : NonCopyable -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor -- allocate the storage - /// - //////////////////////////////////////////////////////////// - ThreadLocalImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Destructor -- free the storage - /// - //////////////////////////////////////////////////////////// - ~ThreadLocalImpl(); - - //////////////////////////////////////////////////////////// - /// \brief Set the thread-specific value of the variable - /// - /// \param value Value of the variable for this thread - /// - //////////////////////////////////////////////////////////// - void setValue(void* value); - - //////////////////////////////////////////////////////////// - /// \brief Retrieve the thread-specific value of the variable - /// - /// \return Value of the variable for this thread - /// - //////////////////////////////////////////////////////////// - void* getValue() const; - -private: - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - DWORD m_index; ///< Index of our thread-local storage slot -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_THREADLOCALIMPL_HPP diff --git a/src/SFML/Window/Android/InputImpl.cpp b/src/SFML/Window/Android/InputImpl.cpp index 9da3a131..3108f78c 100644 --- a/src/SFML/Window/Android/InputImpl.cpp +++ b/src/SFML/Window/Android/InputImpl.cpp @@ -27,9 +27,9 @@ //////////////////////////////////////////////////////////// #include #include -#include #include #include +#include namespace sf @@ -49,7 +49,7 @@ void InputImpl::setVirtualKeyboardVisible(bool visible) // todo: Check if the window is active ActivityStates* states = getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Initializes JNI jint lResult; @@ -139,7 +139,7 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) ALooper_pollAll(0, NULL, NULL, NULL); priv::ActivityStates* states = priv::getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); return states->isButtonPressed[button]; } @@ -151,7 +151,7 @@ Vector2i InputImpl::getMousePosition() ALooper_pollAll(0, NULL, NULL, NULL); priv::ActivityStates* states = priv::getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); return states->mousePosition; } @@ -184,7 +184,7 @@ bool InputImpl::isTouchDown(unsigned int finger) ALooper_pollAll(0, NULL, NULL, NULL); priv::ActivityStates* states = priv::getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); return states->touchEvents.find(finger) != states->touchEvents.end(); } @@ -196,7 +196,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int finger) ALooper_pollAll(0, NULL, NULL, NULL); priv::ActivityStates* states = priv::getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); return states->touchEvents.find(finger)->second; } diff --git a/src/SFML/Window/Android/VideoModeImpl.cpp b/src/SFML/Window/Android/VideoModeImpl.cpp index d9c171c1..4d11ad61 100644 --- a/src/SFML/Window/Android/VideoModeImpl.cpp +++ b/src/SFML/Window/Android/VideoModeImpl.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include namespace sf { @@ -53,7 +53,7 @@ VideoMode VideoModeImpl::getDesktopMode() { // Get the activity states priv::ActivityStates* states = priv::getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); return VideoMode(states->screenSize.x, states->screenSize.y); } diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index 27d2f10e..6f226890 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -29,9 +29,9 @@ #include // important to be included first (conflict with None) #include #include -#include #include #include +#include // Define missing constants for older API levels #if __ANDROID_API__ < 13 @@ -66,7 +66,7 @@ WindowImplAndroid::WindowImplAndroid(VideoMode mode, const String& title, unsign , m_hasFocus(false) { ActivityStates* states = getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); if (style& Style::Fullscreen) states->fullscreen = true; @@ -91,7 +91,7 @@ WindowImplAndroid::~WindowImplAndroid() WindowHandle WindowImplAndroid::getSystemHandle() const { ActivityStates* states = getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); return states->window; } @@ -104,7 +104,7 @@ void WindowImplAndroid::processEvents() ALooper_pollAll(0, NULL, NULL, NULL); ActivityStates* states = getActivity(NULL); - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); if (m_windowBeingCreated) { @@ -232,7 +232,7 @@ void WindowImplAndroid::forwardEvent(const Event& event) int WindowImplAndroid::processEvent(int fd, int events, void* data) { ActivityStates* states = getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); AInputEvent* _event = NULL; @@ -666,7 +666,7 @@ int WindowImplAndroid::getUnicode(AInputEvent* event) { // Retrieve activity states ActivityStates* states = getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); // Initializes JNI jint lResult; diff --git a/src/SFML/Window/Context.cpp b/src/SFML/Window/Context.cpp index 05bddfc0..b59e4deb 100644 --- a/src/SFML/Window/Context.cpp +++ b/src/SFML/Window/Context.cpp @@ -27,13 +27,12 @@ //////////////////////////////////////////////////////////// #include #include -#include namespace { // This per-thread variable holds the current context for each thread - sf::ThreadLocalPtr currentContext(NULL); + thread_local sf::Context* currentContext = nullptr; } namespace sf diff --git a/src/SFML/Window/EglContext.cpp b/src/SFML/Window/EglContext.cpp index 03c41979..d1893886 100644 --- a/src/SFML/Window/EglContext.cpp +++ b/src/SFML/Window/EglContext.cpp @@ -31,14 +31,13 @@ #include #include #include -#include -#include #ifdef SFML_SYSTEM_ANDROID #include #endif #ifdef SFML_SYSTEM_LINUX #include #endif +#include namespace { @@ -60,7 +59,7 @@ namespace // On Android, its native activity handles this for us sf::priv::ActivityStates* states = sf::priv::getActivity(NULL); - sf::Lock lock(states->mutex); + std::lock_guard lock(states->mutex); return states->display; @@ -113,7 +112,7 @@ m_config (NULL) // On Android, we must save the created context ActivityStates* states = getActivity(NULL); - Lock lock(states->mutex); + std::lock_guard lock(states->mutex); states->context = this; diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 1dbbde33..e4695be1 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -27,15 +27,13 @@ //////////////////////////////////////////////////////////// #include #include -#include -#include -#include #include #include #include #include #include #include +#include #include #include #include @@ -134,13 +132,13 @@ namespace // This mutex is also used to protect the shared context // from being locked on multiple threads and for managing // the resource count - sf::Mutex mutex; + std::recursive_mutex mutex; // OpenGL resources counter unsigned int resourceCount = 0; // This per-thread variable holds the current context for each thread - sf::ThreadLocalPtr currentContext(NULL); + thread_local sf::priv::GlContext* currentContext = nullptr; // The hidden, inactive context that will be shared with all other contexts std::unique_ptr sharedContext; @@ -163,7 +161,7 @@ namespace } else if (!currentContext) { - sharedContextLock = std::make_unique(mutex); + sharedContextLock = std::make_unique>(mutex); useSharedContext = true; sharedContext->setActive(true); } @@ -184,7 +182,7 @@ namespace //////////////////////////////////////////////////////////// unsigned int referenceCount; std::unique_ptr context; - std::unique_ptr sharedContextLock; + std::unique_ptr> sharedContextLock; bool useSharedContext; }; @@ -205,7 +203,7 @@ namespace priv void GlContext::initResource() { // Protect from concurrent access - Lock lock(mutex); + std::lock_guard lock(mutex); // If this is the very first resource, trigger the global context initialization if (resourceCount == 0) @@ -281,7 +279,7 @@ void GlContext::initResource() void GlContext::cleanupResource() { // Protect from concurrent access - Lock lock(mutex); + std::lock_guard lock(mutex); // Decrement the resources counter resourceCount--; @@ -299,7 +297,7 @@ void GlContext::cleanupResource() void GlContext::acquireTransientContext() { // Protect from concurrent access - Lock lock(mutex); + std::lock_guard lock(mutex); // If this is the first TransientContextLock on this thread // construct the state object @@ -315,7 +313,7 @@ void GlContext::acquireTransientContext() void GlContext::releaseTransientContext() { // Protect from concurrent access - Lock lock(mutex); + std::lock_guard lock(mutex); // Make sure a matching acquireTransientContext() was called assert(transientContext); @@ -336,7 +334,7 @@ std::unique_ptr GlContext::create() // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != NULL); - Lock lock(mutex); + std::lock_guard lock(mutex); std::unique_ptr context; @@ -364,7 +362,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, co // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != NULL); - Lock lock(mutex); + std::lock_guard lock(mutex); std::unique_ptr context; @@ -393,7 +391,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, un // Make sure that there's an active context (context creation may need extensions, and thus a valid context) assert(sharedContext != NULL); - Lock lock(mutex); + std::lock_guard lock(mutex); std::unique_ptr context; @@ -428,7 +426,7 @@ GlFunctionPointer GlContext::getFunction(const char* name) { #if !defined(SFML_OPENGL_ES) - Lock lock(mutex); + std::lock_guard lock(mutex); return ContextType::getFunction(name); @@ -466,7 +464,7 @@ bool GlContext::setActive(bool active) { if (this != currentContext) { - Lock lock(mutex); + std::lock_guard lock(mutex); // Activate the context if (makeCurrent(true)) @@ -490,7 +488,7 @@ bool GlContext::setActive(bool active) { if (this == currentContext) { - Lock lock(mutex); + std::lock_guard lock(mutex); // Deactivate the context if (makeCurrent(false)) diff --git a/src/SFML/Window/Unix/Display.cpp b/src/SFML/Window/Unix/Display.cpp index 60f4c55a..5d6a3142 100644 --- a/src/SFML/Window/Unix/Display.cpp +++ b/src/SFML/Window/Unix/Display.cpp @@ -26,12 +26,11 @@ // Headers //////////////////////////////////////////////////////////// #include -#include -#include #include #include #include #include +#include #include @@ -40,7 +39,7 @@ namespace // The shared display and its reference counter Display* sharedDisplay = NULL; unsigned int referenceCount = 0; - sf::Mutex mutex; + std::mutex mutex; typedef std::map AtomMap; AtomMap atoms; @@ -53,7 +52,7 @@ namespace priv //////////////////////////////////////////////////////////// Display* OpenDisplay() { - Lock lock(mutex); + std::lock_guard lock(mutex); if (referenceCount == 0) { @@ -76,7 +75,7 @@ Display* OpenDisplay() //////////////////////////////////////////////////////////// void CloseDisplay(Display* display) { - Lock lock(mutex); + std::lock_guard lock(mutex); assert(display == sharedDisplay); diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index b16c0e28..28d9f3de 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -28,10 +28,9 @@ #include #include #include -#include -#include #include #include +#include #if !defined(GLX_DEBUGGING) && defined(SFML_DEBUG) // Enable this to print messages to err() everytime GLX produces errors @@ -40,7 +39,7 @@ namespace { - sf::Mutex glxErrorMutex; + std::mutex glxErrorMutex; bool glxErrorOccurred = false; int HandleXError(::Display*, XErrorEvent*) @@ -68,9 +67,9 @@ namespace } private: - sf::Lock m_lock; - ::Display* m_display; - int (*m_previousHandler)(::Display*, XErrorEvent*); + std::lock_guard m_lock; + ::Display* m_display; + int (*m_previousHandler)(::Display*, XErrorEvent*); }; } diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index f14f69b0..64886443 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -31,8 +31,6 @@ #include #include #include -#include -#include #include #include #include @@ -47,6 +45,7 @@ #include #include #include +#include #include #ifdef SFML_OPENGL_ES @@ -64,7 +63,7 @@ namespace { sf::priv::WindowImplX11* fullscreenWindow = NULL; std::vector allWindows; - sf::Mutex allWindowsMutex; + std::mutex allWindowsMutex; sf::String windowManagerName; static const unsigned long eventMask = FocusChangeMask | ButtonPressMask | @@ -649,7 +648,7 @@ WindowImplX11::~WindowImplX11() CloseDisplay(m_display); // Remove this window from the global list of windows (required for focus request) - Lock lock(allWindowsMutex); + std::lock_guard lock(allWindowsMutex); allWindows.erase(std::find(allWindows.begin(), allWindows.end(), this)); } @@ -950,7 +949,7 @@ void WindowImplX11::requestFocus() bool sfmlWindowFocused = false; { - Lock lock(allWindowsMutex); + std::lock_guard lock(allWindowsMutex); for (std::vector::iterator itr = allWindows.begin(); itr != allWindows.end(); ++itr) { if ((*itr)->hasFocus()) @@ -1313,7 +1312,7 @@ void WindowImplX11::initialize() XFlush(m_display); // Add this window to the global list of windows (required for focus request) - Lock lock(allWindowsMutex); + std::lock_guard lock(allWindowsMutex); allWindows.push_back(this); } diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index c2a813f7..6037b0dc 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -28,9 +28,6 @@ #include // included first to avoid a warning about macro redefinition #include // included second to avoid an error in WglExtensions.hpp #include -#include -#include -#include #include #include #include @@ -41,7 +38,7 @@ namespace { // Some drivers are bugged and don't track the current HDC/HGLRC properly // In order to deactivate successfully, we need to track it ourselves as well - sf::ThreadLocalPtr currentContext(NULL); + thread_local sf::priv::WglContext* currentContext = nullptr; } @@ -636,8 +633,8 @@ void WglContext::createContext(WglContext* shared) if (sharedContext) { - static Mutex mutex; - Lock lock(mutex); + static std::mutex mutex; + std::lock_guard lock(mutex); if (currentContext == shared) { @@ -706,8 +703,8 @@ void WglContext::createContext(WglContext* shared) if (sharedContext) { // wglShareLists doesn't seem to be thread-safe - static Mutex mutex; - Lock lock(mutex); + static std::mutex mutex; + std::lock_guard lock(mutex); if (currentContext == shared) { From 0000fa3e5ec7a47bc35f7e11c1ab08742fcca5f3 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sun, 2 Apr 2017 03:27:05 +0200 Subject: [PATCH 09/18] Replaced Clock, Time and Sleep implementations with std::chrono based ones. --- include/SFML/System/Time.hpp | 48 ++++++++++++++---- src/SFML/System/CMakeLists.txt | 31 +++-------- src/SFML/System/Clock.cpp | 22 +++++--- src/SFML/System/Sleep.cpp | 10 ++-- src/SFML/System/Time.cpp | 30 ++++++++--- src/SFML/System/Unix/ClockImpl.cpp | 64 ----------------------- src/SFML/System/Unix/ClockImpl.hpp | 61 ---------------------- src/SFML/System/Unix/SleepImpl.cpp | 59 --------------------- src/SFML/System/Unix/SleepImpl.hpp | 52 ------------------- src/SFML/System/Win32/ClockImpl.cpp | 79 ----------------------------- src/SFML/System/Win32/ClockImpl.hpp | 61 ---------------------- src/SFML/System/Win32/SleepImpl.cpp | 55 -------------------- src/SFML/System/Win32/SleepImpl.hpp | 52 ------------------- 13 files changed, 83 insertions(+), 541 deletions(-) delete mode 100644 src/SFML/System/Unix/ClockImpl.cpp delete mode 100644 src/SFML/System/Unix/ClockImpl.hpp delete mode 100644 src/SFML/System/Unix/SleepImpl.cpp delete mode 100644 src/SFML/System/Unix/SleepImpl.hpp delete mode 100644 src/SFML/System/Win32/ClockImpl.cpp delete mode 100644 src/SFML/System/Win32/ClockImpl.hpp delete mode 100644 src/SFML/System/Win32/SleepImpl.cpp delete mode 100644 src/SFML/System/Win32/SleepImpl.hpp diff --git a/include/SFML/System/Time.hpp b/include/SFML/System/Time.hpp index 4dff9283..b33ba998 100644 --- a/include/SFML/System/Time.hpp +++ b/include/SFML/System/Time.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include namespace sf @@ -54,7 +55,7 @@ public: /// /// \return Time in seconds /// - /// \see asMilliseconds, asMicroseconds + /// \see asMilliseconds, asMicroseconds, asNanoseconds /// //////////////////////////////////////////////////////////// float asSeconds() const; @@ -64,7 +65,7 @@ public: /// /// \return Time in milliseconds /// - /// \see asSeconds, asMicroseconds + /// \see asSeconds, asMicroseconds, asNanoseconds /// //////////////////////////////////////////////////////////// Int32 asMilliseconds() const; @@ -74,11 +75,21 @@ public: /// /// \return Time in microseconds /// - /// \see asSeconds, asMilliseconds + /// \see asSeconds, asMilliseconds, asNanoseconds /// //////////////////////////////////////////////////////////// Int64 asMicroseconds() const; + //////////////////////////////////////////////////////////// + /// \brief Return the time value as a number of nanoseconds + /// + /// \return Time in nanoseconds + /// + /// \see asSeconds, asMilliseconds, asMicroseconds + /// + //////////////////////////////////////////////////////////// + Int64 asNanoseconds() const; + //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// @@ -89,24 +100,26 @@ private: friend SFML_SYSTEM_API Time seconds(float); friend SFML_SYSTEM_API Time milliseconds(Int32); friend SFML_SYSTEM_API Time microseconds(Int64); + friend SFML_SYSTEM_API Time nanoseconds(Int64); //////////////////////////////////////////////////////////// - /// \brief Construct from a number of microseconds + /// \brief Construct from a number of nanoseconds /// /// This function is internal. To construct time values, - /// use sf::seconds, sf::milliseconds or sf::microseconds instead. + /// use sf::seconds, sf::milliseconds, sf::microseconds + /// or sf::nanoseconds instead. /// - /// \param microseconds Number of microseconds + /// \param nanoseconds Number of nanoseconds /// //////////////////////////////////////////////////////////// - explicit Time(Int64 microseconds); + explicit Time(Int64 nanoseconds); private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Int64 m_microseconds; ///< Time value stored as microseconds + std::chrono::nanoseconds m_nanoseconds; ///< Time value stored as nanoseconds }; //////////////////////////////////////////////////////////// @@ -117,7 +130,7 @@ private: /// /// \return Time value constructed from the amount of seconds /// -/// \see milliseconds, microseconds +/// \see milliseconds, microseconds, nanoseconds /// //////////////////////////////////////////////////////////// SFML_SYSTEM_API Time seconds(float amount); @@ -130,7 +143,7 @@ SFML_SYSTEM_API Time seconds(float amount); /// /// \return Time value constructed from the amount of milliseconds /// -/// \see seconds, microseconds +/// \see seconds, microseconds, nanoseconds /// //////////////////////////////////////////////////////////// SFML_SYSTEM_API Time milliseconds(Int32 amount); @@ -143,11 +156,24 @@ SFML_SYSTEM_API Time milliseconds(Int32 amount); /// /// \return Time value constructed from the amount of microseconds /// -/// \see seconds, milliseconds +/// \see seconds, milliseconds, nanoseconds /// //////////////////////////////////////////////////////////// SFML_SYSTEM_API Time microseconds(Int64 amount); +//////////////////////////////////////////////////////////// +/// \relates Time +/// \brief Construct a time value from a number of nanoseconds +/// +/// \param amount Number of nanoseconds +/// +/// \return Time value constructed from the amount of nanoseconds +/// +/// \see seconds, milliseconds, microseconds +/// +//////////////////////////////////////////////////////////// +SFML_SYSTEM_API Time nanoseconds(Int64 amount); + //////////////////////////////////////////////////////////// /// \relates Time /// \brief Overload of == operator to compare two time values diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index dbac1081..683f23f8 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -33,31 +33,14 @@ set(SRC source_group("" FILES ${SRC}) # add platform specific sources -if(SFML_OS_WINDOWS) - set(PLATFORM_SRC - ${SRCROOT}/Win32/ClockImpl.cpp - ${SRCROOT}/Win32/ClockImpl.hpp - ${SRCROOT}/Win32/SleepImpl.cpp - ${SRCROOT}/Win32/SleepImpl.hpp +if(SFML_OS_ANDROID) + set(PLATFORM_SRC ${PLATFORM_SRC} + ${SRCROOT}/Android/Activity.hpp + ${SRCROOT}/Android/Activity.cpp + ${SRCROOT}/Android/NativeActivity.cpp + ${SRCROOT}/Android/ResourceStream.cpp + ${SRCROOT}/Android/ResourceStream.cpp ) - source_group("windows" FILES ${PLATFORM_SRC}) -else() - set(PLATFORM_SRC - ${SRCROOT}/Unix/ClockImpl.cpp - ${SRCROOT}/Unix/ClockImpl.hpp - ${SRCROOT}/Unix/SleepImpl.cpp - ${SRCROOT}/Unix/SleepImpl.hpp - ) - - if(SFML_OS_ANDROID) - set(PLATFORM_SRC ${PLATFORM_SRC} - ${SRCROOT}/Android/Activity.hpp - ${SRCROOT}/Android/Activity.cpp - ${SRCROOT}/Android/NativeActivity.cpp - ${SRCROOT}/Android/ResourceStream.cpp - ${SRCROOT}/Android/ResourceStream.cpp - ) - endif() source_group("unix" FILES ${PLATFORM_SRC}) endif() diff --git a/src/SFML/System/Clock.cpp b/src/SFML/System/Clock.cpp index e4f347e3..80efa681 100644 --- a/src/SFML/System/Clock.cpp +++ b/src/SFML/System/Clock.cpp @@ -26,19 +26,25 @@ // Headers //////////////////////////////////////////////////////////// #include +#include -#if defined(SFML_SYSTEM_WINDOWS) - #include -#else - #include -#endif + +namespace +{ + sf::Time getCurrentTime() + { + auto timeSinceEpoch = std::chrono::high_resolution_clock::now().time_since_epoch(); + + return sf::nanoseconds(std::chrono::duration_cast(timeSinceEpoch).count()); + } +} namespace sf { //////////////////////////////////////////////////////////// Clock::Clock() : -m_startTime(priv::ClockImpl::getCurrentTime()) +m_startTime(getCurrentTime()) { } @@ -46,14 +52,14 @@ m_startTime(priv::ClockImpl::getCurrentTime()) //////////////////////////////////////////////////////////// Time Clock::getElapsedTime() const { - return priv::ClockImpl::getCurrentTime() - m_startTime; + return getCurrentTime() - m_startTime; } //////////////////////////////////////////////////////////// Time Clock::restart() { - Time now = priv::ClockImpl::getCurrentTime(); + Time now = getCurrentTime(); Time elapsed = now - m_startTime; m_startTime = now; diff --git a/src/SFML/System/Sleep.cpp b/src/SFML/System/Sleep.cpp index 4f2a50e4..282ad259 100644 --- a/src/SFML/System/Sleep.cpp +++ b/src/SFML/System/Sleep.cpp @@ -26,12 +26,8 @@ // Headers //////////////////////////////////////////////////////////// #include - -#if defined(SFML_SYSTEM_WINDOWS) - #include -#else - #include -#endif +#include +#include namespace sf @@ -40,7 +36,7 @@ namespace sf void sleep(Time duration) { if (duration >= Time::Zero) - priv::sleepImpl(duration); + std::this_thread::sleep_for(std::chrono::microseconds(duration.asMicroseconds())); } } // namespace sf diff --git a/src/SFML/System/Time.cpp b/src/SFML/System/Time.cpp index 63de359a..760ef2b7 100644 --- a/src/SFML/System/Time.cpp +++ b/src/SFML/System/Time.cpp @@ -36,7 +36,7 @@ const Time Time::Zero; //////////////////////////////////////////////////////////// Time::Time() : -m_microseconds(0) +m_nanoseconds(0) { } @@ -44,27 +44,34 @@ m_microseconds(0) //////////////////////////////////////////////////////////// float Time::asSeconds() const { - return m_microseconds / 1000000.f; + return std::chrono::duration_cast>>(m_nanoseconds).count(); } //////////////////////////////////////////////////////////// Int32 Time::asMilliseconds() const { - return static_cast(m_microseconds / 1000); + return std::chrono::duration_cast>(m_nanoseconds).count(); } //////////////////////////////////////////////////////////// Int64 Time::asMicroseconds() const { - return m_microseconds; + return std::chrono::duration_cast>(m_nanoseconds).count(); } //////////////////////////////////////////////////////////// -Time::Time(Int64 microseconds) : -m_microseconds(microseconds) +Int64 Time::asNanoseconds() const +{ + return std::chrono::duration_cast>(m_nanoseconds).count(); +} + + +//////////////////////////////////////////////////////////// +Time::Time(Int64 nanoseconds) : +m_nanoseconds(std::chrono::nanoseconds(nanoseconds)) { } @@ -72,19 +79,26 @@ m_microseconds(microseconds) //////////////////////////////////////////////////////////// Time seconds(float amount) { - return Time(static_cast(amount * 1000000)); + return Time(static_cast(amount * 1000000000)); } //////////////////////////////////////////////////////////// Time milliseconds(Int32 amount) { - return Time(static_cast(amount) * 1000); + return Time(static_cast(amount) * 1000000); } //////////////////////////////////////////////////////////// Time microseconds(Int64 amount) +{ + return Time(static_cast(amount) * 1000); +} + + +//////////////////////////////////////////////////////////// +Time nanoseconds(Int64 amount) { return Time(amount); } diff --git a/src/SFML/System/Unix/ClockImpl.cpp b/src/SFML/System/Unix/ClockImpl.cpp deleted file mode 100644 index 2cd89cfc..00000000 --- a/src/SFML/System/Unix/ClockImpl.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) - #include -#else - #include -#endif - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -Time ClockImpl::getCurrentTime() -{ -#if defined(SFML_SYSTEM_MACOS) || defined(SFML_SYSTEM_IOS) - - // Mac OS X specific implementation (it doesn't support clock_gettime) - static mach_timebase_info_data_t frequency = {0, 0}; - if (frequency.denom == 0) - mach_timebase_info(&frequency); - Uint64 nanoseconds = mach_absolute_time() * frequency.numer / frequency.denom; - return sf::microseconds(nanoseconds / 1000); - -#else - - // POSIX implementation - timespec time; - clock_gettime(CLOCK_MONOTONIC, &time); - return sf::microseconds(static_cast(time.tv_sec) * 1000000 + time.tv_nsec / 1000); - -#endif -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Unix/ClockImpl.hpp b/src/SFML/System/Unix/ClockImpl.hpp deleted file mode 100644 index 26c6433a..00000000 --- a/src/SFML/System/Unix/ClockImpl.hpp +++ /dev/null @@ -1,61 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_CLOCKIMPLUNIX_HPP -#define SFML_CLOCKIMPLUNIX_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Unix implementation of sf::Clock -/// -//////////////////////////////////////////////////////////// -class ClockImpl -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Get the current time - /// - /// \return Current time - /// - //////////////////////////////////////////////////////////// - static Time getCurrentTime(); -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_CLOCKIMPLUNIX_HPP diff --git a/src/SFML/System/Unix/SleepImpl.cpp b/src/SFML/System/Unix/SleepImpl.cpp deleted file mode 100644 index 22b6f358..00000000 --- a/src/SFML/System/Unix/SleepImpl.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -void sleepImpl(Time time) -{ - Uint64 usecs = time.asMicroseconds(); - - // Construct the time to wait - timespec ti; - ti.tv_nsec = (usecs % 1000000) * 1000; - ti.tv_sec = usecs / 1000000; - - // Wait... - // If nanosleep returns -1, we check errno. If it is EINTR - // nanosleep was interrupted and has set ti to the remaining - // duration. We continue sleeping until the complete duration - // has passed. We stop sleeping if it was due to an error. - while ((nanosleep(&ti, &ti) == -1) && (errno == EINTR)) - { - } -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Unix/SleepImpl.hpp b/src/SFML/System/Unix/SleepImpl.hpp deleted file mode 100644 index a4039b6b..00000000 --- a/src/SFML/System/Unix/SleepImpl.hpp +++ /dev/null @@ -1,52 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_SLEEPIMPLUNIX_HPP -#define SFML_SLEEPIMPLUNIX_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Unix implementation of sf::Sleep -/// -/// \param time Time to sleep -/// -//////////////////////////////////////////////////////////// -void sleepImpl(Time time); - -} // namespace priv - -} // namespace sf - - -#endif // SFML_SLEEPIMPLUNIX_HPP diff --git a/src/SFML/System/Win32/ClockImpl.cpp b/src/SFML/System/Win32/ClockImpl.cpp deleted file mode 100644 index b41f4e76..00000000 --- a/src/SFML/System/Win32/ClockImpl.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -Time ClockImpl::getCurrentTime() -{ - // Get the frequency of the performance counter - // (it is constant across the program lifetime) - static const auto frequency = [] - { - LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); - return frequency; - }(); - - // Detect if we are on Windows XP or older - static const auto oldWindows = [] - { - // Windows XP was the last 5.x version of Windows - return static_cast(LOBYTE(LOWORD(GetVersion()))) < 6; - }(); - - LARGE_INTEGER time; - - if (oldWindows) - { - static std::mutex oldWindowsMutex; - - // Acquire a lock to prevent travelling back in time - std::lock_guard lock(oldWindowsMutex); - - // Get the current time - QueryPerformanceCounter(&time); - } - else - { - // Get the current time - QueryPerformanceCounter(&time); - } - - // Return the current time as microseconds - return sf::microseconds(1000000 * time.QuadPart / frequency.QuadPart); -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Win32/ClockImpl.hpp b/src/SFML/System/Win32/ClockImpl.hpp deleted file mode 100644 index 45e08e87..00000000 --- a/src/SFML/System/Win32/ClockImpl.hpp +++ /dev/null @@ -1,61 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_CLOCKIMPLWIN32_HPP -#define SFML_CLOCKIMPLWIN32_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Windows implementation of sf::Clock -/// -//////////////////////////////////////////////////////////// -class ClockImpl -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Get the current time - /// - /// \return Current time - /// - //////////////////////////////////////////////////////////// - static Time getCurrentTime(); -}; - -} // namespace priv - -} // namespace sf - - -#endif // SFML_CLOCKIMPLWIN32_HPP diff --git a/src/SFML/System/Win32/SleepImpl.cpp b/src/SFML/System/Win32/SleepImpl.cpp deleted file mode 100644 index 8a8eee1c..00000000 --- a/src/SFML/System/Win32/SleepImpl.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -void sleepImpl(Time time) -{ - // Get the supported timer resolutions on this system - TIMECAPS tc; - timeGetDevCaps(&tc, sizeof(TIMECAPS)); - - // Set the timer resolution to the minimum for the Sleep call - timeBeginPeriod(tc.wPeriodMin); - - // Wait... - ::Sleep(time.asMilliseconds()); - - // Reset the timer resolution back to the system default - timeEndPeriod(tc.wPeriodMin); -} - -} // namespace priv - -} // namespace sf diff --git a/src/SFML/System/Win32/SleepImpl.hpp b/src/SFML/System/Win32/SleepImpl.hpp deleted file mode 100644 index 2cde5b3d..00000000 --- a/src/SFML/System/Win32/SleepImpl.hpp +++ /dev/null @@ -1,52 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_SLEEPIMPLWIN32_HPP -#define SFML_SLEEPIMPLWIN32_HPP - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -namespace sf -{ -namespace priv -{ -//////////////////////////////////////////////////////////// -/// \brief Windows implementation of sf::Sleep -/// -/// \param time Time to sleep -/// -//////////////////////////////////////////////////////////// -void sleepImpl(Time time); - -} // namespace priv - -} // namespace sf - - -#endif // SFML_SLEEPIMPLWIN32_HPP From 9d2bfcc334b2c86b752eacb6ebf55e826fd8a058 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sun, 2 Apr 2017 04:02:22 +0200 Subject: [PATCH 10/18] Converted some for loops to range-based for loops. --- examples/ftp/Ftp.cpp | 4 ++-- include/SFML/Audio/SoundFileFactory.inl | 4 ++-- include/SFML/Network/SocketSelector.hpp | 4 ++-- src/SFML/Audio/SoundBuffer.cpp | 12 ++++++------ src/SFML/Audio/SoundFileFactory.cpp | 24 ++++++++++++------------ src/SFML/Audio/SoundStream.cpp | 6 +++--- src/SFML/Graphics/ImageLoader.cpp | 4 ++-- src/SFML/Network/Http.cpp | 7 +++---- src/SFML/Network/Packet.cpp | 8 ++++---- 9 files changed, 36 insertions(+), 37 deletions(-) diff --git a/examples/ftp/Ftp.cpp b/examples/ftp/Ftp.cpp index e4de8adc..4a346cc9 100644 --- a/examples/ftp/Ftp.cpp +++ b/examples/ftp/Ftp.cpp @@ -103,8 +103,8 @@ int main() sf::Ftp::ListingResponse response = server.getDirectoryListing(); std::cout << response << std::endl; const std::vector& names = response.getListing(); - for (std::vector::const_iterator it = names.begin(); it != names.end(); ++it) - std::cout << *it << std::endl; + for (const auto& name : names) + std::cout << name << std::endl; break; } diff --git a/include/SFML/Audio/SoundFileFactory.inl b/include/SFML/Audio/SoundFileFactory.inl index 3fb84726..fce1c032 100644 --- a/include/SFML/Audio/SoundFileFactory.inl +++ b/include/SFML/Audio/SoundFileFactory.inl @@ -57,7 +57,7 @@ template void SoundFileFactory::unregisterReader() { // Remove the instance(s) of the reader from the array of factories - for (ReaderFactoryArray::iterator it = s_readers.begin(); it != s_readers.end(); ) + for (auto it = s_readers.begin(); it != s_readers.end(); ) { if (it->create == &priv::createReader) it = s_readers.erase(it); @@ -88,7 +88,7 @@ template void SoundFileFactory::unregisterWriter() { // Remove the instance(s) of the writer from the array of factories - for (WriterFactoryArray::iterator it = s_writers.begin(); it != s_writers.end(); ) + for (auto it = s_writers.begin(); it != s_writers.end(); ) { if (it->create == &priv::createWriter) it = s_writers.erase(it); diff --git a/include/SFML/Network/SocketSelector.hpp b/include/SFML/Network/SocketSelector.hpp index 1936fb54..2900d856 100644 --- a/include/SFML/Network/SocketSelector.hpp +++ b/include/SFML/Network/SocketSelector.hpp @@ -241,9 +241,9 @@ private: /// else /// { /// // The listener socket is not ready, test all other sockets (the clients) -/// for (std::list::iterator it = clients.begin(); it != clients.end(); ++it) +/// for (auto c : clients) /// { -/// sf::TcpSocket& client = **it; +/// sf::TcpSocket& client = *c; /// if (selector.isReady(client)) /// { /// // The client has sent some data, we can receive it diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index c9842048..f412a125 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -72,8 +72,8 @@ SoundBuffer::~SoundBuffer() sounds.swap(m_sounds); // Detach the buffer from the sounds that use it (to avoid OpenAL errors) - for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it) - (*it)->resetBuffer(); + for (const auto& sound : sounds) + sound->resetBuffer(); // Destroy the buffer if (m_buffer) @@ -257,8 +257,8 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate) SoundList sounds(m_sounds); // Detach the buffer from the sounds that use it (to avoid OpenAL errors) - for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it) - (*it)->resetBuffer(); + for (const auto& sound : sounds) + sound->resetBuffer(); // Fill the buffer ALsizei size = static_cast(m_samples.size()) * sizeof(Int16); @@ -268,8 +268,8 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate) m_duration = seconds(static_cast(m_samples.size()) / sampleRate / channelCount); // Now reattach the buffer to the sounds that use it - for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it) - (*it)->setBuffer(*this); + for (const auto& sound : sounds) + sound->setBuffer(*this); return true; } diff --git a/src/SFML/Audio/SoundFileFactory.cpp b/src/SFML/Audio/SoundFileFactory.cpp index d2b1fc84..172fa415 100644 --- a/src/SFML/Audio/SoundFileFactory.cpp +++ b/src/SFML/Audio/SoundFileFactory.cpp @@ -76,11 +76,11 @@ std::unique_ptr SoundFileFactory::createReaderFromFilename(cons } // Test the filename in all the registered factories - for (ReaderFactoryArray::const_iterator it = s_readers.begin(); it != s_readers.end(); ++it) + for (const auto& reader : s_readers) { stream.seek(0); - if (it->check(stream)) - return it->create(); + if (reader.check(stream)) + return reader.create(); } // No suitable reader found @@ -100,11 +100,11 @@ std::unique_ptr SoundFileFactory::createReaderFromMemory(const stream.open(data, sizeInBytes); // Test the stream for all the registered factories - for (ReaderFactoryArray::const_iterator it = s_readers.begin(); it != s_readers.end(); ++it) + for (const auto& reader : s_readers) { stream.seek(0); - if (it->check(stream)) - return it->create(); + if (reader.check(stream)) + return reader.create(); } // No suitable reader found @@ -120,11 +120,11 @@ std::unique_ptr SoundFileFactory::createReaderFromStream(InputS ensureDefaultReadersWritersRegistered(); // Test the stream for all the registered factories - for (ReaderFactoryArray::const_iterator it = s_readers.begin(); it != s_readers.end(); ++it) + for (const auto& reader : s_readers) { stream.seek(0); - if (it->check(stream)) - return it->create(); + if (reader.check(stream)) + return reader.create(); } // No suitable reader found @@ -140,10 +140,10 @@ std::unique_ptr SoundFileFactory::createWriterFromFilename(cons ensureDefaultReadersWritersRegistered(); // Test the filename in all the registered factories - for (WriterFactoryArray::const_iterator it = s_writers.begin(); it != s_writers.end(); ++it) + for (const auto& writer : s_writers) { - if (it->check(filename)) - return it->create(); + if (writer.check(filename)) + return writer.create(); } // No suitable writer found diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 3d6b01e0..78320da7 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -284,8 +284,8 @@ void SoundStream::streamData() // Create the buffers alCheck(alGenBuffers(BufferCount, m_buffers)); - for (int i = 0; i < BufferCount; ++i) - m_endBuffers[i] = false; + for (auto& buffer : m_endBuffers) + buffer = false; // Fill the queue requestStop = fillQueue(); @@ -337,7 +337,7 @@ void SoundStream::streamData() // Find its number unsigned int bufferNum = 0; - for (int i = 0; i < BufferCount; ++i) + for (auto i = 0; i < BufferCount; ++i) if (m_buffers[i] == buffer) { bufferNum = i; diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index 15d50d98..8dc526b9 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -37,6 +37,7 @@ extern "C" #include #include } +#include #include @@ -45,8 +46,7 @@ namespace // Convert a string to lower case std::string toLower(std::string str) { - for (std::string::iterator i = str.begin(); i != str.end(); ++i) - *i = static_cast(std::tolower(*i)); + std::transform(str.begin(), str.end(), str.begin(), ::tolower); return str; } diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index ef6987fb..3d0bd3d7 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -39,8 +39,7 @@ namespace // Convert a string to lower case std::string toLower(std::string str) { - for (std::string::iterator i = str.begin(); i != str.end(); ++i) - *i = static_cast(std::tolower(*i)); + std::transform(str.begin(), str.end(), str.begin(), ::tolower); return str; } } @@ -119,9 +118,9 @@ std::string Http::Request::prepare() const out << "HTTP/" << m_majorVersion << "." << m_minorVersion << "\r\n"; // Write fields - for (FieldTable::const_iterator i = m_fields.begin(); i != m_fields.end(); ++i) + for (const auto& field : m_fields) { - out << i->first << ": " << i->second << "\r\n"; + out << field.first << ": " << field.second << "\r\n"; } // Use an extra \r\n to separate the header from the body diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index fc33355c..8228af77 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -544,8 +544,8 @@ Packet& Packet::operator <<(const std::wstring& data) // Then insert characters if (length > 0) { - for (std::wstring::const_iterator c = data.begin(); c != data.end(); ++c) - *this << static_cast(*c); + for (auto c : data) + *this << static_cast(c); } return *this; @@ -562,8 +562,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 (auto c : data) + *this << c; } return *this; From 1df71a356e9a05a8377720bd9fb02c5b61b8307f Mon Sep 17 00:00:00 2001 From: binary1248 Date: Mon, 3 Apr 2017 01:17:03 +0200 Subject: [PATCH 11/18] Apply clang-tidy modernize suggestions. --- include/SFML/Audio/Music.hpp | 6 ++-- include/SFML/Audio/Sound.hpp | 2 +- include/SFML/Audio/SoundBufferRecorder.hpp | 8 ++--- include/SFML/Audio/SoundStream.hpp | 2 +- include/SFML/Graphics/CircleShape.hpp | 4 +-- include/SFML/Graphics/ConvexShape.hpp | 4 +-- include/SFML/Graphics/RectangleShape.hpp | 4 +-- include/SFML/Graphics/RenderTexture.hpp | 6 ++-- include/SFML/Graphics/RenderWindow.hpp | 10 +++---- include/SFML/Graphics/Shape.hpp | 4 +-- include/SFML/Graphics/Sprite.hpp | 2 +- include/SFML/Graphics/Text.hpp | 2 +- include/SFML/Graphics/VertexArray.hpp | 2 +- include/SFML/System/FileInputStream.hpp | 10 +++---- include/SFML/System/MemoryInputStream.hpp | 8 ++--- src/SFML/Audio/SoundFileReaderFlac.hpp | 8 ++--- src/SFML/Audio/SoundFileReaderOgg.hpp | 8 ++--- src/SFML/Audio/SoundFileReaderWav.hpp | 6 ++-- src/SFML/Audio/SoundFileWriterFlac.hpp | 6 ++-- src/SFML/Audio/SoundFileWriterOgg.hpp | 6 ++-- src/SFML/Audio/SoundFileWriterWav.hpp | 6 ++-- .../Graphics/RenderTextureImplDefault.hpp | 6 ++-- src/SFML/Graphics/RenderTextureImplFBO.hpp | 8 ++--- src/SFML/System/Err.cpp | 8 ++--- src/SFML/Window/Android/WindowImplAndroid.hpp | 30 +++++++++---------- src/SFML/Window/EglContext.hpp | 8 ++--- src/SFML/Window/OSX/SFContext.hpp | 8 ++--- src/SFML/Window/OSX/WindowImplCocoa.hpp | 30 +++++++++---------- src/SFML/Window/Unix/GlxContext.hpp | 8 ++--- src/SFML/Window/Unix/InputImpl.cpp | 2 -- src/SFML/Window/Unix/WindowImplX11.hpp | 30 +++++++++---------- src/SFML/Window/Win32/WglContext.hpp | 8 ++--- src/SFML/Window/Win32/WindowImplWin32.hpp | 30 +++++++++---------- src/SFML/Window/iOS/EaglContext.hpp | 8 ++--- src/SFML/Window/iOS/WindowImplUIKit.hpp | 30 +++++++++---------- 35 files changed, 163 insertions(+), 165 deletions(-) diff --git a/include/SFML/Audio/Music.hpp b/include/SFML/Audio/Music.hpp index cf2fe0cd..955fc528 100644 --- a/include/SFML/Audio/Music.hpp +++ b/include/SFML/Audio/Music.hpp @@ -59,7 +59,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~Music(); + ~Music() override; //////////////////////////////////////////////////////////// /// \brief Open a music from an audio file @@ -147,7 +147,7 @@ protected: /// \return True to continue playback, false to stop /// //////////////////////////////////////////////////////////// - virtual bool onGetData(Chunk& data); + bool onGetData(Chunk& data) override; //////////////////////////////////////////////////////////// /// \brief Change the current playing position in the stream source @@ -155,7 +155,7 @@ protected: /// \param timeOffset New playing position, from the beginning of the music /// //////////////////////////////////////////////////////////// - virtual void onSeek(Time timeOffset); + void onSeek(Time timeOffset) override; private: diff --git a/include/SFML/Audio/Sound.hpp b/include/SFML/Audio/Sound.hpp index 3b200240..5f21cf1e 100644 --- a/include/SFML/Audio/Sound.hpp +++ b/include/SFML/Audio/Sound.hpp @@ -72,7 +72,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~Sound(); + ~Sound() override; //////////////////////////////////////////////////////////// /// \brief Start or resume playing the sound diff --git a/include/SFML/Audio/SoundBufferRecorder.hpp b/include/SFML/Audio/SoundBufferRecorder.hpp index b5b6436c..78365665 100644 --- a/include/SFML/Audio/SoundBufferRecorder.hpp +++ b/include/SFML/Audio/SoundBufferRecorder.hpp @@ -49,7 +49,7 @@ public: /// \brief destructor /// //////////////////////////////////////////////////////////// - ~SoundBufferRecorder(); + ~SoundBufferRecorder() override; //////////////////////////////////////////////////////////// /// \brief Get the sound buffer containing the captured audio data @@ -72,7 +72,7 @@ protected: /// \return True to start the capture, or false to abort it /// //////////////////////////////////////////////////////////// - virtual bool onStart(); + bool onStart() override; //////////////////////////////////////////////////////////// /// \brief Process a new chunk of recorded samples @@ -83,13 +83,13 @@ protected: /// \return True to continue the capture, or false to stop it /// //////////////////////////////////////////////////////////// - virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount); + bool onProcessSamples(const Int16* samples, std::size_t sampleCount) override; //////////////////////////////////////////////////////////// /// \brief Stop capturing audio data /// //////////////////////////////////////////////////////////// - virtual void onStop(); + void onStop() override; private: diff --git a/include/SFML/Audio/SoundStream.hpp b/include/SFML/Audio/SoundStream.hpp index 70a094a2..4ebb2433 100644 --- a/include/SFML/Audio/SoundStream.hpp +++ b/include/SFML/Audio/SoundStream.hpp @@ -60,7 +60,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - virtual ~SoundStream(); + ~SoundStream() override; //////////////////////////////////////////////////////////// /// \brief Start or resume playing the audio stream diff --git a/include/SFML/Graphics/CircleShape.hpp b/include/SFML/Graphics/CircleShape.hpp index 9f689691..f6f0f474 100644 --- a/include/SFML/Graphics/CircleShape.hpp +++ b/include/SFML/Graphics/CircleShape.hpp @@ -89,7 +89,7 @@ public: /// \see setPointCount /// //////////////////////////////////////////////////////////// - virtual std::size_t getPointCount() const; + std::size_t getPointCount() const override; //////////////////////////////////////////////////////////// /// \brief Get a point of the circle @@ -104,7 +104,7 @@ public: /// \return index-th point of the shape /// //////////////////////////////////////////////////////////// - virtual Vector2f getPoint(std::size_t index) const; + Vector2f getPoint(std::size_t index) const override; private: diff --git a/include/SFML/Graphics/ConvexShape.hpp b/include/SFML/Graphics/ConvexShape.hpp index 117f843a..8677ecf0 100644 --- a/include/SFML/Graphics/ConvexShape.hpp +++ b/include/SFML/Graphics/ConvexShape.hpp @@ -71,7 +71,7 @@ public: /// \see setPointCount /// //////////////////////////////////////////////////////////// - virtual std::size_t getPointCount() const; + std::size_t getPointCount() const override; //////////////////////////////////////////////////////////// /// \brief Set the position of a point @@ -105,7 +105,7 @@ public: /// \see setPoint /// //////////////////////////////////////////////////////////// - virtual Vector2f getPoint(std::size_t index) const; + Vector2f getPoint(std::size_t index) const override; private: diff --git a/include/SFML/Graphics/RectangleShape.hpp b/include/SFML/Graphics/RectangleShape.hpp index f9754f69..7b2d677c 100644 --- a/include/SFML/Graphics/RectangleShape.hpp +++ b/include/SFML/Graphics/RectangleShape.hpp @@ -77,7 +77,7 @@ public: /// shapes, this number is always 4. /// //////////////////////////////////////////////////////////// - virtual std::size_t getPointCount() const; + std::size_t getPointCount() const override; //////////////////////////////////////////////////////////// /// \brief Get a point of the rectangle @@ -92,7 +92,7 @@ public: /// \return index-th point of the shape /// //////////////////////////////////////////////////////////// - virtual Vector2f getPoint(std::size_t index) const; + Vector2f getPoint(std::size_t index) const override; private: diff --git a/include/SFML/Graphics/RenderTexture.hpp b/include/SFML/Graphics/RenderTexture.hpp index 040317a3..ccc3f31e 100644 --- a/include/SFML/Graphics/RenderTexture.hpp +++ b/include/SFML/Graphics/RenderTexture.hpp @@ -64,7 +64,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - virtual ~RenderTexture(); + ~RenderTexture() override; //////////////////////////////////////////////////////////// /// \brief Create the render-texture @@ -163,7 +163,7 @@ public: /// \return True if operation was successful, false otherwise /// //////////////////////////////////////////////////////////// - bool setActive(bool active = true); + bool setActive(bool active = true) override; //////////////////////////////////////////////////////////// /// \brief Update the contents of the target texture @@ -185,7 +185,7 @@ public: /// \return Size in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2u getSize() const; + Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Get a read-only reference to the target texture diff --git a/include/SFML/Graphics/RenderWindow.hpp b/include/SFML/Graphics/RenderWindow.hpp index 609f912a..75231e96 100644 --- a/include/SFML/Graphics/RenderWindow.hpp +++ b/include/SFML/Graphics/RenderWindow.hpp @@ -99,7 +99,7 @@ public: /// Closes the window and frees all the resources attached to it. /// //////////////////////////////////////////////////////////// - virtual ~RenderWindow(); + ~RenderWindow() override; //////////////////////////////////////////////////////////// /// \brief Get the size of the rendering region of the window @@ -110,7 +110,7 @@ public: /// \return Size in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2u getSize() const; + Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Activate or deactivate the window as the current target @@ -128,7 +128,7 @@ public: /// \return True if operation was successful, false otherwise /// //////////////////////////////////////////////////////////// - bool setActive(bool active = true); + bool setActive(bool active = true) override; //////////////////////////////////////////////////////////// /// \brief Copy the current contents of the window to an image @@ -167,7 +167,7 @@ protected: /// the window is created. /// //////////////////////////////////////////////////////////// - virtual void onCreate(); + void onCreate() override; //////////////////////////////////////////////////////////// /// \brief Function called after the window has been resized @@ -176,7 +176,7 @@ protected: /// perform custom actions when the size of the window changes. /// //////////////////////////////////////////////////////////// - virtual void onResize(); + void onResize() override; }; } // namespace sf diff --git a/include/SFML/Graphics/Shape.hpp b/include/SFML/Graphics/Shape.hpp index b257ddc8..18f8626f 100644 --- a/include/SFML/Graphics/Shape.hpp +++ b/include/SFML/Graphics/Shape.hpp @@ -49,7 +49,7 @@ public: /// \brief Virtual destructor /// //////////////////////////////////////////////////////////// - virtual ~Shape(); + ~Shape() override; //////////////////////////////////////////////////////////// /// \brief Change the source texture of the shape @@ -274,7 +274,7 @@ private: /// \param states Current render states /// //////////////////////////////////////////////////////////// - virtual void draw(RenderTarget& target, RenderStates states) const; + void draw(RenderTarget& target, RenderStates states) const override; //////////////////////////////////////////////////////////// /// \brief Update the fill vertices' color diff --git a/include/SFML/Graphics/Sprite.hpp b/include/SFML/Graphics/Sprite.hpp index 51bba30c..1791690e 100644 --- a/include/SFML/Graphics/Sprite.hpp +++ b/include/SFML/Graphics/Sprite.hpp @@ -198,7 +198,7 @@ private: /// \param states Current render states /// //////////////////////////////////////////////////////////// - virtual void draw(RenderTarget& target, RenderStates states) const; + void draw(RenderTarget& target, RenderStates states) const override; //////////////////////////////////////////////////////////// /// \brief Update the vertices' positions diff --git a/include/SFML/Graphics/Text.hpp b/include/SFML/Graphics/Text.hpp index 7b7cf611..4d3238d9 100644 --- a/include/SFML/Graphics/Text.hpp +++ b/include/SFML/Graphics/Text.hpp @@ -368,7 +368,7 @@ private: /// \param states Current render states /// //////////////////////////////////////////////////////////// - virtual void draw(RenderTarget& target, RenderStates states) const; + void draw(RenderTarget& target, RenderStates states) const override; //////////////////////////////////////////////////////////// /// \brief Make sure the text's geometry is updated diff --git a/include/SFML/Graphics/VertexArray.hpp b/include/SFML/Graphics/VertexArray.hpp index 109a7e82..ea566571 100644 --- a/include/SFML/Graphics/VertexArray.hpp +++ b/include/SFML/Graphics/VertexArray.hpp @@ -180,7 +180,7 @@ private: /// \param states Current render states /// //////////////////////////////////////////////////////////// - virtual void draw(RenderTarget& target, RenderStates states) const; + void draw(RenderTarget& target, RenderStates states) const override; private: diff --git a/include/SFML/System/FileInputStream.hpp b/include/SFML/System/FileInputStream.hpp index c931dd80..85016e4b 100644 --- a/include/SFML/System/FileInputStream.hpp +++ b/include/SFML/System/FileInputStream.hpp @@ -66,7 +66,7 @@ public: /// \brief Default destructor /// //////////////////////////////////////////////////////////// - virtual ~FileInputStream(); + ~FileInputStream() override; //////////////////////////////////////////////////////////// /// \brief Open the stream from a file path @@ -90,7 +90,7 @@ public: /// \return The number of bytes actually read, or -1 on error /// //////////////////////////////////////////////////////////// - virtual Int64 read(void* data, Int64 size); + Int64 read(void* data, Int64 size) override; //////////////////////////////////////////////////////////// /// \brief Change the current reading position @@ -100,7 +100,7 @@ public: /// \return The position actually sought to, or -1 on error /// //////////////////////////////////////////////////////////// - virtual Int64 seek(Int64 position); + Int64 seek(Int64 position) override; //////////////////////////////////////////////////////////// /// \brief Get the current reading position in the stream @@ -108,7 +108,7 @@ public: /// \return The current position, or -1 on error. /// //////////////////////////////////////////////////////////// - virtual Int64 tell(); + Int64 tell() override; //////////////////////////////////////////////////////////// /// \brief Return the size of the stream @@ -116,7 +116,7 @@ public: /// \return The total number of bytes available in the stream, or -1 on error /// //////////////////////////////////////////////////////////// - virtual Int64 getSize(); + Int64 getSize() override; private: diff --git a/include/SFML/System/MemoryInputStream.hpp b/include/SFML/System/MemoryInputStream.hpp index c26f823d..36d869ea 100644 --- a/include/SFML/System/MemoryInputStream.hpp +++ b/include/SFML/System/MemoryInputStream.hpp @@ -71,7 +71,7 @@ public: /// \return The number of bytes actually read, or -1 on error /// //////////////////////////////////////////////////////////// - virtual Int64 read(void* data, Int64 size); + Int64 read(void* data, Int64 size) override; //////////////////////////////////////////////////////////// /// \brief Change the current reading position @@ -81,7 +81,7 @@ public: /// \return The position actually sought to, or -1 on error /// //////////////////////////////////////////////////////////// - virtual Int64 seek(Int64 position); + Int64 seek(Int64 position) override; //////////////////////////////////////////////////////////// /// \brief Get the current reading position in the stream @@ -89,7 +89,7 @@ public: /// \return The current position, or -1 on error. /// //////////////////////////////////////////////////////////// - virtual Int64 tell(); + Int64 tell() override; //////////////////////////////////////////////////////////// /// \brief Return the size of the stream @@ -97,7 +97,7 @@ public: /// \return The total number of bytes available in the stream, or -1 on error /// //////////////////////////////////////////////////////////// - virtual Int64 getSize(); + Int64 getSize() override; private: diff --git a/src/SFML/Audio/SoundFileReaderFlac.hpp b/src/SFML/Audio/SoundFileReaderFlac.hpp index bde8a197..c5186394 100644 --- a/src/SFML/Audio/SoundFileReaderFlac.hpp +++ b/src/SFML/Audio/SoundFileReaderFlac.hpp @@ -68,7 +68,7 @@ public: /// \brief Default constructor /// //////////////////////////////////////////////////////////// - ~SoundFileReaderFlac(); + ~SoundFileReaderFlac() override; //////////////////////////////////////////////////////////// /// \brief Open a sound file for reading @@ -77,7 +77,7 @@ public: /// \param info Structure to fill with the attributes of the loaded sound /// //////////////////////////////////////////////////////////// - virtual bool open(sf::InputStream& stream, Info& info); + bool open(sf::InputStream& stream, Info& info) override; //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset @@ -91,7 +91,7 @@ public: /// \param sampleOffset Index of the sample to jump to, relative to the beginning /// //////////////////////////////////////////////////////////// - virtual void seek(Uint64 sampleOffset); + void seek(Uint64 sampleOffset) override; //////////////////////////////////////////////////////////// /// \brief Read audio samples from the open file @@ -102,7 +102,7 @@ public: /// \return Number of samples actually read (may be less than \a maxCount) /// //////////////////////////////////////////////////////////// - virtual Uint64 read(Int16* samples, Uint64 maxCount); + Uint64 read(Int16* samples, Uint64 maxCount) override; public: diff --git a/src/SFML/Audio/SoundFileReaderOgg.hpp b/src/SFML/Audio/SoundFileReaderOgg.hpp index b1bf2529..7e9e3c26 100644 --- a/src/SFML/Audio/SoundFileReaderOgg.hpp +++ b/src/SFML/Audio/SoundFileReaderOgg.hpp @@ -66,7 +66,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~SoundFileReaderOgg(); + ~SoundFileReaderOgg() override; //////////////////////////////////////////////////////////// /// \brief Open a sound file for reading @@ -77,7 +77,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - virtual bool open(InputStream& stream, Info& info); + bool open(InputStream& stream, Info& info) override; //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset @@ -91,7 +91,7 @@ public: /// \param sampleOffset Index of the sample to jump to, relative to the beginning /// //////////////////////////////////////////////////////////// - virtual void seek(Uint64 sampleOffset); + void seek(Uint64 sampleOffset) override; //////////////////////////////////////////////////////////// /// \brief Read audio samples from the open file @@ -102,7 +102,7 @@ public: /// \return Number of samples actually read (may be less than \a maxCount) /// //////////////////////////////////////////////////////////// - virtual Uint64 read(Int16* samples, Uint64 maxCount); + Uint64 read(Int16* samples, Uint64 maxCount) override; private: diff --git a/src/SFML/Audio/SoundFileReaderWav.hpp b/src/SFML/Audio/SoundFileReaderWav.hpp index 904408b2..cab6c7e1 100644 --- a/src/SFML/Audio/SoundFileReaderWav.hpp +++ b/src/SFML/Audio/SoundFileReaderWav.hpp @@ -69,7 +69,7 @@ public: /// \param info Structure to fill with the attributes of the loaded sound /// //////////////////////////////////////////////////////////// - virtual bool open(sf::InputStream& stream, Info& info); + bool open(sf::InputStream& stream, Info& info) override; //////////////////////////////////////////////////////////// /// \brief Change the current read position to the given sample offset @@ -83,7 +83,7 @@ public: /// \param sampleOffset Index of the sample to jump to, relative to the beginning /// //////////////////////////////////////////////////////////// - virtual void seek(Uint64 sampleOffset); + void seek(Uint64 sampleOffset) override; //////////////////////////////////////////////////////////// /// \brief Read audio samples from the open file @@ -94,7 +94,7 @@ public: /// \return Number of samples actually read (may be less than \a maxCount) /// //////////////////////////////////////////////////////////// - virtual Uint64 read(Int16* samples, Uint64 maxCount); + Uint64 read(Int16* samples, Uint64 maxCount) override; private: diff --git a/src/SFML/Audio/SoundFileWriterFlac.hpp b/src/SFML/Audio/SoundFileWriterFlac.hpp index 39f50dbb..f7dec7d2 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.hpp +++ b/src/SFML/Audio/SoundFileWriterFlac.hpp @@ -67,7 +67,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~SoundFileWriterFlac(); + ~SoundFileWriterFlac() override; //////////////////////////////////////////////////////////// /// \brief Open a sound file for writing @@ -79,7 +79,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount); + bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) override; //////////////////////////////////////////////////////////// /// \brief Write audio samples to the open file @@ -88,7 +88,7 @@ public: /// \param count Number of samples to write /// //////////////////////////////////////////////////////////// - virtual void write(const Int16* samples, Uint64 count); + void write(const Int16* samples, Uint64 count) override; private: diff --git a/src/SFML/Audio/SoundFileWriterOgg.hpp b/src/SFML/Audio/SoundFileWriterOgg.hpp index 868464a4..e20def71 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.hpp +++ b/src/SFML/Audio/SoundFileWriterOgg.hpp @@ -67,7 +67,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~SoundFileWriterOgg(); + ~SoundFileWriterOgg() override; //////////////////////////////////////////////////////////// /// \brief Open a sound file for writing @@ -79,7 +79,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount); + bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) override; //////////////////////////////////////////////////////////// /// \brief Write audio samples to the open file @@ -88,7 +88,7 @@ public: /// \param count Number of samples to write /// //////////////////////////////////////////////////////////// - virtual void write(const Int16* samples, Uint64 count); + void write(const Int16* samples, Uint64 count) override; private: diff --git a/src/SFML/Audio/SoundFileWriterWav.hpp b/src/SFML/Audio/SoundFileWriterWav.hpp index b37a970c..56bc65c6 100644 --- a/src/SFML/Audio/SoundFileWriterWav.hpp +++ b/src/SFML/Audio/SoundFileWriterWav.hpp @@ -67,7 +67,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~SoundFileWriterWav(); + ~SoundFileWriterWav() override; //////////////////////////////////////////////////////////// /// \brief Open a sound file for writing @@ -79,7 +79,7 @@ public: /// \return True if the file was successfully opened /// //////////////////////////////////////////////////////////// - virtual bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount); + bool open(const std::string& filename, unsigned int sampleRate, unsigned int channelCount) override; //////////////////////////////////////////////////////////// /// \brief Write audio samples to the open file @@ -88,7 +88,7 @@ public: /// \param count Number of samples to write /// //////////////////////////////////////////////////////////// - virtual void write(const Int16* samples, Uint64 count); + void write(const Int16* samples, Uint64 count) override; private: diff --git a/src/SFML/Graphics/RenderTextureImplDefault.hpp b/src/SFML/Graphics/RenderTextureImplDefault.hpp index 8d2a8b47..df7f8be9 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.hpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.hpp @@ -66,7 +66,7 @@ private: /// \return True if creation has been successful /// //////////////////////////////////////////////////////////// - virtual bool create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer); + bool create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer) override; //////////////////////////////////////////////////////////// /// \brief Activate or deactivate the render texture for rendering @@ -76,7 +76,7 @@ private: /// \return True on success, false on failure /// //////////////////////////////////////////////////////////// - virtual bool activate(bool active); + bool activate(bool active) override; //////////////////////////////////////////////////////////// /// \brief Update the pixels of the target texture @@ -84,7 +84,7 @@ private: /// \param textureId OpenGL identifier of the target texture /// //////////////////////////////////////////////////////////// - virtual void updateTexture(unsigned textureId); + void updateTexture(unsigned textureId) override; //////////////////////////////////////////////////////////// // Member data diff --git a/src/SFML/Graphics/RenderTextureImplFBO.hpp b/src/SFML/Graphics/RenderTextureImplFBO.hpp index 321a9878..bc027e7e 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.hpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.hpp @@ -57,7 +57,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~RenderTextureImplFBO(); + ~RenderTextureImplFBO() override; //////////////////////////////////////////////////////////// /// \brief Check whether the system supports FBOs or not @@ -80,7 +80,7 @@ private: /// \return True if creation has been successful /// //////////////////////////////////////////////////////////// - virtual bool create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer); + bool create(unsigned int width, unsigned int height, unsigned int textureId, bool depthBuffer) override; //////////////////////////////////////////////////////////// /// \brief Activate or deactivate the render texture for rendering @@ -90,7 +90,7 @@ private: /// \return True on success, false on failure /// //////////////////////////////////////////////////////////// - virtual bool activate(bool active); + bool activate(bool active) override; //////////////////////////////////////////////////////////// /// \brief Update the pixels of the target texture @@ -98,7 +98,7 @@ private: /// \param textureId OpenGL identifier of the target texture /// //////////////////////////////////////////////////////////// - virtual void updateTexture(unsigned textureId); + void updateTexture(unsigned textureId) override; //////////////////////////////////////////////////////////// // Member data diff --git a/src/SFML/System/Err.cpp b/src/SFML/System/Err.cpp index d4463251..e39a3f9a 100644 --- a/src/SFML/System/Err.cpp +++ b/src/SFML/System/Err.cpp @@ -43,15 +43,15 @@ public: setp(m_buffer, m_buffer + sizeof(m_buffer)); } - ~DefaultErrStreamBuf() + ~DefaultErrStreamBuf() override { // Synchronize - sync(); + DefaultErrStreamBuf::sync(); } private: - virtual int overflow(int character) + int overflow(int character) override { if ((character != EOF) && (pptr() != epptr())) { @@ -71,7 +71,7 @@ private: } } - virtual int sync() + int sync() override { // Check if there is something into the write buffer if (pbase() != pptr()) diff --git a/src/SFML/Window/Android/WindowImplAndroid.hpp b/src/SFML/Window/Android/WindowImplAndroid.hpp index 88250d41..0b44b87d 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.hpp +++ b/src/SFML/Window/Android/WindowImplAndroid.hpp @@ -70,7 +70,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~WindowImplAndroid(); + ~WindowImplAndroid() override; //////////////////////////////////////////////////////////// /// \brief Get the OS-specific handle of the window @@ -78,7 +78,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - virtual WindowHandle getSystemHandle() const; + WindowHandle getSystemHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -86,7 +86,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2i getPosition() const; + Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -94,7 +94,7 @@ public: /// \param position New position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual void setPosition(const Vector2i& position); + void setPosition(const Vector2i& position) override; //////////////////////////////////////////////////////////// /// \brief Get the client size of the window @@ -102,7 +102,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2u getSize() const; + Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -110,7 +110,7 @@ public: /// \param size New size, in pixels /// //////////////////////////////////////////////////////////// - virtual void setSize(const Vector2u& size); + void setSize(const Vector2u& size) override; //////////////////////////////////////////////////////////// /// \brief Change the title of the window @@ -118,7 +118,7 @@ public: /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const String& title); + void setTitle(const String& title) override; //////////////////////////////////////////////////////////// /// \brief Change the window's icon @@ -128,7 +128,7 @@ public: /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels); + void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window @@ -136,7 +136,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setVisible(bool visible); + void setVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the mouse cursor @@ -144,7 +144,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorVisible(bool visible); + void setMouseCursorVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Clips or releases the mouse cursor @@ -152,7 +152,7 @@ public: /// \param grabbed True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorGrabbed(bool grabbed); + void setMouseCursorGrabbed(bool grabbed) override; //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat @@ -160,14 +160,14 @@ public: /// \param enabled True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setKeyRepeatEnabled(bool enabled); + void setKeyRepeatEnabled(bool enabled) override; //////////////////////////////////////////////////////////// /// \brief Request the current window to be made the active /// foreground window /// //////////////////////////////////////////////////////////// - virtual void requestFocus(); + void requestFocus() override; //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus @@ -175,7 +175,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - virtual bool hasFocus() const; + bool hasFocus() const override; static void forwardEvent(const Event& event); static WindowImplAndroid* singleInstance; @@ -186,7 +186,7 @@ protected: /// \brief Process incoming events from the operating system /// //////////////////////////////////////////////////////////// - virtual void processEvents(); + void processEvents() override; private: diff --git a/src/SFML/Window/EglContext.hpp b/src/SFML/Window/EglContext.hpp index a889c3ac..f38e018a 100644 --- a/src/SFML/Window/EglContext.hpp +++ b/src/SFML/Window/EglContext.hpp @@ -77,7 +77,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~EglContext(); + ~EglContext() override; //////////////////////////////////////////////////////////// /// \brief Activate the context as the current target @@ -88,13 +88,13 @@ public: /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(bool current); + bool makeCurrent(bool current) override; //////////////////////////////////////////////////////////// /// \brief Display what has been rendered to the context so far /// //////////////////////////////////////////////////////////// - virtual void display(); + void display() override; //////////////////////////////////////////////////////////// /// \brief Enable or disable vertical synchronization @@ -107,7 +107,7 @@ public: /// \param enabled: True to enable v-sync, false to deactivate /// //////////////////////////////////////////////////////////// - virtual void setVerticalSyncEnabled(bool enabled); + void setVerticalSyncEnabled(bool enabled) override; //////////////////////////////////////////////////////////// /// \brief Create the context diff --git a/src/SFML/Window/OSX/SFContext.hpp b/src/SFML/Window/OSX/SFContext.hpp index 8f020b33..2a1e70d4 100644 --- a/src/SFML/Window/OSX/SFContext.hpp +++ b/src/SFML/Window/OSX/SFContext.hpp @@ -101,7 +101,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~SFContext(); + ~SFContext() override; //////////////////////////////////////////////////////////// /// \brief Get the address of an OpenGL function @@ -117,7 +117,7 @@ public: /// \brief Display what has been rendered to the context so far /// //////////////////////////////////////////////////////////// - virtual void display(); + void display() override; //////////////////////////////////////////////////////////// /// \brief Enable or disable vertical synchronization @@ -130,7 +130,7 @@ public: /// \param enabled True to enable v-sync, false to deactivate /// //////////////////////////////////////////////////////////// - virtual void setVerticalSyncEnabled(bool enabled); + void setVerticalSyncEnabled(bool enabled) override; protected: //////////////////////////////////////////////////////////// @@ -142,7 +142,7 @@ protected: /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(bool current); + bool makeCurrent(bool current) override; private: //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/OSX/WindowImplCocoa.hpp b/src/SFML/Window/OSX/WindowImplCocoa.hpp index 8daa8f83..c3b5ed77 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.hpp +++ b/src/SFML/Window/OSX/WindowImplCocoa.hpp @@ -87,7 +87,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~WindowImplCocoa(); + ~WindowImplCocoa() override; //////////////////////////////////////////////////////////// /// \brief Window Closed Event - called by the cocoa window object @@ -245,7 +245,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - virtual WindowHandle getSystemHandle() const; + WindowHandle getSystemHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -253,7 +253,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2i getPosition() const; + Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -261,7 +261,7 @@ public: /// \param position New position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual void setPosition(const Vector2i& position); + void setPosition(const Vector2i& position) override; //////////////////////////////////////////////////////////// /// \brief Get the client size of the window @@ -269,7 +269,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2u getSize() const; + Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -277,7 +277,7 @@ public: /// \param size New size, in pixels /// //////////////////////////////////////////////////////////// - virtual void setSize(const Vector2u& size); + void setSize(const Vector2u& size) override; //////////////////////////////////////////////////////////// /// \brief Change the title of the window @@ -285,7 +285,7 @@ public: /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const String& title); + void setTitle(const String& title) override; //////////////////////////////////////////////////////////// /// \brief Change the window's icon @@ -295,7 +295,7 @@ public: /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels); + void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window @@ -303,7 +303,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setVisible(bool visible); + void setVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the mouse cursor @@ -311,7 +311,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorVisible(bool visible); + void setMouseCursorVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Grab or release the mouse cursor @@ -319,7 +319,7 @@ public: /// \param grabbed True to grab, false to release /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorGrabbed(bool grabbed); + void setMouseCursorGrabbed(bool grabbed) override; //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat @@ -327,14 +327,14 @@ public: /// \param enabled True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setKeyRepeatEnabled(bool enabled); + void setKeyRepeatEnabled(bool enabled) override; //////////////////////////////////////////////////////////// /// \brief Request the current window to be made the active /// foreground window /// //////////////////////////////////////////////////////////// - virtual void requestFocus(); + void requestFocus() override; //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus @@ -342,7 +342,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - virtual bool hasFocus() const; + bool hasFocus() const override; protected: @@ -350,7 +350,7 @@ protected: /// \brief Process incoming events from the operating system /// //////////////////////////////////////////////////////////// - virtual void processEvents(); + void processEvents() override; private: diff --git a/src/SFML/Window/Unix/GlxContext.hpp b/src/SFML/Window/Unix/GlxContext.hpp index 3991abad..304b0049 100644 --- a/src/SFML/Window/Unix/GlxContext.hpp +++ b/src/SFML/Window/Unix/GlxContext.hpp @@ -79,7 +79,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~GlxContext(); + ~GlxContext() override; //////////////////////////////////////////////////////////// /// \brief Get the address of an OpenGL function @@ -99,13 +99,13 @@ public: /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(bool current); + bool makeCurrent(bool current) override; //////////////////////////////////////////////////////////// /// \brief Display what has been rendered to the context so far /// //////////////////////////////////////////////////////////// - virtual void display(); + void display() override; //////////////////////////////////////////////////////////// /// \brief Enable or disable vertical synchronization @@ -118,7 +118,7 @@ public: /// \param enabled True to enable v-sync, false to deactivate /// //////////////////////////////////////////////////////////// - virtual void setVerticalSyncEnabled(bool enabled); + void setVerticalSyncEnabled(bool enabled) override; //////////////////////////////////////////////////////////// /// \brief Select the best GLX visual for a given set of settings diff --git a/src/SFML/Window/Unix/InputImpl.cpp b/src/SFML/Window/Unix/InputImpl.cpp index 23c114b2..e5510316 100644 --- a/src/SFML/Window/Unix/InputImpl.cpp +++ b/src/SFML/Window/Unix/InputImpl.cpp @@ -212,8 +212,6 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) case Mouse::XButton2: return false; // not supported by X default: return false; } - - return false; } diff --git a/src/SFML/Window/Unix/WindowImplX11.hpp b/src/SFML/Window/Unix/WindowImplX11.hpp index 973a57d3..ff6093ca 100644 --- a/src/SFML/Window/Unix/WindowImplX11.hpp +++ b/src/SFML/Window/Unix/WindowImplX11.hpp @@ -70,7 +70,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~WindowImplX11(); + ~WindowImplX11() override; //////////////////////////////////////////////////////////// /// \brief Get the OS-specific handle of the window @@ -78,7 +78,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - virtual WindowHandle getSystemHandle() const; + WindowHandle getSystemHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -86,7 +86,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2i getPosition() const; + Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -94,7 +94,7 @@ public: /// \param position New position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual void setPosition(const Vector2i& position); + void setPosition(const Vector2i& position) override; //////////////////////////////////////////////////////////// /// \brief Get the client size of the window @@ -102,7 +102,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2u getSize() const; + Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -110,7 +110,7 @@ public: /// \param size New size, in pixels /// //////////////////////////////////////////////////////////// - virtual void setSize(const Vector2u& size); + void setSize(const Vector2u& size) override; //////////////////////////////////////////////////////////// /// \brief Change the title of the window @@ -118,7 +118,7 @@ public: /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const String& title); + void setTitle(const String& title) override; //////////////////////////////////////////////////////////// /// \brief Change the window's icon @@ -128,7 +128,7 @@ public: /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels); + void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window @@ -136,7 +136,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setVisible(bool visible); + void setVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the mouse cursor @@ -144,7 +144,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorVisible(bool visible); + void setMouseCursorVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Grab or release the mouse cursor @@ -152,7 +152,7 @@ public: /// \param grabbed True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorGrabbed(bool grabbed); + void setMouseCursorGrabbed(bool grabbed) override; //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat @@ -160,14 +160,14 @@ public: /// \param enabled True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setKeyRepeatEnabled(bool enabled); + void setKeyRepeatEnabled(bool enabled) override; //////////////////////////////////////////////////////////// /// \brief Request the current window to be made the active /// foreground window /// //////////////////////////////////////////////////////////// - virtual void requestFocus(); + void requestFocus() override; //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus @@ -175,7 +175,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - virtual bool hasFocus() const; + bool hasFocus() const override; protected: @@ -183,7 +183,7 @@ protected: /// \brief Process incoming events from the operating system /// //////////////////////////////////////////////////////////// - virtual void processEvents(); + void processEvents() override; private: diff --git a/src/SFML/Window/Win32/WglContext.hpp b/src/SFML/Window/Win32/WglContext.hpp index d45de78b..d3a284df 100644 --- a/src/SFML/Window/Win32/WglContext.hpp +++ b/src/SFML/Window/Win32/WglContext.hpp @@ -78,7 +78,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~WglContext(); + ~WglContext() override; //////////////////////////////////////////////////////////// /// \brief Get the address of an OpenGL function @@ -98,13 +98,13 @@ public: /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(bool current); + bool makeCurrent(bool current) override; //////////////////////////////////////////////////////////// /// \brief Display what has been rendered to the context so far /// //////////////////////////////////////////////////////////// - virtual void display(); + void display() override; //////////////////////////////////////////////////////////// /// \brief Enable or disable vertical synchronization @@ -117,7 +117,7 @@ public: /// \param enabled: True to enable v-sync, false to deactivate /// //////////////////////////////////////////////////////////// - virtual void setVerticalSyncEnabled(bool enabled); + void setVerticalSyncEnabled(bool enabled) override; //////////////////////////////////////////////////////////// /// \brief Select the best pixel format for a given set of settings diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index 6c29e0b4..1d255861 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -69,7 +69,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~WindowImplWin32(); + ~WindowImplWin32() override; //////////////////////////////////////////////////////////// /// \brief Get the OS-specific handle of the window @@ -77,7 +77,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - virtual WindowHandle getSystemHandle() const; + WindowHandle getSystemHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -85,7 +85,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2i getPosition() const; + Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -93,7 +93,7 @@ public: /// \param position New position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual void setPosition(const Vector2i& position); + void setPosition(const Vector2i& position) override; //////////////////////////////////////////////////////////// /// \brief Get the client size of the window @@ -101,7 +101,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2u getSize() const; + Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -109,7 +109,7 @@ public: /// \param size New size, in pixels /// //////////////////////////////////////////////////////////// - virtual void setSize(const Vector2u& size); + void setSize(const Vector2u& size) override; //////////////////////////////////////////////////////////// /// \brief Change the title of the window @@ -117,7 +117,7 @@ public: /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const String& title); + void setTitle(const String& title) override; //////////////////////////////////////////////////////////// /// \brief Change the window's icon @@ -127,7 +127,7 @@ public: /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels); + void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window @@ -135,7 +135,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setVisible(bool visible); + void setVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the mouse cursor @@ -143,7 +143,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorVisible(bool visible); + void setMouseCursorVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Grab or release the mouse cursor @@ -151,7 +151,7 @@ public: /// \param grabbed True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorGrabbed(bool grabbed); + void setMouseCursorGrabbed(bool grabbed) override; //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat @@ -159,14 +159,14 @@ public: /// \param enabled True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setKeyRepeatEnabled(bool enabled); + void setKeyRepeatEnabled(bool enabled) override; //////////////////////////////////////////////////////////// /// \brief Request the current window to be made the active /// foreground window /// //////////////////////////////////////////////////////////// - virtual void requestFocus(); + void requestFocus() override; //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus @@ -174,7 +174,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - virtual bool hasFocus() const; + bool hasFocus() const override; protected: @@ -182,7 +182,7 @@ protected: /// \brief Process incoming events from the operating system /// //////////////////////////////////////////////////////////// - virtual void processEvents(); + void processEvents() override; private: diff --git a/src/SFML/Window/iOS/EaglContext.hpp b/src/SFML/Window/iOS/EaglContext.hpp index a6853ee1..8eed8f81 100644 --- a/src/SFML/Window/iOS/EaglContext.hpp +++ b/src/SFML/Window/iOS/EaglContext.hpp @@ -88,7 +88,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~EaglContext(); + ~EaglContext() override; //////////////////////////////////////////////////////////// /// \brief Recreate the render buffers of the context @@ -105,7 +105,7 @@ public: /// \brief Display what has been rendered to the context so far /// //////////////////////////////////////////////////////////// - virtual void display(); + void display() override; //////////////////////////////////////////////////////////// /// \brief Enable or disable vertical synchronization @@ -118,7 +118,7 @@ public: /// \param enabled: True to enable v-sync, false to deactivate /// //////////////////////////////////////////////////////////// - virtual void setVerticalSyncEnabled(bool enabled); + void setVerticalSyncEnabled(bool enabled) override; protected: @@ -131,7 +131,7 @@ protected: /// \return True on success, false if any error happened /// //////////////////////////////////////////////////////////// - virtual bool makeCurrent(bool current); + bool makeCurrent(bool current) override; private: diff --git a/src/SFML/Window/iOS/WindowImplUIKit.hpp b/src/SFML/Window/iOS/WindowImplUIKit.hpp index 51e890a7..052c6d6d 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.hpp +++ b/src/SFML/Window/iOS/WindowImplUIKit.hpp @@ -73,7 +73,7 @@ public: /// \brief Destructor /// //////////////////////////////////////////////////////////// - ~WindowImplUIKit(); + ~WindowImplUIKit() override; //////////////////////////////////////////////////////////// /// \brief Get the OS-specific handle of the window @@ -81,7 +81,7 @@ public: /// \return Handle of the window /// //////////////////////////////////////////////////////////// - virtual WindowHandle getSystemHandle() const; + WindowHandle getSystemHandle() const override; //////////////////////////////////////////////////////////// /// \brief Get the position of the window @@ -89,7 +89,7 @@ public: /// \return Position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2i getPosition() const; + Vector2i getPosition() const override; //////////////////////////////////////////////////////////// /// \brief Change the position of the window on screen @@ -97,7 +97,7 @@ public: /// \param position New position of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual void setPosition(const Vector2i& position); + void setPosition(const Vector2i& position) override; //////////////////////////////////////////////////////////// /// \brief Get the client size of the window @@ -105,7 +105,7 @@ public: /// \return Size of the window, in pixels /// //////////////////////////////////////////////////////////// - virtual Vector2u getSize() const; + Vector2u getSize() const override; //////////////////////////////////////////////////////////// /// \brief Change the size of the rendering region of the window @@ -113,7 +113,7 @@ public: /// \param size New size, in pixels /// //////////////////////////////////////////////////////////// - virtual void setSize(const Vector2u& size); + void setSize(const Vector2u& size) override; //////////////////////////////////////////////////////////// /// \brief Change the title of the window @@ -121,7 +121,7 @@ public: /// \param title New title /// //////////////////////////////////////////////////////////// - virtual void setTitle(const String& title); + void setTitle(const String& title) override; //////////////////////////////////////////////////////////// /// \brief Change the window's icon @@ -131,7 +131,7 @@ public: /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels); + void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window @@ -139,7 +139,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setVisible(bool visible); + void setVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the mouse cursor @@ -147,7 +147,7 @@ public: /// \param visible True to show, false to hide /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorVisible(bool visible); + void setMouseCursorVisible(bool visible) override; //////////////////////////////////////////////////////////// /// \brief Clips or releases the mouse cursor @@ -155,7 +155,7 @@ public: /// \param grabbed True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setMouseCursorGrabbed(bool grabbed); + void setMouseCursorGrabbed(bool grabbed) override; //////////////////////////////////////////////////////////// /// \brief Enable or disable automatic key-repeat @@ -163,14 +163,14 @@ public: /// \param enabled True to enable, false to disable /// //////////////////////////////////////////////////////////// - virtual void setKeyRepeatEnabled(bool enabled); + void setKeyRepeatEnabled(bool enabled) override; //////////////////////////////////////////////////////////// /// \brief Request the current window to be made the active /// foreground window /// //////////////////////////////////////////////////////////// - virtual void requestFocus(); + void requestFocus() override; //////////////////////////////////////////////////////////// /// \brief Check whether the window has the input focus @@ -178,7 +178,7 @@ public: /// \return True if window has focus, false otherwise /// //////////////////////////////////////////////////////////// - virtual bool hasFocus() const; + bool hasFocus() const override; public: @@ -212,7 +212,7 @@ protected: /// \brief Process incoming events from the operating system /// //////////////////////////////////////////////////////////// - virtual void processEvents(); + void processEvents() override; private: From e1d3eff5870e3d61e50d32e4f564fe76143f87ef Mon Sep 17 00:00:00 2001 From: binary1248 Date: Mon, 3 Apr 2017 19:08:52 +0200 Subject: [PATCH 12/18] Replaced &container[0] with container.data() wherever applicable. --- examples/voip/Server.cpp | 2 +- src/SFML/Audio/Music.cpp | 4 +-- src/SFML/Audio/SoundBuffer.cpp | 8 +++--- src/SFML/Audio/SoundBufferRecorder.cpp | 2 +- src/SFML/Audio/SoundFileWriterFlac.cpp | 2 +- src/SFML/Audio/SoundRecorder.cpp | 4 +-- src/SFML/Graphics/Font.cpp | 4 +-- src/SFML/Graphics/Image.cpp | 10 +++---- src/SFML/Graphics/ImageLoader.cpp | 14 +++++----- src/SFML/Graphics/Shader.cpp | 34 +++++++++++------------ src/SFML/Graphics/Texture.cpp | 12 ++++---- src/SFML/Graphics/VertexArray.cpp | 2 +- src/SFML/Network/Packet.cpp | 2 +- src/SFML/Network/TcpSocket.cpp | 10 +++---- src/SFML/Network/UdpSocket.cpp | 4 +-- src/SFML/Window/FreeBSD/JoystickImpl.cpp | 6 ++-- src/SFML/Window/OSX/JoystickImpl.cpp | 4 +-- src/SFML/Window/OSX/SFContext.mm | 2 +- src/SFML/Window/Unix/GlxContext.cpp | 2 +- src/SFML/Window/Unix/WindowImplX11.cpp | 14 +++++----- src/SFML/Window/Win32/WglContext.cpp | 2 +- src/SFML/Window/Win32/WindowImplWin32.cpp | 2 +- 22 files changed, 73 insertions(+), 73 deletions(-) diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index 4730cb83..f1a6359d 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -89,7 +89,7 @@ private: } // Fill audio data to pass to the stream - data.samples = &m_tempBuffer[0]; + data.samples = m_tempBuffer.data(); data.sampleCount = m_tempBuffer.size(); // Update the playing offset diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index 3c3bae7f..59853951 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -113,8 +113,8 @@ bool Music::onGetData(SoundStream::Chunk& data) std::lock_guard lock(m_mutex); // Fill the chunk parameters - data.samples = &m_samples[0]; - data.sampleCount = static_cast(m_file.read(&m_samples[0], m_samples.size())); + data.samples = m_samples.data(); + data.sampleCount = static_cast(m_file.read(m_samples.data(), m_samples.size())); // Check if we have stopped obtaining samples or reached the end of the audio file return (data.sampleCount != 0) && (m_file.getSampleOffset() < m_file.getSampleCount()); diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index f412a125..9ccc13bd 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -148,7 +148,7 @@ bool SoundBuffer::saveToFile(const std::string& filename) const if (file.openFromFile(filename, getSampleRate(), getChannelCount())) { // Write the samples to the opened file - file.write(&m_samples[0], m_samples.size()); + file.write(m_samples.data(), m_samples.size()); return true; } @@ -162,7 +162,7 @@ bool SoundBuffer::saveToFile(const std::string& filename) const //////////////////////////////////////////////////////////// const Int16* SoundBuffer::getSamples() const { - return m_samples.empty() ? NULL : &m_samples[0]; + return m_samples.empty() ? NULL : m_samples.data(); } @@ -224,7 +224,7 @@ bool SoundBuffer::initialize(InputSoundFile& file) // Read the samples from the provided file m_samples.resize(static_cast(sampleCount)); - if (file.read(&m_samples[0], sampleCount) == sampleCount) + if (file.read(m_samples.data(), sampleCount) == sampleCount) { // Update the internal buffer with the new samples return update(channelCount, sampleRate); @@ -262,7 +262,7 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate) // Fill the buffer ALsizei size = static_cast(m_samples.size()) * sizeof(Int16); - alCheck(alBufferData(m_buffer, format, &m_samples[0], size, sampleRate)); + alCheck(alBufferData(m_buffer, format, m_samples.data(), size, sampleRate)); // Compute the duration m_duration = seconds(static_cast(m_samples.size()) / sampleRate / channelCount); diff --git a/src/SFML/Audio/SoundBufferRecorder.cpp b/src/SFML/Audio/SoundBufferRecorder.cpp index 105b45b6..486cfec6 100644 --- a/src/SFML/Audio/SoundBufferRecorder.cpp +++ b/src/SFML/Audio/SoundBufferRecorder.cpp @@ -63,7 +63,7 @@ bool SoundBufferRecorder::onProcessSamples(const Int16* samples, std::size_t sam void SoundBufferRecorder::onStop() { if (!m_samples.empty()) - m_buffer.loadFromSamples(&m_samples[0], m_samples.size(), getChannelCount(), getSampleRate()); + m_buffer.loadFromSamples(m_samples.data(), m_samples.size(), getChannelCount(), getSampleRate()); } diff --git a/src/SFML/Audio/SoundFileWriterFlac.cpp b/src/SFML/Audio/SoundFileWriterFlac.cpp index b12088b0..b72ee0d5 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.cpp +++ b/src/SFML/Audio/SoundFileWriterFlac.cpp @@ -105,7 +105,7 @@ void SoundFileWriterFlac::write(const Int16* samples, Uint64 count) m_samples32.assign(samples, samples + frames * m_channelCount); // Write them to the FLAC stream - FLAC__stream_encoder_process_interleaved(m_encoder, &m_samples32[0], frames); + FLAC__stream_encoder_process_interleaved(m_encoder, m_samples32.data(), frames); // Next chunk count -= m_samples32.size(); diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 0e41f27d..f139d67e 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -310,10 +310,10 @@ void SoundRecorder::processCapturedSamples() { // Get the recorded samples m_samples.resize(samplesAvailable * getChannelCount()); - alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable); + alcCaptureSamples(captureDevice, m_samples.data(), samplesAvailable); // Forward them to the derived class - if (!onProcessSamples(&m_samples[0], m_samples.size())) + if (!onProcessSamples(m_samples.data(), m_samples.size())) { // The user wants to stop the capture m_isCapturing = false; diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 4829a526..ec82080f 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -585,7 +585,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f // Resize the pixel buffer to the new size and fill it with transparent white pixels m_pixelBuffer.resize(width * height * 4); - Uint8* current = &m_pixelBuffer[0]; + Uint8* current = m_pixelBuffer.data(); Uint8* end = current + width * height * 4; while (current != end) @@ -632,7 +632,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f unsigned int y = glyph.textureRect.top - padding; unsigned int w = glyph.textureRect.width + 2 * padding; unsigned int h = glyph.textureRect.height + 2 * padding; - page.texture.update(&m_pixelBuffer[0], w, h, x, y); + page.texture.update(m_pixelBuffer.data(), w, h, x, y); } // Delete the FT glyph diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 8fc77a1b..00bb1a7e 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -57,7 +57,7 @@ void Image::create(unsigned int width, unsigned int height, const Color& color) std::vector newPixels(width * height * 4); // Fill it with the specified color - Uint8* ptr = &newPixels[0]; + Uint8* ptr = newPixels.data(); Uint8* end = ptr + newPixels.size(); while (ptr < end) { @@ -164,7 +164,7 @@ void Image::createMaskFromColor(const Color& color, Uint8 alpha) if (!m_pixels.empty()) { // Replace the alpha of the pixels that match the transparent color - Uint8* ptr = &m_pixels[0]; + Uint8* ptr = m_pixels.data(); Uint8* end = ptr + m_pixels.size(); while (ptr < end) { @@ -215,8 +215,8 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co int rows = height; int srcStride = source.m_size.x * 4; int dstStride = m_size.x * 4; - const Uint8* srcPixels = &source.m_pixels[0] + (srcRect.left + srcRect.top * source.m_size.x) * 4; - Uint8* dstPixels = &m_pixels[0] + (destX + destY * m_size.x) * 4; + const Uint8* srcPixels = source.m_pixels.data() + (srcRect.left + srcRect.top * source.m_size.x) * 4; + Uint8* dstPixels = m_pixels.data() + (destX + destY * m_size.x) * 4; // Copy the pixels if (applyAlpha) @@ -279,7 +279,7 @@ const Uint8* Image::getPixelsPtr() const { if (!m_pixels.empty()) { - return &m_pixels[0]; + return m_pixels.data(); } else { diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index 8dc526b9..0e2edfac 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -118,7 +118,7 @@ bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector& p { // Copy the loaded pixels to the pixel buffer pixels.resize(width * height * 4); - memcpy(&pixels[0], ptr, pixels.size()); + memcpy(pixels.data(), ptr, pixels.size()); } // Free the loaded pixels (they are now in our own pixel buffer) @@ -250,19 +250,19 @@ bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector if (extension == "bmp") { // BMP format - if (stbi_write_bmp(filename.c_str(), size.x, size.y, 4, &pixels[0])) + if (stbi_write_bmp(filename.c_str(), size.x, size.y, 4, pixels.data())) return true; } else if (extension == "tga") { // TGA format - if (stbi_write_tga(filename.c_str(), size.x, size.y, 4, &pixels[0])) + if (stbi_write_tga(filename.c_str(), size.x, size.y, 4, pixels.data())) return true; } else if (extension == "png") { // PNG format - if (stbi_write_png(filename.c_str(), size.x, size.y, 4, &pixels[0], 0)) + if (stbi_write_png(filename.c_str(), size.x, size.y, 4, pixels.data(), 0)) return true; } else if (extension == "jpg" || extension == "jpeg") @@ -309,7 +309,7 @@ bool ImageLoader::writeJpg(const std::string& filename, const std::vector buffer[i * 3 + 1] = pixels[i * 4 + 1]; buffer[i * 3 + 2] = pixels[i * 4 + 2]; } - Uint8* ptr = &buffer[0]; + Uint8* ptr = buffer.data(); // Start compression jpeg_start_compress(&compressInfos, TRUE); diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index bae40eee..066a8b10 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -66,7 +66,7 @@ namespace { file.seekg(0, std::ios_base::beg); buffer.resize(static_cast(size)); - file.read(&buffer[0], size); + file.read(buffer.data(), size); } buffer.push_back('\0'); return true; @@ -86,7 +86,7 @@ namespace { buffer.resize(static_cast(size)); stream.seek(0); - sf::Int64 read = stream.read(&buffer[0], size); + sf::Int64 read = stream.read(buffer.data(), size); success = (read == size); } buffer.push_back('\0'); @@ -228,11 +228,11 @@ bool Shader::loadFromFile(const std::string& filename, Type type) // Compile the shader program if (type == Vertex) - return compile(&shader[0], NULL, NULL); + return compile(shader.data(), NULL, NULL); else if (type == Geometry) - return compile(NULL, &shader[0], NULL); + return compile(NULL, shader.data(), NULL); else - return compile(NULL, NULL, &shader[0]); + return compile(NULL, NULL, shader.data()); } @@ -256,7 +256,7 @@ bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::st } // Compile the shader program - return compile(&vertexShader[0], NULL, &fragmentShader[0]); + return compile(vertexShader.data(), NULL, fragmentShader.data()); } @@ -288,7 +288,7 @@ bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::st } // Compile the shader program - return compile(&vertexShader[0], &geometryShader[0], &fragmentShader[0]); + return compile(vertexShader.data(), geometryShader.data(), fragmentShader.data()); } @@ -334,11 +334,11 @@ bool Shader::loadFromStream(InputStream& stream, Type type) // Compile the shader program if (type == Vertex) - return compile(&shader[0], NULL, NULL); + return compile(shader.data(), NULL, NULL); else if (type == Geometry) - return compile(NULL, &shader[0], NULL); + return compile(NULL, shader.data(), NULL); else - return compile(NULL, NULL, &shader[0]); + return compile(NULL, NULL, shader.data()); } @@ -362,7 +362,7 @@ bool Shader::loadFromStream(InputStream& vertexShaderStream, InputStream& fragme } // Compile the shader program - return compile(&vertexShader[0], NULL, &fragmentShader[0]); + return compile(vertexShader.data(), NULL, fragmentShader.data()); } @@ -394,7 +394,7 @@ bool Shader::loadFromStream(InputStream& vertexShaderStream, InputStream& geomet } // Compile the shader program - return compile(&vertexShader[0], &geometryShader[0], &fragmentShader[0]); + return compile(vertexShader.data(), geometryShader.data(), fragmentShader.data()); } @@ -588,7 +588,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec2* vectorAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniform2fv(binder.location, length, &contiguous[0])); + glCheck(GLEXT_glUniform2fv(binder.location, length, contiguous.data())); } @@ -599,7 +599,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec3* vectorAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniform3fv(binder.location, length, &contiguous[0])); + glCheck(GLEXT_glUniform3fv(binder.location, length, contiguous.data())); } @@ -610,7 +610,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec4* vectorAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniform4fv(binder.location, length, &contiguous[0])); + glCheck(GLEXT_glUniform4fv(binder.location, length, contiguous.data())); } @@ -625,7 +625,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Mat3* matrixAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniformMatrix3fv(binder.location, length, GL_FALSE, &contiguous[0])); + glCheck(GLEXT_glUniformMatrix3fv(binder.location, length, GL_FALSE, contiguous.data())); } @@ -640,7 +640,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Mat4* matrixAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniformMatrix4fv(binder.location, length, GL_FALSE, &contiguous[0])); + glCheck(GLEXT_glUniformMatrix4fv(binder.location, length, GL_FALSE, contiguous.data())); } diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 4c09dcf5..98d4fbb7 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -337,7 +337,7 @@ Image Texture::copyToImage() const glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, frameBuffer)); glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0)); - glCheck(glReadPixels(0, 0, m_size.x, m_size.y, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0])); + glCheck(glReadPixels(0, 0, m_size.x, m_size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data())); glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer)); glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, previousFrameBuffer)); @@ -349,7 +349,7 @@ Image Texture::copyToImage() const { // Texture is not padded nor flipped, we can use a direct copy glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); - glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0])); + glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data())); } else { @@ -358,11 +358,11 @@ Image Texture::copyToImage() const // All the pixels will first be copied to a temporary array std::vector allPixels(m_actualSize.x * m_actualSize.y * 4); glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); - glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0])); + glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, allPixels.data())); // Then we copy the useful pixels from the temporary array to the final one - const Uint8* src = &allPixels[0]; - Uint8* dst = &pixels[0]; + const Uint8* src = allPixels.data(); + Uint8* dst = pixels.data(); int srcPitch = m_actualSize.x * 4; int dstPitch = m_size.x * 4; @@ -385,7 +385,7 @@ Image Texture::copyToImage() const // Create the image Image image; - image.create(m_size.x, m_size.y, &pixels[0]); + image.create(m_size.x, m_size.y, pixels.data()); return image; } diff --git a/src/SFML/Graphics/VertexArray.cpp b/src/SFML/Graphics/VertexArray.cpp index 0f9c8136..d64fa72a 100644 --- a/src/SFML/Graphics/VertexArray.cpp +++ b/src/SFML/Graphics/VertexArray.cpp @@ -144,7 +144,7 @@ FloatRect VertexArray::getBounds() const void VertexArray::draw(RenderTarget& target, RenderStates states) const { if (!m_vertices.empty()) - target.draw(&m_vertices[0], m_vertices.size(), m_primitiveType, states); + target.draw(m_vertices.data(), m_vertices.size(), m_primitiveType, states); } } // namespace sf diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index 8228af77..7dff0a8b 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -75,7 +75,7 @@ void Packet::clear() //////////////////////////////////////////////////////////// const void* Packet::getData() const { - return !m_data.empty() ? &m_data[0] : NULL; + return !m_data.empty() ? m_data.data() : NULL; } diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index be218cf3..73394011 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -317,13 +317,13 @@ Socket::Status TcpSocket::send(Packet& packet) std::vector blockToSend(sizeof(packetSize) + size); // Copy the packet size and data into the block to send - std::memcpy(&blockToSend[0], &packetSize, sizeof(packetSize)); + std::memcpy(blockToSend.data(), &packetSize, sizeof(packetSize)); if (size > 0) - std::memcpy(&blockToSend[0] + sizeof(packetSize), data, size); + std::memcpy(blockToSend.data() + sizeof(packetSize), data, size); // Send the data block std::size_t sent; - Status status = send(&blockToSend[0] + packet.m_sendPos, blockToSend.size() - packet.m_sendPos, sent); + Status status = send(blockToSend.data() + packet.m_sendPos, blockToSend.size() - packet.m_sendPos, sent); // In the case of a partial send, record the location to resume from if (status == Partial) @@ -385,14 +385,14 @@ Socket::Status TcpSocket::receive(Packet& packet) if (received > 0) { m_pendingPacket.Data.resize(m_pendingPacket.Data.size() + received); - char* begin = &m_pendingPacket.Data[0] + m_pendingPacket.Data.size() - received; + char* begin = m_pendingPacket.Data.data() + m_pendingPacket.Data.size() - received; std::memcpy(begin, buffer, received); } } // We have received all the packet data: we can copy it to the user packet if (!m_pendingPacket.Data.empty()) - packet.onReceive(&m_pendingPacket.Data[0], m_pendingPacket.Data.size()); + packet.onReceive(m_pendingPacket.Data.data(), m_pendingPacket.Data.size()); // Clear the pending packet data m_pendingPacket = PendingPacket(); diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index 81e2e49c..29ba0982 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -183,12 +183,12 @@ Socket::Status UdpSocket::receive(Packet& packet, IpAddress& remoteAddress, unsi // Receive the datagram std::size_t received = 0; - Status status = receive(&m_buffer[0], m_buffer.size(), received, remoteAddress, remotePort); + Status status = receive(m_buffer.data(), m_buffer.size(), received, remoteAddress, remotePort); // If we received valid data, we can copy it to the user packet packet.clear(); if ((status == Done) && (received > 0)) - packet.onReceive(&m_buffer[0], received); + packet.onReceive(m_buffer.data(), received); return status; } diff --git a/src/SFML/Window/FreeBSD/JoystickImpl.cpp b/src/SFML/Window/FreeBSD/JoystickImpl.cpp index 7636e472..8758b904 100644 --- a/src/SFML/Window/FreeBSD/JoystickImpl.cpp +++ b/src/SFML/Window/FreeBSD/JoystickImpl.cpp @@ -293,7 +293,7 @@ Joystick::Identification JoystickImpl::getIdentification() const //////////////////////////////////////////////////////////// JoystickState JoystickImpl::JoystickImpl::update() { - while (read(m_file, &m_buffer[0], m_length) == m_length) + while (read(m_file, m_buffer.data(), m_length) == m_length) { hid_data_t data = hid_start_parse(m_desc, 1 << hid_input, m_id); @@ -312,11 +312,11 @@ JoystickState JoystickImpl::JoystickImpl::update() if (usage == HUP_BUTTON) { - m_state.buttons[buttonIndex++] = hid_get_data(&m_buffer[0], &item); + m_state.buttons[buttonIndex++] = hid_get_data(m_buffer.data(), &item); } else if (usage == HUP_GENERIC_DESKTOP) { - int value = hid_get_data(&m_buffer[0], &item); + int value = hid_get_data(m_buffer.data(), &item); int axis = usageToAxis(usage); if (usage == HUG_HAT_SWITCH) diff --git a/src/SFML/Window/OSX/JoystickImpl.cpp b/src/SFML/Window/OSX/JoystickImpl.cpp index 215a6a92..117caa6f 100644 --- a/src/SFML/Window/OSX/JoystickImpl.cpp +++ b/src/SFML/Window/OSX/JoystickImpl.cpp @@ -45,8 +45,8 @@ namespace CFIndex length = CFStringGetLength(cfString); std::vector str(length); CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8); - CFStringGetCString(cfString, &str[0], maxSize, kCFStringEncodingUTF8); - return &str[0]; + CFStringGetCString(cfString, str.data(), maxSize, kCFStringEncodingUTF8); + return str.data(); } // Get HID device property key as a string diff --git a/src/SFML/Window/OSX/SFContext.mm b/src/SFML/Window/OSX/SFContext.mm index 8c7e5a11..88d17551 100644 --- a/src/SFML/Window/OSX/SFContext.mm +++ b/src/SFML/Window/OSX/SFContext.mm @@ -258,7 +258,7 @@ void SFContext::createContext(SFContext* shared, m_settings.sRgbCapable = true; // Create the pixel format. - NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attrs[0]]; + NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs.data()]; if (pixFmt == nil) { diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index 28d9f3de..a557ba1f 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -701,7 +701,7 @@ void GlxContext::createContext(GlxContext* shared) } // Create the context - m_context = glXCreateContextAttribsARB(m_display, *config, toShare, true, &attributes[0]); + m_context = glXCreateContextAttribsARB(m_display, *config, toShare, true, attributes.data()); if (!m_context) { diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 64886443..af8ccbb5 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -109,7 +109,7 @@ namespace buffer[offset] = 0; // Remove the path to keep the executable name only - return basename(&buffer[0]); + return basename(buffer.data()); } // Default fallback name @@ -581,7 +581,7 @@ m_lastInputTime (0) std::string executableName = findExecutableName(); std::vector windowInstance(executableName.size() + 1, 0); std::copy(executableName.begin(), executableName.end(), windowInstance.begin()); - hint->res_name = &windowInstance[0]; + hint->res_name = windowInstance.data(); // The class name identifies a class of windows that // "are of the same type". We simply use the initial window name as @@ -589,7 +589,7 @@ m_lastInputTime (0) std::string ansiTitle = title.toAnsiString(); std::vector windowClass(ansiTitle.size() + 1, 0); std::copy(ansiTitle.begin(), ansiTitle.end(), windowClass.begin()); - hint->res_class = &windowClass[0]; + hint->res_class = windowClass.data(); XSetClassHint(m_display, m_window, hint); @@ -822,7 +822,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 } } } - m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, (char*)&maskPixels[0], width, height, 1, 0, 1); + m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, reinterpret_cast(maskPixels.data()), width, height, 1, 0, 1); // Send our new icon to the window through the WMHints XWMHints* hints = XAllocWMHints(); @@ -835,7 +835,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 // ICCCM wants BGRA pixels: swap red and blue channels // ICCCM also wants the first 2 unsigned 32-bit values to be width and height std::vector icccmIconPixels(2 + width * height, 0); - unsigned long* ptr = &icccmIconPixels[0]; + unsigned long* ptr = icccmIconPixels.data(); *ptr++ = width; *ptr++ = height; @@ -856,7 +856,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 XA_CARDINAL, 32, PropModeReplace, - reinterpret_cast(&icccmIconPixels[0]), + reinterpret_cast(icccmIconPixels.data()), 2 + width * height); XFlush(m_display); @@ -1249,7 +1249,7 @@ void WindowImplX11::setProtocols() XA_ATOM, 32, PropModeReplace, - reinterpret_cast(&atoms[0]), + reinterpret_cast(atoms.data()), atoms.size()); } else diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index 6037b0dc..198f7ef2 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -649,7 +649,7 @@ void WglContext::createContext(WglContext* shared) } // Create the context - m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, &attributes[0]); + m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, attributes.data()); } else { diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index f21a85b3..9c55180d 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -364,7 +364,7 @@ void WindowImplWin32::setIcon(unsigned int width, unsigned int height, const Uin } // Create the icon from the pixel array - m_icon = CreateIcon(GetModuleHandleW(NULL), width, height, 1, 32, NULL, &iconPixels[0]); + m_icon = CreateIcon(GetModuleHandleW(NULL), width, height, 1, 32, NULL, iconPixels.data()); // Set it as both big and small icon of the window if (m_icon) From b3b094fc91423c1e4d690e926020fbb2dd6e9285 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Mon, 3 Apr 2017 19:13:33 +0200 Subject: [PATCH 13/18] Replaced NULL with nullptr. --- examples/pong/Pong.cpp | 2 +- examples/shader/Effect.hpp | 2 +- examples/shader/Shader.cpp | 2 +- examples/win32/Win32.cpp | 16 +- include/SFML/Audio/Sound.hpp | 2 +- include/SFML/Graphics/Shader.hpp | 6 +- include/SFML/Graphics/Shape.hpp | 4 +- include/SFML/Graphics/Sprite.hpp | 2 +- include/SFML/Graphics/Text.hpp | 2 +- include/SFML/Graphics/Texture.hpp | 4 +- include/SFML/Network/Packet.hpp | 2 +- include/SFML/System/Err.hpp | 2 +- include/SFML/Window/Context.hpp | 2 +- src/SFML/Audio/AudioDevice.cpp | 10 +- src/SFML/Audio/Sound.cpp | 10 +- src/SFML/Audio/SoundBuffer.cpp | 2 +- src/SFML/Audio/SoundFileFactory.cpp | 10 +- src/SFML/Audio/SoundFileReaderFlac.cpp | 8 +- src/SFML/Audio/SoundFileReaderOgg.cpp | 12 +- src/SFML/Audio/SoundFileReaderWav.cpp | 2 +- src/SFML/Audio/SoundFileWriterFlac.cpp | 6 +- src/SFML/Audio/SoundFileWriterOgg.cpp | 2 +- src/SFML/Audio/SoundRecorder.cpp | 8 +- src/SFML/Audio/SoundStream.cpp | 2 +- src/SFML/Graphics/Font.cpp | 18 +- src/SFML/Graphics/GLLoader.cpp | 302 +++++++++--------- src/SFML/Graphics/Image.cpp | 2 +- src/SFML/Graphics/RenderStates.cpp | 16 +- src/SFML/Graphics/RenderTarget.cpp | 12 +- src/SFML/Graphics/Shader.cpp | 30 +- src/SFML/Graphics/Shape.cpp | 4 +- src/SFML/Graphics/Sprite.cpp | 6 +- src/SFML/Graphics/Text.cpp | 2 +- src/SFML/Graphics/Texture.cpp | 2 +- src/SFML/Main/MainAndroid.cpp | 36 +-- src/SFML/Main/SFMLActivity.cpp | 6 +- src/SFML/Network/IpAddress.cpp | 4 +- src/SFML/Network/Packet.cpp | 4 +- src/SFML/Network/SocketSelector.cpp | 2 +- src/SFML/Network/TcpSocket.cpp | 2 +- src/SFML/System/Android/Activity.cpp | 2 +- src/SFML/System/Android/Activity.hpp | 2 +- src/SFML/System/Android/ResourceStream.cpp | 4 +- src/SFML/System/FileInputStream.cpp | 4 +- src/SFML/System/MemoryInputStream.cpp | 2 +- src/SFML/Window/Android/InputImpl.cpp | 20 +- src/SFML/Window/Android/SensorImpl.cpp | 4 +- src/SFML/Window/Android/SensorImpl.hpp | 2 +- src/SFML/Window/Android/VideoModeImpl.cpp | 2 +- src/SFML/Window/Android/WindowImplAndroid.cpp | 22 +- src/SFML/Window/Context.cpp | 2 +- src/SFML/Window/EglContext.cpp | 16 +- src/SFML/Window/EglContext.hpp | 4 +- src/SFML/Window/FreeBSD/JoystickImpl.cpp | 2 +- src/SFML/Window/GlContext.cpp | 12 +- src/SFML/Window/OSX/AutoreleasePoolWrapper.mm | 4 +- src/SFML/Window/OSX/HIDInputManager.hpp | 2 +- src/SFML/Window/OSX/HIDInputManager.mm | 12 +- src/SFML/Window/OSX/HIDJoystickManager.cpp | 6 +- src/SFML/Window/OSX/HIDJoystickManager.hpp | 2 +- src/SFML/Window/OSX/InputImpl.mm | 2 +- src/SFML/Window/OSX/JoystickImpl.cpp | 10 +- src/SFML/Window/OSX/SFContext.hpp | 4 +- src/SFML/Window/OSX/SFContext.mm | 4 +- src/SFML/Window/OSX/VideoModeImpl.cpp | 4 +- src/SFML/Window/Unix/Display.cpp | 4 +- src/SFML/Window/Unix/GlxContext.cpp | 34 +- src/SFML/Window/Unix/GlxContext.hpp | 6 +- src/SFML/Window/Unix/GlxExtensions.cpp | 30 +- src/SFML/Window/Unix/JoystickImpl.cpp | 14 +- src/SFML/Window/Unix/WindowImplX11.cpp | 44 +-- src/SFML/Window/Win32/JoystickImpl.cpp | 6 +- src/SFML/Window/Win32/VideoModeImpl.cpp | 4 +- src/SFML/Window/Win32/WglContext.cpp | 50 +-- src/SFML/Window/Win32/WglContext.hpp | 6 +- src/SFML/Window/Win32/WglExtensions.cpp | 36 +-- src/SFML/Window/Win32/WindowImplWin32.cpp | 54 ++-- src/SFML/Window/Window.cpp | 6 +- src/SFML/Window/iOS/EaglContext.hpp | 6 +- src/SFML/Window/iOS/SFAppDelegate.mm | 4 +- src/SFML/Window/iOS/SFView.mm | 2 +- 81 files changed, 512 insertions(+), 512 deletions(-) diff --git a/examples/pong/Pong.cpp b/examples/pong/Pong.cpp index 58c9fd71..9fdcede0 100644 --- a/examples/pong/Pong.cpp +++ b/examples/pong/Pong.cpp @@ -17,7 +17,7 @@ //////////////////////////////////////////////////////////// int main() { - std::srand(static_cast(std::time(NULL))); + std::srand(static_cast(std::time(nullptr))); // Define some constants const float pi = 3.14159f; diff --git a/examples/shader/Effect.hpp b/examples/shader/Effect.hpp index 0ff65b43..f6065dfe 100644 --- a/examples/shader/Effect.hpp +++ b/examples/shader/Effect.hpp @@ -66,7 +66,7 @@ protected: static const sf::Font& getFont() { - assert(s_font != NULL); + assert(s_font != nullptr); return *s_font; } diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index 0b8fd4f1..1d87cf17 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -8,7 +8,7 @@ #include -const sf::Font* Effect::s_font = NULL; +const sf::Font* Effect::s_font = nullptr; //////////////////////////////////////////////////////////// // "Pixelate" fragment shader diff --git a/examples/win32/Win32.cpp b/examples/win32/Win32.cpp index aedfc76e..e39b42f9 100644 --- a/examples/win32/Win32.cpp +++ b/examples/win32/Win32.cpp @@ -49,7 +49,7 @@ LRESULT CALLBACK onEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam //////////////////////////////////////////////////////////// int main() { - HINSTANCE instance = GetModuleHandle(NULL); + HINSTANCE instance = GetModuleHandle(nullptr); // Define a class for our main window WNDCLASS windowClass; @@ -58,22 +58,22 @@ int main() windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = instance; - windowClass.hIcon = NULL; + windowClass.hIcon = nullptr; windowClass.hCursor = 0; windowClass.hbrBackground = reinterpret_cast(COLOR_BACKGROUND); - windowClass.lpszMenuName = NULL; + windowClass.lpszMenuName = nullptr; windowClass.lpszClassName = TEXT("SFML App"); RegisterClass(&windowClass); // Let's create the main window - HWND window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, NULL, NULL, instance, NULL); + HWND window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, nullptr, nullptr, instance, nullptr); // Add a button for exiting - button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, window, NULL, instance, NULL); + button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, window, nullptr, instance, nullptr); // Let's create two SFML views - HWND view1 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, window, NULL, instance, NULL); - HWND view2 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, window, NULL, instance, NULL); + HWND view1 = CreateWindow(TEXT("STATIC"), nullptr, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, window, nullptr, instance, nullptr); + HWND view2 = CreateWindow(TEXT("STATIC"), nullptr, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, window, nullptr, instance, nullptr); sf::RenderWindow SFMLView1(view1); sf::RenderWindow SFMLView2(view2); @@ -94,7 +94,7 @@ int main() message.message = static_cast(~WM_QUIT); while (message.message != WM_QUIT) { - if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) + if (PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) { // If a message was waiting in the message queue, process it TranslateMessage(&message); diff --git a/include/SFML/Audio/Sound.hpp b/include/SFML/Audio/Sound.hpp index 5f21cf1e..3ef57606 100644 --- a/include/SFML/Audio/Sound.hpp +++ b/include/SFML/Audio/Sound.hpp @@ -158,7 +158,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Get the audio buffer attached to the sound /// - /// \return Sound buffer attached to the sound (can be NULL) + /// \return Sound buffer attached to the sound (can be nullptr) /// //////////////////////////////////////////////////////////// const SoundBuffer* getBuffer() const; diff --git a/include/SFML/Graphics/Shader.hpp b/include/SFML/Graphics/Shader.hpp index 9fe9c607..114dbdc8 100644 --- a/include/SFML/Graphics/Shader.hpp +++ b/include/SFML/Graphics/Shader.hpp @@ -651,7 +651,7 @@ public: /// // draw OpenGL stuff that use s1... /// sf::Shader::bind(&s2); /// // draw OpenGL stuff that use s2... - /// sf::Shader::bind(NULL); + /// sf::Shader::bind(nullptr); /// // draw OpenGL stuff that use no shader... /// \endcode /// @@ -696,7 +696,7 @@ private: //////////////////////////////////////////////////////////// /// \brief Compile the shader(s) and create the program /// - /// If one of the arguments is NULL, the corresponding shader + /// If one of the arguments is nullptr, the corresponding shader /// is not created. /// /// \param vertexShaderCode Source code of the vertex shader @@ -867,7 +867,7 @@ private: /// \code /// sf::Shader::bind(&shader); /// ... render OpenGL geometry ... -/// sf::Shader::bind(NULL); +/// sf::Shader::bind(nullptr); /// \endcode /// /// \see sf::Glsl diff --git a/include/SFML/Graphics/Shape.hpp b/include/SFML/Graphics/Shape.hpp index 18f8626f..73722d5c 100644 --- a/include/SFML/Graphics/Shape.hpp +++ b/include/SFML/Graphics/Shape.hpp @@ -60,7 +60,7 @@ public: /// a pointer to the one that you passed to this function. /// If the source texture is destroyed and the shape tries to /// use it, the behavior is undefined. - /// \a texture can be NULL to disable texturing. + /// \a texture can be nullptr to disable texturing. /// If \a resetRect is true, the TextureRect property of /// the shape is automatically adjusted to the size of the new /// texture. If it is false, the texture rect is left unchanged. @@ -134,7 +134,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Get the source texture of the shape /// - /// If the shape has no source texture, a NULL pointer is returned. + /// If the shape has no source texture, a nullptr pointer is returned. /// The returned pointer is const, which means that you can't /// modify the texture when you retrieve it with this function. /// diff --git a/include/SFML/Graphics/Sprite.hpp b/include/SFML/Graphics/Sprite.hpp index 1791690e..d2c42060 100644 --- a/include/SFML/Graphics/Sprite.hpp +++ b/include/SFML/Graphics/Sprite.hpp @@ -130,7 +130,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Get the source texture of the sprite /// - /// If the sprite has no source texture, a NULL pointer is returned. + /// If the sprite has no source texture, a nullptr pointer is returned. /// The returned pointer is const, which means that you can't /// modify the texture when you retrieve it with this function. /// diff --git a/include/SFML/Graphics/Text.hpp b/include/SFML/Graphics/Text.hpp index 4d3238d9..ac8463d6 100644 --- a/include/SFML/Graphics/Text.hpp +++ b/include/SFML/Graphics/Text.hpp @@ -239,7 +239,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Get the text's font /// - /// If the text has no font attached, a NULL pointer is returned. + /// If the text has no font attached, a nullptr pointer is returned. /// The returned pointer is const, which means that you /// cannot modify the font when you get it from this function. /// diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index 20a8ede8..99ae3725 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -551,7 +551,7 @@ public: /// // draw OpenGL stuff that use t1... /// sf::Texture::bind(&t2); /// // draw OpenGL stuff that use t2... - /// sf::Texture::bind(NULL); + /// sf::Texture::bind(nullptr); /// // draw OpenGL stuff that use no texture... /// \endcode /// @@ -723,7 +723,7 @@ private: /// \code /// sf::Texture::bind(&texture); /// ... render OpenGL geometry ... -/// sf::Texture::bind(NULL); +/// sf::Texture::bind(nullptr); /// \endcode /// /// \see sf::Sprite, sf::Image, sf::RenderTexture diff --git a/include/SFML/Network/Packet.hpp b/include/SFML/Network/Packet.hpp index ac97692a..e9970c39 100644 --- a/include/SFML/Network/Packet.hpp +++ b/include/SFML/Network/Packet.hpp @@ -92,7 +92,7 @@ public: /// Warning: the returned pointer may become invalid after /// you append data to the packet, therefore it should never /// be stored. - /// The return pointer is NULL if the packet is empty. + /// The return pointer is nullptr if the packet is empty. /// /// \return Pointer to the data /// diff --git a/include/SFML/System/Err.hpp b/include/SFML/System/Err.hpp index 56505a9d..a41f4626 100644 --- a/include/SFML/System/Err.hpp +++ b/include/SFML/System/Err.hpp @@ -69,7 +69,7 @@ SFML_SYSTEM_API std::ostream& err(); /// std::streambuf* previous = sf::err().rdbuf(file.rdbuf()); /// /// // Redirect to nothing -/// sf::err().rdbuf(NULL); +/// sf::err().rdbuf(nullptr); /// /// // Restore the original output /// sf::err().rdbuf(previous); diff --git a/include/SFML/Window/Context.hpp b/include/SFML/Window/Context.hpp index 53e6177b..1a0057d3 100644 --- a/include/SFML/Window/Context.hpp +++ b/include/SFML/Window/Context.hpp @@ -113,7 +113,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Get the currently active context /// - /// \return The currently active context or NULL if none is active + /// \return The currently active context or nullptr if none is active /// //////////////////////////////////////////////////////////// static const Context* getActiveContext(); diff --git a/src/SFML/Audio/AudioDevice.cpp b/src/SFML/Audio/AudioDevice.cpp index 02fd0e37..d5472cee 100644 --- a/src/SFML/Audio/AudioDevice.cpp +++ b/src/SFML/Audio/AudioDevice.cpp @@ -33,8 +33,8 @@ namespace { - ALCdevice* audioDevice = NULL; - ALCcontext* audioContext = NULL; + ALCdevice* audioDevice = nullptr; + ALCcontext* audioContext = nullptr; float listenerVolume = 100.f; sf::Vector3f listenerPosition (0.f, 0.f, 0.f); @@ -50,12 +50,12 @@ namespace priv AudioDevice::AudioDevice() { // Create the device - audioDevice = alcOpenDevice(NULL); + audioDevice = alcOpenDevice(nullptr); if (audioDevice) { // Create the context - audioContext = alcCreateContext(audioDevice, NULL); + audioContext = alcCreateContext(audioDevice, nullptr); if (audioContext) { @@ -89,7 +89,7 @@ AudioDevice::AudioDevice() AudioDevice::~AudioDevice() { // Destroy the context - alcMakeContextCurrent(NULL); + alcMakeContextCurrent(nullptr); if (audioContext) alcDestroyContext(audioContext); diff --git a/src/SFML/Audio/Sound.cpp b/src/SFML/Audio/Sound.cpp index 8ebaa038..1b4aeefa 100644 --- a/src/SFML/Audio/Sound.cpp +++ b/src/SFML/Audio/Sound.cpp @@ -34,14 +34,14 @@ namespace sf { //////////////////////////////////////////////////////////// Sound::Sound() : -m_buffer(NULL) +m_buffer(nullptr) { } //////////////////////////////////////////////////////////// Sound::Sound(const SoundBuffer& buffer) : -m_buffer(NULL) +m_buffer(nullptr) { setBuffer(buffer); } @@ -50,7 +50,7 @@ m_buffer(NULL) //////////////////////////////////////////////////////////// Sound::Sound(const Sound& copy) : SoundSource(copy), -m_buffer (NULL) +m_buffer (nullptr) { if (copy.m_buffer) setBuffer(*copy.m_buffer); @@ -168,7 +168,7 @@ Sound& Sound::operator =(const Sound& right) { stop(); m_buffer->detachSound(this); - m_buffer = NULL; + m_buffer = nullptr; } // Copy the remaining sound attributes @@ -191,7 +191,7 @@ void Sound::resetBuffer() { alCheck(alSourcei(m_source, AL_BUFFER, 0)); m_buffer->detachSound(this); - m_buffer = NULL; + m_buffer = nullptr; } } diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index 9ccc13bd..bae25181 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -162,7 +162,7 @@ bool SoundBuffer::saveToFile(const std::string& filename) const //////////////////////////////////////////////////////////// const Int16* SoundBuffer::getSamples() const { - return m_samples.empty() ? NULL : m_samples.data(); + return m_samples.empty() ? nullptr : m_samples.data(); } diff --git a/src/SFML/Audio/SoundFileFactory.cpp b/src/SFML/Audio/SoundFileFactory.cpp index 172fa415..f12b847f 100644 --- a/src/SFML/Audio/SoundFileFactory.cpp +++ b/src/SFML/Audio/SoundFileFactory.cpp @@ -72,7 +72,7 @@ std::unique_ptr SoundFileFactory::createReaderFromFilename(cons FileInputStream stream; if (!stream.open(filename)) { err() << "Failed to open sound file \"" << filename << "\" (couldn't open stream)" << std::endl; - return NULL; + return nullptr; } // Test the filename in all the registered factories @@ -85,7 +85,7 @@ std::unique_ptr SoundFileFactory::createReaderFromFilename(cons // No suitable reader found err() << "Failed to open sound file \"" << filename << "\" (format not supported)" << std::endl; - return NULL; + return nullptr; } @@ -109,7 +109,7 @@ std::unique_ptr SoundFileFactory::createReaderFromMemory(const // No suitable reader found err() << "Failed to open sound file from memory (format not supported)" << std::endl; - return NULL; + return nullptr; } @@ -129,7 +129,7 @@ std::unique_ptr SoundFileFactory::createReaderFromStream(InputS // No suitable reader found err() << "Failed to open sound file from stream (format not supported)" << std::endl; - return NULL; + return nullptr; } @@ -148,7 +148,7 @@ std::unique_ptr SoundFileFactory::createWriterFromFilename(cons // No suitable writer found err() << "Failed to open sound file \"" << filename << "\" (format not supported)" << std::endl; - return NULL; + return nullptr; } } // namespace sf diff --git a/src/SFML/Audio/SoundFileReaderFlac.cpp b/src/SFML/Audio/SoundFileReaderFlac.cpp index 00794b66..64112ab7 100644 --- a/src/SFML/Audio/SoundFileReaderFlac.cpp +++ b/src/SFML/Audio/SoundFileReaderFlac.cpp @@ -191,7 +191,7 @@ bool SoundFileReaderFlac::check(InputStream& stream) ClientData data; data.stream = &stream; data.error = false; - FLAC__stream_decoder_init_stream(decoder, &streamRead, &streamSeek, &streamTell, &streamLength, &streamEof, &streamWrite, NULL, &streamError, &data); + FLAC__stream_decoder_init_stream(decoder, &streamRead, &streamSeek, &streamTell, &streamLength, &streamEof, &streamWrite, nullptr, &streamError, &data); // Read the header bool valid = FLAC__stream_decoder_process_until_end_of_metadata(decoder) != 0; @@ -206,7 +206,7 @@ bool SoundFileReaderFlac::check(InputStream& stream) //////////////////////////////////////////////////////////// SoundFileReaderFlac::SoundFileReaderFlac() : -m_decoder(NULL), +m_decoder(nullptr), m_clientData() { } @@ -255,7 +255,7 @@ void SoundFileReaderFlac::seek(Uint64 sampleOffset) assert(m_decoder); // Reset the callback data (the "write" callback will be called) - m_clientData.buffer = NULL; + m_clientData.buffer = nullptr; m_clientData.remaining = 0; m_clientData.leftovers.clear(); @@ -331,7 +331,7 @@ void SoundFileReaderFlac::close() { FLAC__stream_decoder_finish(m_decoder); FLAC__stream_decoder_delete(m_decoder); - m_decoder = NULL; + m_decoder = nullptr; } } diff --git a/src/SFML/Audio/SoundFileReaderOgg.cpp b/src/SFML/Audio/SoundFileReaderOgg.cpp index df46193e..b99cbd75 100644 --- a/src/SFML/Audio/SoundFileReaderOgg.cpp +++ b/src/SFML/Audio/SoundFileReaderOgg.cpp @@ -63,7 +63,7 @@ namespace return static_cast(stream->tell()); } - static ov_callbacks callbacks = {&read, &seek, NULL, &tell}; + static ov_callbacks callbacks = {&read, &seek, nullptr, &tell}; } namespace sf @@ -74,7 +74,7 @@ namespace priv bool SoundFileReaderOgg::check(InputStream& stream) { OggVorbis_File file; - if (ov_test_callbacks(&stream, &file, NULL, 0, callbacks) == 0) + if (ov_test_callbacks(&stream, &file, nullptr, 0, callbacks) == 0) { ov_clear(&file); return true; @@ -91,7 +91,7 @@ SoundFileReaderOgg::SoundFileReaderOgg() : m_vorbis (), m_channelCount(0) { - m_vorbis.datasource = NULL; + m_vorbis.datasource = nullptr; } @@ -106,7 +106,7 @@ SoundFileReaderOgg::~SoundFileReaderOgg() bool SoundFileReaderOgg::open(InputStream& stream, Info& info) { // Open the Vorbis stream - int status = ov_open_callbacks(&stream, &m_vorbis, NULL, 0, callbacks); + int status = ov_open_callbacks(&stream, &m_vorbis, nullptr, 0, callbacks); if (status < 0) { err() << "Failed to open Vorbis file for reading" << std::endl; @@ -145,7 +145,7 @@ Uint64 SoundFileReaderOgg::read(Int16* samples, Uint64 maxCount) while (count < maxCount) { int bytesToRead = static_cast(maxCount - count) * sizeof(Int16); - long bytesRead = ov_read(&m_vorbis, reinterpret_cast(samples), bytesToRead, 0, 2, 1, NULL); + long bytesRead = ov_read(&m_vorbis, reinterpret_cast(samples), bytesToRead, 0, 2, 1, nullptr); if (bytesRead > 0) { long samplesRead = bytesRead / sizeof(Int16); @@ -169,7 +169,7 @@ void SoundFileReaderOgg::close() if (m_vorbis.datasource) { ov_clear(&m_vorbis); - m_vorbis.datasource = NULL; + m_vorbis.datasource = nullptr; m_channelCount = 0; } } diff --git a/src/SFML/Audio/SoundFileReaderWav.cpp b/src/SFML/Audio/SoundFileReaderWav.cpp index 6f4a7779..35ca04a6 100644 --- a/src/SFML/Audio/SoundFileReaderWav.cpp +++ b/src/SFML/Audio/SoundFileReaderWav.cpp @@ -108,7 +108,7 @@ bool SoundFileReaderWav::check(InputStream& stream) //////////////////////////////////////////////////////////// SoundFileReaderWav::SoundFileReaderWav() : -m_stream (NULL), +m_stream (nullptr), m_bytesPerSample(0), m_dataStart (0), m_dataEnd (0) diff --git a/src/SFML/Audio/SoundFileWriterFlac.cpp b/src/SFML/Audio/SoundFileWriterFlac.cpp index b72ee0d5..acc66f3c 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.cpp +++ b/src/SFML/Audio/SoundFileWriterFlac.cpp @@ -48,7 +48,7 @@ bool SoundFileWriterFlac::check(const std::string& filename) //////////////////////////////////////////////////////////// SoundFileWriterFlac::SoundFileWriterFlac() : -m_encoder (NULL), +m_encoder (nullptr), m_channelCount(0), m_samples32 () { @@ -79,7 +79,7 @@ bool SoundFileWriterFlac::open(const std::string& filename, unsigned int sampleR FLAC__stream_encoder_set_sample_rate(m_encoder, sampleRate); // Initialize the output stream - if (FLAC__stream_encoder_init_file(m_encoder, filename.c_str(), NULL, NULL) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) + if (FLAC__stream_encoder_init_file(m_encoder, filename.c_str(), nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { err() << "Failed to write flac file \"" << filename << "\" (failed to open the file)" << std::endl; close(); @@ -124,7 +124,7 @@ void SoundFileWriterFlac::close() // Destroy the encoder FLAC__stream_encoder_delete(m_encoder); - m_encoder = NULL; + m_encoder = nullptr; } } diff --git a/src/SFML/Audio/SoundFileWriterOgg.cpp b/src/SFML/Audio/SoundFileWriterOgg.cpp index a5cbf15b..52f3a348 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.cpp +++ b/src/SFML/Audio/SoundFileWriterOgg.cpp @@ -167,7 +167,7 @@ void SoundFileWriterOgg::flushBlocks() while (vorbis_analysis_blockout(&m_state, &block) == 1) { // Let the automatic bitrate management do its job - vorbis_analysis(&block, NULL); + vorbis_analysis(&block, nullptr); vorbis_bitrate_addblock(&block); // Get new packets from the bitrate management engine diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index f139d67e..bc678bc6 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -40,7 +40,7 @@ namespace { - ALCdevice* captureDevice = NULL; + ALCdevice* captureDevice = nullptr; } namespace sf @@ -152,7 +152,7 @@ std::vector SoundRecorder::getAvailableDevices() { std::vector deviceNameList; - const ALchar* deviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); + const ALchar* deviceList = alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER); if (deviceList) { while (*deviceList) @@ -169,7 +169,7 @@ std::vector SoundRecorder::getAvailableDevices() //////////////////////////////////////////////////////////// std::string SoundRecorder::getDefaultDevice() { - return alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); + return alcGetString(nullptr, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); } @@ -333,7 +333,7 @@ void SoundRecorder::cleanup() // Close the device alcCaptureCloseDevice(captureDevice); - captureDevice = NULL; + captureDevice = nullptr; } } // namespace sf diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 78320da7..e6d6afc4 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -406,7 +406,7 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop) bool requestStop = false; // Acquire audio data, also address EOF and error cases if they occur - Chunk data = {NULL, 0}; + Chunk data = {nullptr, 0}; for (Uint32 retryCount = 0; !onGetData(data) && (retryCount < BufferRetries); ++retryCount) { // Mark the buffer as the last one (so that we know when to reset the playing position) diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index ec82080f..868e3df1 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -68,9 +68,9 @@ namespace sf { //////////////////////////////////////////////////////////// Font::Font() : -m_library (NULL), -m_face (NULL), -m_stroker (NULL), +m_library (nullptr), +m_face (nullptr), +m_stroker (nullptr), m_info () { } @@ -241,7 +241,7 @@ bool Font::loadFromStream(InputStream& stream) // Prepare a wrapper for our stream, that we'll pass to FreeType callbacks auto rec = std::make_shared(); std::memset(rec.get(), 0, sizeof(FT_StreamRec)); - rec->base = NULL; + rec->base = nullptr; rec->size = static_cast(stream.getSize()); rec->pos = 0; rec->descriptor.pointer = &stream; @@ -476,10 +476,10 @@ void Font::cleanup() } // Reset members - m_library = NULL; - m_face = NULL; - m_stroker = NULL; - m_streamRec = NULL; + m_library = nullptr; + m_face = nullptr; + m_stroker = nullptr; + m_streamRec = nullptr; m_pages.clear(); std::vector().swap(m_pixelBuffer); } @@ -647,7 +647,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) const { // Find the line that fits well the glyph - Row* row = NULL; + Row* row = nullptr; float bestRatio = 0; for (std::vector::iterator it = page.rows.begin(); it != page.rows.end() && !row; ++it) { diff --git a/src/SFML/Graphics/GLLoader.cpp b/src/SFML/Graphics/GLLoader.cpp index ec1531fb..d5d5838f 100644 --- a/src/SFML/Graphics/GLLoader.cpp +++ b/src/SFML/Graphics/GLLoader.cpp @@ -50,7 +50,7 @@ int sfogl_ext_EXT_framebuffer_object = sfogl_LOAD_FAILED; int sfogl_ext_EXT_framebuffer_blit = sfogl_LOAD_FAILED; int sfogl_ext_ARB_geometry_shader4 = sfogl_LOAD_FAILED; -void (GL_FUNCPTR *sf_ptrc_glBlendEquationEXT)(GLenum) = NULL; +void (GL_FUNCPTR *sf_ptrc_glBlendEquationEXT)(GLenum) = nullptr; static int Load_EXT_blend_minmax() { @@ -63,40 +63,40 @@ static int Load_EXT_blend_minmax() return numFailed; } -void (GL_FUNCPTR *sf_ptrc_glActiveTextureARB)(GLenum) = NULL; -void (GL_FUNCPTR *sf_ptrc_glClientActiveTextureARB)(GLenum) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1dARB)(GLenum, GLdouble) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1dvARB)(GLenum, const GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1fARB)(GLenum, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1fvARB)(GLenum, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1iARB)(GLenum, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1ivARB)(GLenum, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1sARB)(GLenum, GLshort) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1svARB)(GLenum, const GLshort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2dARB)(GLenum, GLdouble, GLdouble) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2dvARB)(GLenum, const GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2fARB)(GLenum, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2fvARB)(GLenum, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2iARB)(GLenum, GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2ivARB)(GLenum, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2sARB)(GLenum, GLshort, GLshort) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2svARB)(GLenum, const GLshort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3dARB)(GLenum, GLdouble, GLdouble, GLdouble) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3dvARB)(GLenum, const GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3fARB)(GLenum, GLfloat, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3fvARB)(GLenum, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3iARB)(GLenum, GLint, GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3ivARB)(GLenum, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3sARB)(GLenum, GLshort, GLshort, GLshort) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3svARB)(GLenum, const GLshort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4dARB)(GLenum, GLdouble, GLdouble, GLdouble, GLdouble) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4dvARB)(GLenum, const GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4fARB)(GLenum, GLfloat, GLfloat, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4fvARB)(GLenum, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4iARB)(GLenum, GLint, GLint, GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4ivARB)(GLenum, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4sARB)(GLenum, GLshort, GLshort, GLshort, GLshort) = NULL; -void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4svARB)(GLenum, const GLshort*) = NULL; +void (GL_FUNCPTR *sf_ptrc_glActiveTextureARB)(GLenum) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glClientActiveTextureARB)(GLenum) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1dARB)(GLenum, GLdouble) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1dvARB)(GLenum, const GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1fARB)(GLenum, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1fvARB)(GLenum, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1iARB)(GLenum, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1ivARB)(GLenum, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1sARB)(GLenum, GLshort) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord1svARB)(GLenum, const GLshort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2dARB)(GLenum, GLdouble, GLdouble) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2dvARB)(GLenum, const GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2fARB)(GLenum, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2fvARB)(GLenum, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2iARB)(GLenum, GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2ivARB)(GLenum, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2sARB)(GLenum, GLshort, GLshort) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord2svARB)(GLenum, const GLshort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3dARB)(GLenum, GLdouble, GLdouble, GLdouble) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3dvARB)(GLenum, const GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3fARB)(GLenum, GLfloat, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3fvARB)(GLenum, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3iARB)(GLenum, GLint, GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3ivARB)(GLenum, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3sARB)(GLenum, GLshort, GLshort, GLshort) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord3svARB)(GLenum, const GLshort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4dARB)(GLenum, GLdouble, GLdouble, GLdouble, GLdouble) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4dvARB)(GLenum, const GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4fARB)(GLenum, GLfloat, GLfloat, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4fvARB)(GLenum, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4iARB)(GLenum, GLint, GLint, GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4ivARB)(GLenum, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4sARB)(GLenum, GLshort, GLshort, GLshort, GLshort) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glMultiTexCoord4svARB)(GLenum, const GLshort*) = nullptr; static int Load_ARB_multitexture() { @@ -241,7 +241,7 @@ static int Load_ARB_multitexture() return numFailed; } -void (GL_FUNCPTR *sf_ptrc_glBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum) = NULL; +void (GL_FUNCPTR *sf_ptrc_glBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum) = nullptr; static int Load_EXT_blend_func_separate() { @@ -254,45 +254,45 @@ static int Load_EXT_blend_func_separate() return numFailed; } -void (GL_FUNCPTR *sf_ptrc_glAttachObjectARB)(GLhandleARB, GLhandleARB) = NULL; -void (GL_FUNCPTR *sf_ptrc_glCompileShaderARB)(GLhandleARB) = NULL; -GLhandleARB (GL_FUNCPTR *sf_ptrc_glCreateProgramObjectARB)() = NULL; -GLhandleARB (GL_FUNCPTR *sf_ptrc_glCreateShaderObjectARB)(GLenum) = NULL; -void (GL_FUNCPTR *sf_ptrc_glDeleteObjectARB)(GLhandleARB) = NULL; -void (GL_FUNCPTR *sf_ptrc_glDetachObjectARB)(GLhandleARB, GLhandleARB) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetActiveUniformARB)(GLhandleARB, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLcharARB*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetAttachedObjectsARB)(GLhandleARB, GLsizei, GLsizei*, GLhandleARB*) = NULL; -GLhandleARB (GL_FUNCPTR *sf_ptrc_glGetHandleARB)(GLenum) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetInfoLogARB)(GLhandleARB, GLsizei, GLsizei*, GLcharARB*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetObjectParameterfvARB)(GLhandleARB, GLenum, GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetObjectParameterivARB)(GLhandleARB, GLenum, GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetShaderSourceARB)(GLhandleARB, GLsizei, GLsizei*, GLcharARB*) = NULL; -GLint (GL_FUNCPTR *sf_ptrc_glGetUniformLocationARB)(GLhandleARB, const GLcharARB*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetUniformfvARB)(GLhandleARB, GLint, GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetUniformivARB)(GLhandleARB, GLint, GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glLinkProgramARB)(GLhandleARB) = NULL; -void (GL_FUNCPTR *sf_ptrc_glShaderSourceARB)(GLhandleARB, GLsizei, const GLcharARB**, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform1fARB)(GLint, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform1fvARB)(GLint, GLsizei, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform1iARB)(GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform1ivARB)(GLint, GLsizei, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform2fARB)(GLint, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform2fvARB)(GLint, GLsizei, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform2iARB)(GLint, GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform2ivARB)(GLint, GLsizei, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform3fARB)(GLint, GLfloat, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform3fvARB)(GLint, GLsizei, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform3iARB)(GLint, GLint, GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform3ivARB)(GLint, GLsizei, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform4fARB)(GLint, GLfloat, GLfloat, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform4fvARB)(GLint, GLsizei, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform4iARB)(GLint, GLint, GLint, GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniform4ivARB)(GLint, GLsizei, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniformMatrix2fvARB)(GLint, GLsizei, GLboolean, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniformMatrix3fvARB)(GLint, GLsizei, GLboolean, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUniformMatrix4fvARB)(GLint, GLsizei, GLboolean, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glUseProgramObjectARB)(GLhandleARB) = NULL; -void (GL_FUNCPTR *sf_ptrc_glValidateProgramARB)(GLhandleARB) = NULL; +void (GL_FUNCPTR *sf_ptrc_glAttachObjectARB)(GLhandleARB, GLhandleARB) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glCompileShaderARB)(GLhandleARB) = nullptr; +GLhandleARB (GL_FUNCPTR *sf_ptrc_glCreateProgramObjectARB)() = nullptr; +GLhandleARB (GL_FUNCPTR *sf_ptrc_glCreateShaderObjectARB)(GLenum) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glDeleteObjectARB)(GLhandleARB) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glDetachObjectARB)(GLhandleARB, GLhandleARB) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetActiveUniformARB)(GLhandleARB, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLcharARB*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetAttachedObjectsARB)(GLhandleARB, GLsizei, GLsizei*, GLhandleARB*) = nullptr; +GLhandleARB (GL_FUNCPTR *sf_ptrc_glGetHandleARB)(GLenum) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetInfoLogARB)(GLhandleARB, GLsizei, GLsizei*, GLcharARB*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetObjectParameterfvARB)(GLhandleARB, GLenum, GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetObjectParameterivARB)(GLhandleARB, GLenum, GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetShaderSourceARB)(GLhandleARB, GLsizei, GLsizei*, GLcharARB*) = nullptr; +GLint (GL_FUNCPTR *sf_ptrc_glGetUniformLocationARB)(GLhandleARB, const GLcharARB*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetUniformfvARB)(GLhandleARB, GLint, GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetUniformivARB)(GLhandleARB, GLint, GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glLinkProgramARB)(GLhandleARB) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glShaderSourceARB)(GLhandleARB, GLsizei, const GLcharARB**, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform1fARB)(GLint, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform1fvARB)(GLint, GLsizei, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform1iARB)(GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform1ivARB)(GLint, GLsizei, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform2fARB)(GLint, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform2fvARB)(GLint, GLsizei, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform2iARB)(GLint, GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform2ivARB)(GLint, GLsizei, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform3fARB)(GLint, GLfloat, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform3fvARB)(GLint, GLsizei, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform3iARB)(GLint, GLint, GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform3ivARB)(GLint, GLsizei, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform4fARB)(GLint, GLfloat, GLfloat, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform4fvARB)(GLint, GLsizei, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform4iARB)(GLint, GLint, GLint, GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniform4ivARB)(GLint, GLsizei, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniformMatrix2fvARB)(GLint, GLsizei, GLboolean, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniformMatrix3fvARB)(GLint, GLsizei, GLboolean, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUniformMatrix4fvARB)(GLint, GLsizei, GLboolean, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glUseProgramObjectARB)(GLhandleARB) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glValidateProgramARB)(GLhandleARB) = nullptr; static int Load_ARB_shader_objects() { @@ -457,52 +457,52 @@ static int Load_ARB_shader_objects() return numFailed; } -void (GL_FUNCPTR *sf_ptrc_glBindAttribLocationARB)(GLhandleARB, GLuint, const GLcharARB*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glDisableVertexAttribArrayARB)(GLuint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glEnableVertexAttribArrayARB)(GLuint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetActiveAttribARB)(GLhandleARB, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLcharARB*) = NULL; -GLint (GL_FUNCPTR *sf_ptrc_glGetAttribLocationARB)(GLhandleARB, const GLcharARB*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetVertexAttribPointervARB)(GLuint, GLenum, void**) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetVertexAttribdvARB)(GLuint, GLenum, GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetVertexAttribfvARB)(GLuint, GLenum, GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetVertexAttribivARB)(GLuint, GLenum, GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1dARB)(GLuint, GLdouble) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1dvARB)(GLuint, const GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1fARB)(GLuint, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1fvARB)(GLuint, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1sARB)(GLuint, GLshort) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1svARB)(GLuint, const GLshort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2dARB)(GLuint, GLdouble, GLdouble) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2dvARB)(GLuint, const GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2fARB)(GLuint, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2fvARB)(GLuint, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2sARB)(GLuint, GLshort, GLshort) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2svARB)(GLuint, const GLshort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3dARB)(GLuint, GLdouble, GLdouble, GLdouble) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3dvARB)(GLuint, const GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3fARB)(GLuint, GLfloat, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3fvARB)(GLuint, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3sARB)(GLuint, GLshort, GLshort, GLshort) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3svARB)(GLuint, const GLshort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NbvARB)(GLuint, const GLbyte*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NivARB)(GLuint, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NsvARB)(GLuint, const GLshort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NubARB)(GLuint, GLubyte, GLubyte, GLubyte, GLubyte) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NubvARB)(GLuint, const GLubyte*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NuivARB)(GLuint, const GLuint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NusvARB)(GLuint, const GLushort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4bvARB)(GLuint, const GLbyte*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4dARB)(GLuint, GLdouble, GLdouble, GLdouble, GLdouble) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4dvARB)(GLuint, const GLdouble*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4fARB)(GLuint, GLfloat, GLfloat, GLfloat, GLfloat) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4fvARB)(GLuint, const GLfloat*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4ivARB)(GLuint, const GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4sARB)(GLuint, GLshort, GLshort, GLshort, GLshort) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4svARB)(GLuint, const GLshort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4ubvARB)(GLuint, const GLubyte*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4uivARB)(GLuint, const GLuint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4usvARB)(GLuint, const GLushort*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glVertexAttribPointerARB)(GLuint, GLint, GLenum, GLboolean, GLsizei, const void*) = NULL; +void (GL_FUNCPTR *sf_ptrc_glBindAttribLocationARB)(GLhandleARB, GLuint, const GLcharARB*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glDisableVertexAttribArrayARB)(GLuint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glEnableVertexAttribArrayARB)(GLuint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetActiveAttribARB)(GLhandleARB, GLuint, GLsizei, GLsizei*, GLint*, GLenum*, GLcharARB*) = nullptr; +GLint (GL_FUNCPTR *sf_ptrc_glGetAttribLocationARB)(GLhandleARB, const GLcharARB*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetVertexAttribPointervARB)(GLuint, GLenum, void**) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetVertexAttribdvARB)(GLuint, GLenum, GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetVertexAttribfvARB)(GLuint, GLenum, GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetVertexAttribivARB)(GLuint, GLenum, GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1dARB)(GLuint, GLdouble) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1dvARB)(GLuint, const GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1fARB)(GLuint, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1fvARB)(GLuint, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1sARB)(GLuint, GLshort) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib1svARB)(GLuint, const GLshort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2dARB)(GLuint, GLdouble, GLdouble) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2dvARB)(GLuint, const GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2fARB)(GLuint, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2fvARB)(GLuint, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2sARB)(GLuint, GLshort, GLshort) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib2svARB)(GLuint, const GLshort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3dARB)(GLuint, GLdouble, GLdouble, GLdouble) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3dvARB)(GLuint, const GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3fARB)(GLuint, GLfloat, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3fvARB)(GLuint, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3sARB)(GLuint, GLshort, GLshort, GLshort) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib3svARB)(GLuint, const GLshort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NbvARB)(GLuint, const GLbyte*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NivARB)(GLuint, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NsvARB)(GLuint, const GLshort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NubARB)(GLuint, GLubyte, GLubyte, GLubyte, GLubyte) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NubvARB)(GLuint, const GLubyte*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NuivARB)(GLuint, const GLuint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4NusvARB)(GLuint, const GLushort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4bvARB)(GLuint, const GLbyte*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4dARB)(GLuint, GLdouble, GLdouble, GLdouble, GLdouble) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4dvARB)(GLuint, const GLdouble*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4fARB)(GLuint, GLfloat, GLfloat, GLfloat, GLfloat) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4fvARB)(GLuint, const GLfloat*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4ivARB)(GLuint, const GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4sARB)(GLuint, GLshort, GLshort, GLshort, GLshort) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4svARB)(GLuint, const GLshort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4ubvARB)(GLuint, const GLubyte*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4uivARB)(GLuint, const GLuint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttrib4usvARB)(GLuint, const GLushort*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glVertexAttribPointerARB)(GLuint, GLint, GLenum, GLboolean, GLsizei, const void*) = nullptr; static int Load_ARB_vertex_shader() { @@ -695,7 +695,7 @@ static int Load_ARB_vertex_shader() return numFailed; } -void (GL_FUNCPTR *sf_ptrc_glBlendEquationSeparateEXT)(GLenum, GLenum) = NULL; +void (GL_FUNCPTR *sf_ptrc_glBlendEquationSeparateEXT)(GLenum, GLenum) = nullptr; static int Load_EXT_blend_equation_separate() { @@ -708,23 +708,23 @@ static int Load_EXT_blend_equation_separate() return numFailed; } -void (GL_FUNCPTR *sf_ptrc_glBindFramebufferEXT)(GLenum, GLuint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glBindRenderbufferEXT)(GLenum, GLuint) = NULL; -GLenum (GL_FUNCPTR *sf_ptrc_glCheckFramebufferStatusEXT)(GLenum) = NULL; -void (GL_FUNCPTR *sf_ptrc_glDeleteFramebuffersEXT)(GLsizei, const GLuint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glDeleteRenderbuffersEXT)(GLsizei, const GLuint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glFramebufferRenderbufferEXT)(GLenum, GLenum, GLenum, GLuint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glFramebufferTexture1DEXT)(GLenum, GLenum, GLenum, GLuint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glFramebufferTexture2DEXT)(GLenum, GLenum, GLenum, GLuint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glFramebufferTexture3DEXT)(GLenum, GLenum, GLenum, GLuint, GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGenFramebuffersEXT)(GLsizei, GLuint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGenRenderbuffersEXT)(GLsizei, GLuint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGenerateMipmapEXT)(GLenum) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetFramebufferAttachmentParameterivEXT)(GLenum, GLenum, GLenum, GLint*) = NULL; -void (GL_FUNCPTR *sf_ptrc_glGetRenderbufferParameterivEXT)(GLenum, GLenum, GLint*) = NULL; -GLboolean (GL_FUNCPTR *sf_ptrc_glIsFramebufferEXT)(GLuint) = NULL; -GLboolean (GL_FUNCPTR *sf_ptrc_glIsRenderbufferEXT)(GLuint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glRenderbufferStorageEXT)(GLenum, GLenum, GLsizei, GLsizei) = NULL; +void (GL_FUNCPTR *sf_ptrc_glBindFramebufferEXT)(GLenum, GLuint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glBindRenderbufferEXT)(GLenum, GLuint) = nullptr; +GLenum (GL_FUNCPTR *sf_ptrc_glCheckFramebufferStatusEXT)(GLenum) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glDeleteFramebuffersEXT)(GLsizei, const GLuint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glDeleteRenderbuffersEXT)(GLsizei, const GLuint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glFramebufferRenderbufferEXT)(GLenum, GLenum, GLenum, GLuint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glFramebufferTexture1DEXT)(GLenum, GLenum, GLenum, GLuint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glFramebufferTexture2DEXT)(GLenum, GLenum, GLenum, GLuint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glFramebufferTexture3DEXT)(GLenum, GLenum, GLenum, GLuint, GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGenFramebuffersEXT)(GLsizei, GLuint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGenRenderbuffersEXT)(GLsizei, GLuint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGenerateMipmapEXT)(GLenum) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetFramebufferAttachmentParameterivEXT)(GLenum, GLenum, GLenum, GLint*) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glGetRenderbufferParameterivEXT)(GLenum, GLenum, GLint*) = nullptr; +GLboolean (GL_FUNCPTR *sf_ptrc_glIsFramebufferEXT)(GLuint) = nullptr; +GLboolean (GL_FUNCPTR *sf_ptrc_glIsRenderbufferEXT)(GLuint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glRenderbufferStorageEXT)(GLenum, GLenum, GLsizei, GLsizei) = nullptr; static int Load_EXT_framebuffer_object() { @@ -801,7 +801,7 @@ static int Load_EXT_framebuffer_object() return numFailed; } -void (GL_FUNCPTR *sf_ptrc_glBlitFramebufferEXT)(GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum) = NULL; +void (GL_FUNCPTR *sf_ptrc_glBlitFramebufferEXT)(GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum) = nullptr; static int Load_EXT_framebuffer_blit() { @@ -814,10 +814,10 @@ static int Load_EXT_framebuffer_blit() return numFailed; } -void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureARB)(GLenum, GLenum, GLuint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureFaceARB)(GLenum, GLenum, GLuint, GLint, GLenum) = NULL; -void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureLayerARB)(GLenum, GLenum, GLuint, GLint, GLint) = NULL; -void (GL_FUNCPTR *sf_ptrc_glProgramParameteriARB)(GLuint, GLenum, GLint) = NULL; +void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureARB)(GLenum, GLenum, GLuint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureFaceARB)(GLenum, GLenum, GLuint, GLint, GLenum) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glFramebufferTextureLayerARB)(GLenum, GLenum, GLuint, GLint, GLint) = nullptr; +void (GL_FUNCPTR *sf_ptrc_glProgramParameteriARB)(GLuint, GLenum, GLint) = nullptr; static int Load_ARB_geometry_shader4() { @@ -851,19 +851,19 @@ typedef struct sfogl_StrToExtMap_s } sfogl_StrToExtMap; static sfogl_StrToExtMap ExtensionMap[16] = { - {"GL_SGIS_texture_edge_clamp", &sfogl_ext_SGIS_texture_edge_clamp, NULL}, - {"GL_EXT_texture_edge_clamp", &sfogl_ext_EXT_texture_edge_clamp, NULL}, + {"GL_SGIS_texture_edge_clamp", &sfogl_ext_SGIS_texture_edge_clamp, nullptr}, + {"GL_EXT_texture_edge_clamp", &sfogl_ext_EXT_texture_edge_clamp, nullptr}, {"GL_EXT_blend_minmax", &sfogl_ext_EXT_blend_minmax, Load_EXT_blend_minmax}, - {"GL_EXT_blend_subtract", &sfogl_ext_EXT_blend_subtract, NULL}, + {"GL_EXT_blend_subtract", &sfogl_ext_EXT_blend_subtract, nullptr}, {"GL_ARB_multitexture", &sfogl_ext_ARB_multitexture, Load_ARB_multitexture}, {"GL_EXT_blend_func_separate", &sfogl_ext_EXT_blend_func_separate, Load_EXT_blend_func_separate}, - {"GL_ARB_shading_language_100", &sfogl_ext_ARB_shading_language_100, NULL}, + {"GL_ARB_shading_language_100", &sfogl_ext_ARB_shading_language_100, nullptr}, {"GL_ARB_shader_objects", &sfogl_ext_ARB_shader_objects, Load_ARB_shader_objects}, {"GL_ARB_vertex_shader", &sfogl_ext_ARB_vertex_shader, Load_ARB_vertex_shader}, - {"GL_ARB_fragment_shader", &sfogl_ext_ARB_fragment_shader, NULL}, - {"GL_ARB_texture_non_power_of_two", &sfogl_ext_ARB_texture_non_power_of_two, NULL}, + {"GL_ARB_fragment_shader", &sfogl_ext_ARB_fragment_shader, nullptr}, + {"GL_ARB_texture_non_power_of_two", &sfogl_ext_ARB_texture_non_power_of_two, nullptr}, {"GL_EXT_blend_equation_separate", &sfogl_ext_EXT_blend_equation_separate, Load_EXT_blend_equation_separate}, - {"GL_EXT_texture_sRGB", &sfogl_ext_EXT_texture_sRGB, NULL}, + {"GL_EXT_texture_sRGB", &sfogl_ext_EXT_texture_sRGB, nullptr}, {"GL_EXT_framebuffer_object", &sfogl_ext_EXT_framebuffer_object, Load_EXT_framebuffer_object}, {"GL_EXT_framebuffer_blit", &sfogl_ext_EXT_framebuffer_blit, Load_EXT_framebuffer_blit}, {"GL_ARB_geometry_shader4", &sfogl_ext_ARB_geometry_shader4, Load_ARB_geometry_shader4} diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 00bb1a7e..efc77f5d 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -284,7 +284,7 @@ const Uint8* Image::getPixelsPtr() const else { err() << "Trying to access the pixels of an empty image" << std::endl; - return NULL; + return nullptr; } } diff --git a/src/SFML/Graphics/RenderStates.cpp b/src/SFML/Graphics/RenderStates.cpp index bc451031..01a0f09b 100644 --- a/src/SFML/Graphics/RenderStates.cpp +++ b/src/SFML/Graphics/RenderStates.cpp @@ -43,8 +43,8 @@ const RenderStates RenderStates::Default(BlendMode( RenderStates::RenderStates() : blendMode(BlendAlpha), transform(), -texture (NULL), -shader (NULL) +texture (nullptr), +shader (nullptr) { } @@ -53,8 +53,8 @@ shader (NULL) RenderStates::RenderStates(const Transform& theTransform) : blendMode(BlendAlpha), transform(theTransform), -texture (NULL), -shader (NULL) +texture (nullptr), +shader (nullptr) { } @@ -63,8 +63,8 @@ shader (NULL) RenderStates::RenderStates(const BlendMode& theBlendMode) : blendMode(theBlendMode), transform(), -texture (NULL), -shader (NULL) +texture (nullptr), +shader (nullptr) { } @@ -74,7 +74,7 @@ RenderStates::RenderStates(const Texture* theTexture) : blendMode(BlendAlpha), transform(), texture (theTexture), -shader (NULL) +shader (nullptr) { } @@ -83,7 +83,7 @@ shader (NULL) RenderStates::RenderStates(const Shader* theShader) : blendMode(BlendAlpha), transform(), -texture (NULL), +texture (nullptr), shader (theShader) { } diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 146f48a2..0b5a6af1 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -102,7 +102,7 @@ void RenderTarget::clear(const Color& color) if (setActive(true)) { // Unbind texture to fix RenderTexture preventing clear - applyTexture(NULL); + applyTexture(nullptr); glCheck(glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f)); glCheck(glClear(GL_COLOR_BUFFER_BIT)); @@ -267,7 +267,7 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, if (!m_cache.useVertexCache) vertices = m_cache.vertexCache; else - vertices = NULL; + vertices = nullptr; } // Setup the pointers to the vertices' components @@ -289,12 +289,12 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, // Unbind the shader, if any if (states.shader) - applyShader(NULL); + applyShader(nullptr); // If the texture we used to draw belonged to a RenderTexture, then forcibly unbind that texture. // This prevents a bug where some drivers do not clear RenderTextures properly. if (states.texture && states.texture->m_fboAttachment) - applyTexture(NULL); + applyTexture(nullptr); // Update the cache m_cache.useVertexCache = useVertexCache; @@ -387,9 +387,9 @@ void RenderTarget::resetGLStates() // Apply the default SFML states applyBlendMode(BlendAlpha); applyTransform(Transform::Identity); - applyTexture(NULL); + applyTexture(nullptr); if (shaderAvailable) - applyShader(NULL); + applyShader(nullptr); m_cache.useVertexCache = false; diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 066a8b10..86511d4e 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -228,11 +228,11 @@ bool Shader::loadFromFile(const std::string& filename, Type type) // Compile the shader program if (type == Vertex) - return compile(shader.data(), NULL, NULL); + return compile(shader.data(), nullptr, nullptr); else if (type == Geometry) - return compile(NULL, shader.data(), NULL); + return compile(nullptr, shader.data(), nullptr); else - return compile(NULL, NULL, shader.data()); + return compile(nullptr, nullptr, shader.data()); } @@ -256,7 +256,7 @@ bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::st } // Compile the shader program - return compile(vertexShader.data(), NULL, fragmentShader.data()); + return compile(vertexShader.data(), nullptr, fragmentShader.data()); } @@ -297,11 +297,11 @@ bool Shader::loadFromMemory(const std::string& shader, Type type) { // Compile the shader program if (type == Vertex) - return compile(shader.c_str(), NULL, NULL); + return compile(shader.c_str(), nullptr, nullptr); else if (type == Geometry) - return compile(NULL, shader.c_str(), NULL); + return compile(nullptr, shader.c_str(), nullptr); else - return compile(NULL, NULL, shader.c_str()); + return compile(nullptr, nullptr, shader.c_str()); } @@ -309,7 +309,7 @@ bool Shader::loadFromMemory(const std::string& shader, Type type) bool Shader::loadFromMemory(const std::string& vertexShader, const std::string& fragmentShader) { // Compile the shader program - return compile(vertexShader.c_str(), NULL, fragmentShader.c_str()); + return compile(vertexShader.c_str(), nullptr, fragmentShader.c_str()); } @@ -334,11 +334,11 @@ bool Shader::loadFromStream(InputStream& stream, Type type) // Compile the shader program if (type == Vertex) - return compile(shader.data(), NULL, NULL); + return compile(shader.data(), nullptr, nullptr); else if (type == Geometry) - return compile(NULL, shader.data(), NULL); + return compile(nullptr, shader.data(), nullptr); else - return compile(NULL, NULL, shader.data()); + return compile(nullptr, nullptr, shader.data()); } @@ -362,7 +362,7 @@ bool Shader::loadFromStream(InputStream& vertexShaderStream, InputStream& fragme } // Compile the shader program - return compile(vertexShader.data(), NULL, fragmentShader.data()); + return compile(vertexShader.data(), nullptr, fragmentShader.data()); } @@ -835,7 +835,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod // Create and compile the shader GLEXT_GLhandle vertexShader; glCheck(vertexShader = GLEXT_glCreateShaderObject(GLEXT_GL_VERTEX_SHADER)); - glCheck(GLEXT_glShaderSource(vertexShader, 1, &vertexShaderCode, NULL)); + glCheck(GLEXT_glShaderSource(vertexShader, 1, &vertexShaderCode, nullptr)); glCheck(GLEXT_glCompileShader(vertexShader)); // Check the compile log @@ -862,7 +862,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod { // Create and compile the shader GLEXT_GLhandle geometryShader = GLEXT_glCreateShaderObject(GLEXT_GL_GEOMETRY_SHADER); - glCheck(GLEXT_glShaderSource(geometryShader, 1, &geometryShaderCode, NULL)); + glCheck(GLEXT_glShaderSource(geometryShader, 1, &geometryShaderCode, nullptr)); glCheck(GLEXT_glCompileShader(geometryShader)); // Check the compile log @@ -890,7 +890,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod // Create and compile the shader GLEXT_GLhandle fragmentShader; glCheck(fragmentShader = GLEXT_glCreateShaderObject(GLEXT_GL_FRAGMENT_SHADER)); - glCheck(GLEXT_glShaderSource(fragmentShader, 1, &fragmentShaderCode, NULL)); + glCheck(GLEXT_glShaderSource(fragmentShader, 1, &fragmentShaderCode, nullptr)); glCheck(GLEXT_glCompileShader(fragmentShader)); // Check the compile log diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index c0d4f821..634286c9 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -158,7 +158,7 @@ FloatRect Shape::getGlobalBounds() const //////////////////////////////////////////////////////////// Shape::Shape() : -m_texture (NULL), +m_texture (nullptr), m_textureRect (), m_fillColor (255, 255, 255), m_outlineColor (255, 255, 255), @@ -221,7 +221,7 @@ void Shape::draw(RenderTarget& target, RenderStates states) const // Render the outline if (m_outlineThickness != 0) { - states.texture = NULL; + states.texture = nullptr; target.draw(m_outlineVertices, states); } } diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 71d5c70a..bad0059a 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -35,7 +35,7 @@ namespace sf { //////////////////////////////////////////////////////////// Sprite::Sprite() : -m_texture (NULL), +m_texture (nullptr), m_textureRect() { } @@ -43,7 +43,7 @@ m_textureRect() //////////////////////////////////////////////////////////// Sprite::Sprite(const Texture& texture) : -m_texture (NULL), +m_texture (nullptr), m_textureRect() { setTexture(texture); @@ -52,7 +52,7 @@ m_textureRect() //////////////////////////////////////////////////////////// Sprite::Sprite(const Texture& texture, const IntRect& rectangle) : -m_texture (NULL), +m_texture (nullptr), m_textureRect() { setTexture(texture); diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 5ad50c1f..c830e0bd 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -75,7 +75,7 @@ namespace sf //////////////////////////////////////////////////////////// Text::Text() : m_string (), -m_font (NULL), +m_font (nullptr), m_characterSize (30), m_style (Regular), m_fillColor (255, 255, 255), diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 98d4fbb7..bd066972 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -197,7 +197,7 @@ bool Texture::create(unsigned int width, unsigned int height) // Initialize the texture glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); - glCheck(glTexImage2D(GL_TEXTURE_2D, 0, (m_sRgb ? GLEXT_GL_SRGB8_ALPHA8 : GL_RGBA), m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)); + glCheck(glTexImage2D(GL_TEXTURE_2D, 0, (m_sRgb ? GLEXT_GL_SRGB8_ALPHA8 : GL_RGBA), m_actualSize.x, m_actualSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_isRepeated ? GL_REPEAT : (textureEdgeClamp ? GLEXT_GL_CLAMP_TO_EDGE : GLEXT_GL_CLAMP))); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index c5a352e0..7db2082a 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -60,11 +60,11 @@ int getAndroidApiLevel(ANativeActivity* activity) JNIEnv* lJNIEnv = activity->env; jclass versionClass = lJNIEnv->FindClass("android/os/Build$VERSION"); - if (versionClass == NULL) + if (versionClass == nullptr) return 0; jfieldID sdkIntFieldID = lJNIEnv->GetStaticFieldID(versionClass, "SDK_INT", "I"); - if (sdkIntFieldID == NULL) + if (sdkIntFieldID == nullptr) return 0; jint sdkInt = 0; @@ -117,7 +117,7 @@ void* main(ActivityStates* states) initializeMain(states); sleep(seconds(0.5)); - ::main(0, NULL); + ::main(0, nullptr); // Terminate properly the main thread and wait until it's done terminateMain(states); @@ -128,7 +128,7 @@ void* main(ActivityStates* states) states->terminated = true; } - return NULL; + return nullptr; } } // namespace priv @@ -315,7 +315,7 @@ static void onDestroy(ANativeActivity* activity) delete states; // Reset the activity pointer for all modules - sf::priv::getActivity(NULL, true); + sf::priv::getActivity(nullptr, true); // The application should now terminate } @@ -353,7 +353,7 @@ static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* wi std::lock_guard lock(states->mutex); // Update the activity states - states->window = NULL; + states->window = nullptr; // Notify SFML mechanism sf::Event event; @@ -393,7 +393,7 @@ static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue) { std::lock_guard lock(states->mutex); - AInputQueue_attachLooper(queue, states->looper, 1, states->processEvent, NULL); + AInputQueue_attachLooper(queue, states->looper, 1, states->processEvent, nullptr); states->inputQueue = queue; } } @@ -409,7 +409,7 @@ static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue) { std::lock_guard lock(states->mutex); - states->inputQueue = NULL; + states->inputQueue = nullptr; AInputQueue_detachLooper(queue); } } @@ -429,7 +429,7 @@ static void onContentRectChanged(ANativeActivity* activity, const ARect* rect) std::lock_guard lock(states->mutex); // Make sure the window still exists before we access the dimensions on it - if (states->window != NULL) { + if (states->window != nullptr) { // Send an event to warn people about the window move/resize sf::Event event; event.type = sf::Event::Resized; @@ -452,7 +452,7 @@ static void* onSaveInstanceState(ANativeActivity* activity, size_t* outLen) { *outLen = 0; - return NULL; + return nullptr; } @@ -466,22 +466,22 @@ static void onLowMemory(ANativeActivity* activity) void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize) { // Create an activity states (will keep us in the know, about events we care) - sf::priv::ActivityStates* states = NULL; + sf::priv::ActivityStates* states = nullptr; states = new sf::priv::ActivityStates; // Initialize the states value - states->activity = NULL; - states->window = NULL; - states->looper = NULL; - states->inputQueue = NULL; - states->config = NULL; + states->activity = nullptr; + states->window = nullptr; + states->looper = nullptr; + states->inputQueue = nullptr; + states->config = nullptr; for (unsigned int i = 0; i < sf::Mouse::ButtonCount; i++) states->isButtonPressed[i] = false; states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (savedState != NULL) + if (savedState != nullptr) { states->savedState = malloc(savedStateSize); states->savedStateSize = savedStateSize; @@ -527,7 +527,7 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_ AWINDOW_FLAG_KEEP_SCREEN_ON); // Initialize the display - eglInitialize(states->display, NULL, NULL); + eglInitialize(states->display, nullptr, nullptr); getScreenSizeInPixels(activity, &states->screenSize.x, &states->screenSize.y); diff --git a/src/SFML/Main/SFMLActivity.cpp b/src/SFML/Main/SFMLActivity.cpp index 07602fb2..070f72b4 100644 --- a/src/SFML/Main/SFMLActivity.cpp +++ b/src/SFML/Main/SFMLActivity.cpp @@ -59,7 +59,7 @@ const char *getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo) jstring valueString = (jstring)lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName); // No meta-data "sfml.app.lib_name" was found so we abort and inform the user - if (valueString == NULL) + if (valueString == nullptr) { LOGE("No meta-data 'sfml.app.lib_name' found in AndroidManifest.xml file"); exit(1); @@ -67,7 +67,7 @@ const char *getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo) // Convert the application name to a C++ string and return it const jsize applicationNameLength = lJNIEnv->GetStringUTFLength(valueString); - const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, NULL); + const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, nullptr); if (applicationNameLength >= 256) { @@ -107,7 +107,7 @@ void* loadLibrary(const char* libraryName, JNIEnv* lJNIEnv, jobject& ObjectActiv // Get the library absolute path and convert it jmethodID MethodGetPath = lJNIEnv->GetMethodID(ClassFile, "getPath", "()Ljava/lang/String;"); jstring javaLibraryPath = static_cast(lJNIEnv->CallObjectMethod(ObjectFile, MethodGetPath)); - const char* libraryPath = lJNIEnv->GetStringUTFChars(javaLibraryPath, NULL); + const char* libraryPath = lJNIEnv->GetStringUTFChars(javaLibraryPath, nullptr); // Manually load the library void * handle = dlopen(libraryPath, RTLD_NOW | RTLD_GLOBAL); diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 91eec78e..923e5c53 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -193,8 +193,8 @@ void IpAddress::resolve(const std::string& address) addrinfo hints; std::memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; - addrinfo* result = NULL; - if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) + addrinfo* result = nullptr; + if (getaddrinfo(address.c_str(), nullptr, &hints, &result) == 0) { if (result) { diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index 7dff0a8b..3349ed57 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -75,7 +75,7 @@ void Packet::clear() //////////////////////////////////////////////////////////// const void* Packet::getData() const { - return !m_data.empty() ? m_data.data() : NULL; + return !m_data.empty() ? m_data.data() : nullptr; } @@ -96,7 +96,7 @@ bool Packet::endOfPacket() const //////////////////////////////////////////////////////////// Packet::operator BoolType() const { - return m_isValid ? &Packet::checkSize : NULL; + return m_isValid ? &Packet::checkSize : nullptr; } diff --git a/src/SFML/Network/SocketSelector.cpp b/src/SFML/Network/SocketSelector.cpp index 9159391a..ad2ae373 100644 --- a/src/SFML/Network/SocketSelector.cpp +++ b/src/SFML/Network/SocketSelector.cpp @@ -162,7 +162,7 @@ bool SocketSelector::wait(Time timeout) // Wait until one of the sockets is ready for reading, or timeout is reached // The first parameter is ignored on Windows - int count = select(m_impl->maxSocket + 1, &m_impl->socketsReady, NULL, NULL, timeout != Time::Zero ? &time : NULL); + int count = select(m_impl->maxSocket + 1, &m_impl->socketsReady, nullptr, nullptr, timeout != Time::Zero ? &time : nullptr); return count > 0; } diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index 73394011..944ca79b 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -175,7 +175,7 @@ Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short time.tv_usec = static_cast(timeout.asMicroseconds() % 1000000); // Wait for something to write on our socket (which means that the connection request has returned) - if (select(static_cast(getHandle() + 1), NULL, &selector, NULL, &time) > 0) + if (select(static_cast(getHandle() + 1), nullptr, &selector, nullptr, &time) > 0) { // At this point the connection may have been either accepted or refused. // To know whether it's a success or a failure, we must check the address of the connected peer diff --git a/src/SFML/System/Android/Activity.cpp b/src/SFML/System/Android/Activity.cpp index 4f657ee0..7067ccae 100644 --- a/src/SFML/System/Android/Activity.cpp +++ b/src/SFML/System/Android/Activity.cpp @@ -58,7 +58,7 @@ namespace priv { ActivityStates* getActivity(ActivityStates* initializedStates, bool reset) { - static ActivityStates* states = NULL; + static ActivityStates* states = nullptr; if (!states || reset) states = initializedStates; diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp index 772ab70e..94df7afd 100644 --- a/src/SFML/System/Android/Activity.hpp +++ b/src/SFML/System/Android/Activity.hpp @@ -92,7 +92,7 @@ struct ActivityStates LogcatStream logcat; }; -SFML_SYSTEM_API ActivityStates* getActivity(ActivityStates* initializedStates=NULL, bool reset=false); +SFML_SYSTEM_API ActivityStates* getActivity(ActivityStates* initializedStates=nullptr, bool reset=false); } // namespace priv } // namespace sf diff --git a/src/SFML/System/Android/ResourceStream.cpp b/src/SFML/System/Android/ResourceStream.cpp index b6f2b390..d4c40ea7 100644 --- a/src/SFML/System/Android/ResourceStream.cpp +++ b/src/SFML/System/Android/ResourceStream.cpp @@ -38,9 +38,9 @@ namespace priv //////////////////////////////////////////////////////////// ResourceStream::ResourceStream(const std::string& filename) : -m_file (NULL) +m_file (nullptr) { - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); std::lock_guard lock(states->mutex); m_file = AAssetManager_open(states->activity->assetManager, filename.c_str(), AASSET_MODE_UNKNOWN); } diff --git a/src/SFML/System/FileInputStream.cpp b/src/SFML/System/FileInputStream.cpp index 924b6c43..63199353 100644 --- a/src/SFML/System/FileInputStream.cpp +++ b/src/SFML/System/FileInputStream.cpp @@ -35,7 +35,7 @@ namespace sf { //////////////////////////////////////////////////////////// FileInputStream::FileInputStream() -: m_file(NULL) +: m_file(nullptr) { } @@ -63,7 +63,7 @@ bool FileInputStream::open(const std::string& filename) m_file = std::fopen(filename.c_str(), "rb"); - return m_file != NULL; + return m_file != nullptr; #endif } diff --git a/src/SFML/System/MemoryInputStream.cpp b/src/SFML/System/MemoryInputStream.cpp index e3129279..a0ac46cf 100644 --- a/src/SFML/System/MemoryInputStream.cpp +++ b/src/SFML/System/MemoryInputStream.cpp @@ -33,7 +33,7 @@ namespace sf { //////////////////////////////////////////////////////////// MemoryInputStream::MemoryInputStream() : -m_data (NULL), +m_data (nullptr), m_size (0), m_offset(0) { diff --git a/src/SFML/Window/Android/InputImpl.cpp b/src/SFML/Window/Android/InputImpl.cpp index 3108f78c..1ab1e1f0 100644 --- a/src/SFML/Window/Android/InputImpl.cpp +++ b/src/SFML/Window/Android/InputImpl.cpp @@ -48,7 +48,7 @@ void InputImpl::setVirtualKeyboardVisible(bool visible) { // todo: Check if the window is active - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); std::lock_guard lock(states->mutex); // Initializes JNI @@ -61,7 +61,7 @@ void InputImpl::setVirtualKeyboardVisible(bool visible) JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; - lJavaVMAttachArgs.group = NULL; + lJavaVMAttachArgs.group = nullptr; lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); @@ -136,9 +136,9 @@ void InputImpl::setVirtualKeyboardVisible(bool visible) //////////////////////////////////////////////////////////// bool InputImpl::isMouseButtonPressed(Mouse::Button button) { - ALooper_pollAll(0, NULL, NULL, NULL); + ALooper_pollAll(0, nullptr, nullptr, nullptr); - priv::ActivityStates* states = priv::getActivity(NULL); + priv::ActivityStates* states = priv::getActivity(nullptr); std::lock_guard lock(states->mutex); return states->isButtonPressed[button]; @@ -148,9 +148,9 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) //////////////////////////////////////////////////////////// Vector2i InputImpl::getMousePosition() { - ALooper_pollAll(0, NULL, NULL, NULL); + ALooper_pollAll(0, nullptr, nullptr, nullptr); - priv::ActivityStates* states = priv::getActivity(NULL); + priv::ActivityStates* states = priv::getActivity(nullptr); std::lock_guard lock(states->mutex); return states->mousePosition; @@ -181,9 +181,9 @@ void InputImpl::setMousePosition(const Vector2i& position, const Window& relativ //////////////////////////////////////////////////////////// bool InputImpl::isTouchDown(unsigned int finger) { - ALooper_pollAll(0, NULL, NULL, NULL); + ALooper_pollAll(0, nullptr, nullptr, nullptr); - priv::ActivityStates* states = priv::getActivity(NULL); + priv::ActivityStates* states = priv::getActivity(nullptr); std::lock_guard lock(states->mutex); return states->touchEvents.find(finger) != states->touchEvents.end(); @@ -193,9 +193,9 @@ bool InputImpl::isTouchDown(unsigned int finger) //////////////////////////////////////////////////////////// Vector2i InputImpl::getTouchPosition(unsigned int finger) { - ALooper_pollAll(0, NULL, NULL, NULL); + ALooper_pollAll(0, nullptr, nullptr, nullptr); - priv::ActivityStates* states = priv::getActivity(NULL); + priv::ActivityStates* states = priv::getActivity(nullptr); std::lock_guard lock(states->mutex); return states->touchEvents.find(finger)->second; diff --git a/src/SFML/Window/Android/SensorImpl.cpp b/src/SFML/Window/Android/SensorImpl.cpp index 201c3ebf..902a410f 100644 --- a/src/SFML/Window/Android/SensorImpl.cpp +++ b/src/SFML/Window/Android/SensorImpl.cpp @@ -58,7 +58,7 @@ void SensorImpl::initialize() // Create the sensor events queue and attach it to the looper sensorEventQueue = ASensorManager_createEventQueue(sensorManager, looper, - 1, &processSensorEvents, NULL); + 1, &processSensorEvents, nullptr); } @@ -113,7 +113,7 @@ void SensorImpl::close() Vector3f SensorImpl::update() { // Update our sensor data list - ALooper_pollAll(0, NULL, NULL, NULL); + ALooper_pollAll(0, nullptr, nullptr, nullptr); return sensorData[m_index]; } diff --git a/src/SFML/Window/Android/SensorImpl.hpp b/src/SFML/Window/Android/SensorImpl.hpp index 5cae66b4..a35c56b6 100644 --- a/src/SFML/Window/Android/SensorImpl.hpp +++ b/src/SFML/Window/Android/SensorImpl.hpp @@ -105,7 +105,7 @@ private: /// /// \param type Type of the sensor /// - /// \return The default Android sensor, NULL otherwise + /// \return The default Android sensor, nullptr otherwise /// //////////////////////////////////////////////////////////// static ASensor const* getDefaultSensor(Sensor::Type sensor); diff --git a/src/SFML/Window/Android/VideoModeImpl.cpp b/src/SFML/Window/Android/VideoModeImpl.cpp index 4d11ad61..ce39de5f 100644 --- a/src/SFML/Window/Android/VideoModeImpl.cpp +++ b/src/SFML/Window/Android/VideoModeImpl.cpp @@ -52,7 +52,7 @@ std::vector VideoModeImpl::getFullscreenModes() VideoMode VideoModeImpl::getDesktopMode() { // Get the activity states - priv::ActivityStates* states = priv::getActivity(NULL); + priv::ActivityStates* states = priv::getActivity(nullptr); std::lock_guard lock(states->mutex); return VideoMode(states->screenSize.x, states->screenSize.y); diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index 6f226890..5c0f4305 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -46,7 +46,7 @@ namespace sf { namespace priv { -WindowImplAndroid* WindowImplAndroid::singleInstance = NULL; +WindowImplAndroid* WindowImplAndroid::singleInstance = nullptr; //////////////////////////////////////////////////////////// WindowImplAndroid::WindowImplAndroid(WindowHandle handle) @@ -65,7 +65,7 @@ WindowImplAndroid::WindowImplAndroid(VideoMode mode, const String& title, unsign , m_windowBeingDestroyed(false) , m_hasFocus(false) { - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); std::lock_guard lock(states->mutex); if (style& Style::Fullscreen) @@ -90,7 +90,7 @@ WindowImplAndroid::~WindowImplAndroid() //////////////////////////////////////////////////////////// WindowHandle WindowImplAndroid::getSystemHandle() const { - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); std::lock_guard lock(states->mutex); return states->window; @@ -101,9 +101,9 @@ WindowHandle WindowImplAndroid::getSystemHandle() const void WindowImplAndroid::processEvents() { // Process incoming OS events - ALooper_pollAll(0, NULL, NULL, NULL); + ALooper_pollAll(0, nullptr, nullptr, nullptr); - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); std::lock_guard lock(states->mutex); if (m_windowBeingCreated) @@ -209,7 +209,7 @@ bool WindowImplAndroid::hasFocus() const //////////////////////////////////////////////////////////// void WindowImplAndroid::forwardEvent(const Event& event) { - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); if (event.type == Event::GainedFocus) { @@ -231,10 +231,10 @@ void WindowImplAndroid::forwardEvent(const Event& event) //////////////////////////////////////////////////////////// int WindowImplAndroid::processEvent(int fd, int events, void* data) { - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); std::lock_guard lock(states->mutex); - AInputEvent* _event = NULL; + AInputEvent* _event = nullptr; if (AInputQueue_getEvent(states->inputQueue, &_event) >= 0) { @@ -315,7 +315,7 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates* s JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; - lJavaVMAttachArgs.group = NULL; + lJavaVMAttachArgs.group = nullptr; lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); @@ -665,7 +665,7 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(int32_t key) int WindowImplAndroid::getUnicode(AInputEvent* event) { // Retrieve activity states - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); std::lock_guard lock(states->mutex); // Initializes JNI @@ -678,7 +678,7 @@ int WindowImplAndroid::getUnicode(AInputEvent* event) JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; - lJavaVMAttachArgs.group = NULL; + lJavaVMAttachArgs.group = nullptr; lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); diff --git a/src/SFML/Window/Context.cpp b/src/SFML/Window/Context.cpp index b59e4deb..2d40438d 100644 --- a/src/SFML/Window/Context.cpp +++ b/src/SFML/Window/Context.cpp @@ -58,7 +58,7 @@ bool Context::setActive(bool active) bool result = m_context->setActive(active); if (result) - currentContext = (active ? this : NULL); + currentContext = (active ? this : nullptr); return result; } diff --git a/src/SFML/Window/EglContext.cpp b/src/SFML/Window/EglContext.cpp index d1893886..65f408b4 100644 --- a/src/SFML/Window/EglContext.cpp +++ b/src/SFML/Window/EglContext.cpp @@ -50,7 +50,7 @@ namespace if (display == EGL_NO_DISPLAY) { display = eglCheck(eglGetDisplay(EGL_DEFAULT_DISPLAY)); - eglCheck(eglInitialize(display, NULL, NULL)); + eglCheck(eglInitialize(display, nullptr, nullptr)); } return display; @@ -58,7 +58,7 @@ namespace #elif defined(SFML_SYSTEM_ANDROID) // On Android, its native activity handles this for us - sf::priv::ActivityStates* states = sf::priv::getActivity(NULL); + sf::priv::ActivityStates* states = sf::priv::getActivity(nullptr); std::lock_guard lock(states->mutex); return states->display; @@ -77,7 +77,7 @@ EglContext::EglContext(EglContext* shared) : m_display (EGL_NO_DISPLAY), m_context (EGL_NO_CONTEXT), m_surface (EGL_NO_SURFACE), -m_config (NULL) +m_config (nullptr) { // Get the initialized EGL display m_display = getInitializedDisplay(); @@ -86,7 +86,7 @@ m_config (NULL) m_config = getBestConfig(m_display, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings()); updateSettings(); - // Note: The EGL specs say that attrib_list can be NULL when passed to eglCreatePbufferSurface, + // Note: The EGL specs say that attrib_list can be nullptr when passed to eglCreatePbufferSurface, // but this is resulting in a segfault. Bug in Android? EGLint attrib_list[] = { EGL_WIDTH, 1, @@ -106,12 +106,12 @@ EglContext::EglContext(EglContext* shared, const ContextSettings& settings, cons m_display (EGL_NO_DISPLAY), m_context (EGL_NO_CONTEXT), m_surface (EGL_NO_SURFACE), -m_config (NULL) +m_config (nullptr) { #ifdef SFML_SYSTEM_ANDROID // On Android, we must save the created context - ActivityStates* states = getActivity(NULL); + ActivityStates* states = getActivity(nullptr); std::lock_guard lock(states->mutex); states->context = this; @@ -141,7 +141,7 @@ EglContext::EglContext(EglContext* shared, const ContextSettings& settings, unsi m_display (EGL_NO_DISPLAY), m_context (EGL_NO_CONTEXT), m_surface (EGL_NO_SURFACE), -m_config (NULL) +m_config (nullptr) { } @@ -222,7 +222,7 @@ void EglContext::createContext(EglContext* shared) //////////////////////////////////////////////////////////// void EglContext::createSurface(EGLNativeWindowType window) { - m_surface = eglCheck(eglCreateWindowSurface(m_display, m_config, window, NULL)); + m_surface = eglCheck(eglCreateWindowSurface(m_display, m_config, window, nullptr)); } diff --git a/src/SFML/Window/EglContext.hpp b/src/SFML/Window/EglContext.hpp index f38e018a..b6796d91 100644 --- a/src/SFML/Window/EglContext.hpp +++ b/src/SFML/Window/EglContext.hpp @@ -46,7 +46,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Create a new context, not associated to a window /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// //////////////////////////////////////////////////////////// EglContext(EglContext* shared); @@ -112,7 +112,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Create the context /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// \param bitsPerPixel Pixel depth, in bits per pixel /// \param settings Creation parameters /// diff --git a/src/SFML/Window/FreeBSD/JoystickImpl.cpp b/src/SFML/Window/FreeBSD/JoystickImpl.cpp index 8758b904..dd8c659d 100644 --- a/src/SFML/Window/FreeBSD/JoystickImpl.cpp +++ b/src/SFML/Window/FreeBSD/JoystickImpl.cpp @@ -163,7 +163,7 @@ namespace priv //////////////////////////////////////////////////////////// void JoystickImpl::initialize() { - hid_init(NULL); + hid_init(nullptr); // Do an initial scan updatePluggedList(); diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index e4695be1..514ad865 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -246,7 +246,7 @@ void GlContext::initResource() else { // Try to load the >= 3.0 way - glGetStringiFuncType glGetStringiFunc = NULL; + glGetStringiFuncType glGetStringiFunc = nullptr; glGetStringiFunc = reinterpret_cast(getFunction("glGetStringi")); if (glGetStringiFunc) @@ -332,7 +332,7 @@ void GlContext::releaseTransientContext() std::unique_ptr GlContext::create() { // Make sure that there's an active context (context creation may need extensions, and thus a valid context) - assert(sharedContext != NULL); + assert(sharedContext != nullptr); std::lock_guard lock(mutex); @@ -360,7 +360,7 @@ std::unique_ptr GlContext::create() std::unique_ptr GlContext::create(const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel) { // Make sure that there's an active context (context creation may need extensions, and thus a valid context) - assert(sharedContext != NULL); + assert(sharedContext != nullptr); std::lock_guard lock(mutex); @@ -389,7 +389,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, co std::unique_ptr GlContext::create(const ContextSettings& settings, unsigned int width, unsigned int height) { // Make sure that there's an active context (context creation may need extensions, and thus a valid context) - assert(sharedContext != NULL); + assert(sharedContext != nullptr); std::lock_guard lock(mutex); @@ -445,7 +445,7 @@ GlContext::~GlContext() if (sharedContext) { if (this == currentContext) - currentContext = NULL; + currentContext = nullptr; } } @@ -493,7 +493,7 @@ bool GlContext::setActive(bool active) // Deactivate the context if (makeCurrent(false)) { - currentContext = NULL; + currentContext = nullptr; return true; } else diff --git a/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm b/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm index 9f832c7d..51fd49c6 100644 --- a/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm +++ b/src/SFML/Window/OSX/AutoreleasePoolWrapper.mm @@ -85,7 +85,7 @@ static void createNewPool(void) void ensureThreadHasPool(void) { pthread_once(&initOnceToken, createPoolKey); - if (pthread_getspecific(poolKey) == NULL) + if (pthread_getspecific(poolKey) == nullptr) { createNewPool(); } @@ -96,7 +96,7 @@ void ensureThreadHasPool(void) void drainThreadPool(void) { void* data = pthread_getspecific(poolKey); - assert(data != NULL); + assert(data != nullptr); // Drain the pool but keep it alive by creating a new one destroyPool(data); diff --git a/src/SFML/Window/OSX/HIDInputManager.hpp b/src/SFML/Window/OSX/HIDInputManager.hpp index 819039a7..1b80ad2b 100644 --- a/src/SFML/Window/OSX/HIDInputManager.hpp +++ b/src/SFML/Window/OSX/HIDInputManager.hpp @@ -178,7 +178,7 @@ private: /// /// \param page HID page like kHIDPage_GenericDesktop /// \param usage HID usage page like kHIDUsage_GD_Keyboard or kHIDUsage_GD_Mouse - /// \return a retained CFSetRef of IOHIDDeviceRef or NULL + /// \return a retained CFSetRef of IOHIDDeviceRef or nullptr /// //////////////////////////////////////////////////////////// CFSetRef copyDevices(UInt32 page, UInt32 usage); diff --git a/src/SFML/Window/OSX/HIDInputManager.mm b/src/SFML/Window/OSX/HIDInputManager.mm index c74200ce..d4bf5101 100644 --- a/src/SFML/Window/OSX/HIDInputManager.mm +++ b/src/SFML/Window/OSX/HIDInputManager.mm @@ -150,7 +150,7 @@ void HIDInputManager::initializeKeyboard() // Get only keyboards CFSetRef keyboards = copyDevices(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard); - if (keyboards == NULL) + if (keyboards == nullptr) { freeUp(); return; @@ -180,9 +180,9 @@ void HIDInputManager::initializeKeyboard() void HIDInputManager::loadKeyboard(IOHIDDeviceRef keyboard) { CFArrayRef keys = IOHIDDeviceCopyMatchingElements(keyboard, - NULL, + nullptr, kIOHIDOptionsTypeNone); - if (keys == NULL) + if (keys == nullptr) { sf::err() << "We got a keyboard without any keys (1)" << std::endl; return; @@ -339,15 +339,15 @@ CFSetRef HIDInputManager::copyDevices(UInt32 page, UInt32 usage) mask = 0; CFSetRef devices = IOHIDManagerCopyDevices(m_manager); - if (devices == NULL) - return NULL; + if (devices == nullptr) + return nullptr; // Is there at least one device? CFIndex deviceCount = CFSetGetCount(devices); if (deviceCount < 1) { CFRelease(devices); - return NULL; + return nullptr; } return devices; diff --git a/src/SFML/Window/OSX/HIDJoystickManager.cpp b/src/SFML/Window/OSX/HIDJoystickManager.cpp index 64416809..4660d3ec 100644 --- a/src/SFML/Window/OSX/HIDJoystickManager.cpp +++ b/src/SFML/Window/OSX/HIDJoystickManager.cpp @@ -85,7 +85,7 @@ m_joystickCount(0) maskArray[0] = mask0; maskArray[1] = mask1; - CFArrayRef mask = CFArrayCreate(NULL, (const void**)maskArray, 2, NULL); + CFArrayRef mask = CFArrayCreate(nullptr, (const void**)maskArray, 2, nullptr); IOHIDManagerSetDeviceMatchingMultiple(m_manager, mask); CFRelease(mask); @@ -111,8 +111,8 @@ HIDJoystickManager::~HIDJoystickManager() CFRunLoopGetCurrent(), RunLoopMode); - IOHIDManagerRegisterDeviceMatchingCallback(m_manager, NULL, 0); - IOHIDManagerRegisterDeviceRemovalCallback(m_manager, NULL, 0); + IOHIDManagerRegisterDeviceMatchingCallback(m_manager, nullptr, 0); + IOHIDManagerRegisterDeviceRemovalCallback(m_manager, nullptr, 0); IOHIDManagerClose(m_manager, kIOHIDOptionsTypeNone); } diff --git a/src/SFML/Window/OSX/HIDJoystickManager.hpp b/src/SFML/Window/OSX/HIDJoystickManager.hpp index 6052d38d..5df27701 100644 --- a/src/SFML/Window/OSX/HIDJoystickManager.hpp +++ b/src/SFML/Window/OSX/HIDJoystickManager.hpp @@ -69,7 +69,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Copy the devices associated with this HID manager /// - /// \return a retained CFSetRef of IOHIDDeviceRef or NULL + /// \return a retained CFSetRef of IOHIDDeviceRef or nullptr /// //////////////////////////////////////////////////////////// CFSetRef copyJoysticks(); diff --git a/src/SFML/Window/OSX/InputImpl.mm b/src/SFML/Window/OSX/InputImpl.mm index cf41b032..24f2aaf2 100644 --- a/src/SFML/Window/OSX/InputImpl.mm +++ b/src/SFML/Window/OSX/InputImpl.mm @@ -182,7 +182,7 @@ void InputImpl::setMousePosition(const Vector2i& position) CGPoint pos = CGPointMake(position.x / scale, position.y / scale); // Place the cursor. - CGEventRef event = CGEventCreateMouseEvent(NULL, + CGEventRef event = CGEventCreateMouseEvent(nullptr, kCGEventMouseMoved, pos, /* we don't care about this: */ kCGMouseButtonLeft); diff --git a/src/SFML/Window/OSX/JoystickImpl.cpp b/src/SFML/Window/OSX/JoystickImpl.cpp index 117caa6f..5740cd7a 100644 --- a/src/SFML/Window/OSX/JoystickImpl.cpp +++ b/src/SFML/Window/OSX/JoystickImpl.cpp @@ -136,7 +136,7 @@ bool JoystickImpl::isConnected(unsigned int index) // Get all devices CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks(); - if (devices != NULL) + if (devices != nullptr) { CFIndex size = CFSetGetCount(devices); if (size > 0) @@ -189,7 +189,7 @@ bool JoystickImpl::open(unsigned int index) // Get all devices CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks(); - if (devices == NULL) + if (devices == nullptr) return false; // Get a usable copy of the joysticks devices. @@ -221,9 +221,9 @@ bool JoystickImpl::open(unsigned int index) m_identification.productId = getDeviceUint(self, CFSTR(kIOHIDProductIDKey), m_index); // Get a list of all elements attached to the device. - CFArrayRef elements = IOHIDDeviceCopyMatchingElements(self, NULL, kIOHIDOptionsTypeNone); + CFArrayRef elements = IOHIDDeviceCopyMatchingElements(self, nullptr, kIOHIDOptionsTypeNone); - if (elements == NULL) + if (elements == nullptr) { CFRelease(devices); return false; @@ -350,7 +350,7 @@ JoystickState JoystickImpl::update() // Get all devices CFSetRef devices = HIDJoystickManager::getInstance().copyJoysticks(); - if (devices == NULL) + if (devices == nullptr) return disconnectedState; // Get a usable copy of the joysticks devices. diff --git a/src/SFML/Window/OSX/SFContext.hpp b/src/SFML/Window/OSX/SFContext.hpp index 2a1e70d4..10787b2e 100644 --- a/src/SFML/Window/OSX/SFContext.hpp +++ b/src/SFML/Window/OSX/SFContext.hpp @@ -68,7 +68,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Create a new context, not associated to a window /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// //////////////////////////////////////////////////////////// SFContext(SFContext* shared); @@ -149,7 +149,7 @@ private: /// \brief Create the context /// \note Must only be called from Ctor. /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// \param bitsPerPixel bpp /// \param settings Creation parameters /// diff --git a/src/SFML/Window/OSX/SFContext.mm b/src/SFML/Window/OSX/SFContext.mm index 88d17551..c5f541ce 100644 --- a/src/SFML/Window/OSX/SFContext.mm +++ b/src/SFML/Window/OSX/SFContext.mm @@ -118,7 +118,7 @@ SFContext::~SFContext() //////////////////////////////////////////////////////////// GlFunctionPointer SFContext::getFunction(const char* name) { - static void* image = NULL; + static void* image = nullptr; if (!image) image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY); @@ -267,7 +267,7 @@ void SFContext::createContext(SFContext* shared, } // Use the shared context if one is given. - NSOpenGLContext* sharedContext = shared != NULL ? shared->m_context : nil; + NSOpenGLContext* sharedContext = shared != nullptr ? shared->m_context : nil; if (sharedContext != nil) { diff --git a/src/SFML/Window/OSX/VideoModeImpl.cpp b/src/SFML/Window/OSX/VideoModeImpl.cpp index ae5fdfb9..5de6f372 100644 --- a/src/SFML/Window/OSX/VideoModeImpl.cpp +++ b/src/SFML/Window/OSX/VideoModeImpl.cpp @@ -42,9 +42,9 @@ std::vector VideoModeImpl::getFullscreenModes() std::vector modes; // Retrieve all modes available for main screen only. - CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL); + CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), nullptr); - if (cgmodes == NULL) + if (cgmodes == nullptr) { sf::err() << "Couldn't get VideoMode for main display." << std::endl; return modes; diff --git a/src/SFML/Window/Unix/Display.cpp b/src/SFML/Window/Unix/Display.cpp index 5d6a3142..97b59292 100644 --- a/src/SFML/Window/Unix/Display.cpp +++ b/src/SFML/Window/Unix/Display.cpp @@ -37,7 +37,7 @@ namespace { // The shared display and its reference counter - Display* sharedDisplay = NULL; + Display* sharedDisplay = nullptr; unsigned int referenceCount = 0; std::mutex mutex; @@ -56,7 +56,7 @@ Display* OpenDisplay() if (referenceCount == 0) { - sharedDisplay = XOpenDisplay(NULL); + sharedDisplay = XOpenDisplay(nullptr); // Opening display failed: The best we can do at the moment is to output a meaningful error message // and cause an abnormal program termination diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index a557ba1f..2655142f 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -95,9 +95,9 @@ void ensureExtensionsInit(::Display* display, int screen) //////////////////////////////////////////////////////////// GlxContext::GlxContext(GlxContext* shared) : -m_display (NULL), +m_display (nullptr), m_window (0), -m_context (NULL), +m_context (nullptr), m_pbuffer (0), m_ownsWindow(false) { @@ -120,9 +120,9 @@ m_ownsWindow(false) //////////////////////////////////////////////////////////// GlxContext::GlxContext(GlxContext* shared, const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel) : -m_display (NULL), +m_display (nullptr), m_window (0), -m_context (NULL), +m_context (nullptr), m_pbuffer (0), m_ownsWindow(false) { @@ -145,9 +145,9 @@ m_ownsWindow(false) //////////////////////////////////////////////////////////// GlxContext::GlxContext(GlxContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height) : -m_display (NULL), +m_display (nullptr), m_window (0), -m_context (NULL), +m_context (nullptr), m_pbuffer (0), m_ownsWindow(false) { @@ -179,7 +179,7 @@ GlxContext::~GlxContext() #endif if (glXGetCurrentContext() == m_context) - glXMakeCurrent(m_display, None, NULL); + glXMakeCurrent(m_display, None, nullptr); glXDestroyContext(m_display, m_context); #if defined(GLX_DEBUGGING) @@ -237,7 +237,7 @@ bool GlxContext::makeCurrent(bool current) } else { - result = glXMakeCurrent(m_display, None, NULL); + result = glXMakeCurrent(m_display, None, nullptr); } #if defined(GLX_DEBUGGING) @@ -314,7 +314,7 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe // Retrieve all the visuals int count; - XVisualInfo* visuals = XGetVisualInfo(display, 0, NULL, &count); + XVisualInfo* visuals = XGetVisualInfo(display, 0, nullptr, &count); if (visuals) { // Evaluate all the returned visuals, and pick the best one @@ -470,13 +470,13 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned if (hasCreatePbuffer) { // Get a GLXFBConfig that matches the visual - GLXFBConfig* config = NULL; + GLXFBConfig* config = nullptr; // We don't supply attributes to match against, since // the visual we are matching against was already // deemed suitable in selectBestVisual() int nbConfigs = 0; - GLXFBConfig* configs = glXChooseFBConfig(m_display, DefaultScreen(m_display), NULL, &nbConfigs); + GLXFBConfig* configs = glXChooseFBConfig(m_display, DefaultScreen(m_display), nullptr, &nbConfigs); for (int i = 0; configs && (i < nbConfigs); ++i) { @@ -558,7 +558,7 @@ void GlxContext::createContext(GlxContext* shared) // Get a working copy of the context settings ContextSettings settings = m_settings; - XVisualInfo* visualInfo = NULL; + XVisualInfo* visualInfo = nullptr; if (m_pbuffer) { @@ -606,7 +606,7 @@ void GlxContext::createContext(GlxContext* shared) } // Get the context to share display lists with - GLXContext toShare = shared ? shared->m_context : NULL; + GLXContext toShare = shared ? shared->m_context : nullptr; // There are no GLX versions prior to 1.0 int major = 0; @@ -622,13 +622,13 @@ void GlxContext::createContext(GlxContext* shared) if (hasCreateContextArb) { // Get a GLXFBConfig that matches the window's visual, for glXCreateContextAttribsARB - GLXFBConfig* config = NULL; + GLXFBConfig* config = nullptr; // We don't supply attributes to match against, since // the visual we are matching against was already // deemed suitable in selectBestVisual() int nbConfigs = 0; - GLXFBConfig* configs = glXChooseFBConfig(m_display, DefaultScreen(m_display), NULL, &nbConfigs); + GLXFBConfig* configs = glXChooseFBConfig(m_display, DefaultScreen(m_display), nullptr, &nbConfigs); for (int i = 0; configs && (i < nbConfigs); ++i) { @@ -693,7 +693,7 @@ void GlxContext::createContext(GlxContext* shared) if (toShare) { - if (!glXMakeCurrent(m_display, None, NULL)) + if (!glXMakeCurrent(m_display, None, nullptr)) { err() << "Failed to deactivate shared context before sharing" << std::endl; return; @@ -748,7 +748,7 @@ void GlxContext::createContext(GlxContext* shared) if (toShare) { - if (!glXMakeCurrent(m_display, None, NULL)) + if (!glXMakeCurrent(m_display, None, nullptr)) { err() << "Failed to deactivate shared context before sharing" << std::endl; return; diff --git a/src/SFML/Window/Unix/GlxContext.hpp b/src/SFML/Window/Unix/GlxContext.hpp index 304b0049..c0c41adb 100644 --- a/src/SFML/Window/Unix/GlxContext.hpp +++ b/src/SFML/Window/Unix/GlxContext.hpp @@ -48,7 +48,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Create a new default context /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// //////////////////////////////////////////////////////////// GlxContext(GlxContext* shared); @@ -151,7 +151,7 @@ private: //////////////////////////////////////////////////////////// /// \brief Create the context's drawing surface /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// \param width Back buffer width, in pixels /// \param height Back buffer height, in pixels /// \param bitsPerPixel Pixel depth, in bits per pixel @@ -170,7 +170,7 @@ private: //////////////////////////////////////////////////////////// /// \brief Create the context /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// //////////////////////////////////////////////////////////// void createContext(GlxContext* shared); diff --git a/src/SFML/Window/Unix/GlxExtensions.cpp b/src/SFML/Window/Unix/GlxExtensions.cpp index 4d9d9781..e667b696 100644 --- a/src/SFML/Window/Unix/GlxExtensions.cpp +++ b/src/SFML/Window/Unix/GlxExtensions.cpp @@ -47,7 +47,7 @@ int sfglx_ext_SGIX_pbuffer = sfglx_LOAD_FAILED; int sfglx_ext_ARB_create_context = sfglx_LOAD_FAILED; int sfglx_ext_ARB_create_context_profile = sfglx_LOAD_FAILED; -void (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalEXT)(Display*, GLXDrawable, int) = NULL; +void (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalEXT)(Display*, GLXDrawable, int) = nullptr; static int Load_EXT_swap_control(void) { @@ -58,7 +58,7 @@ static int Load_EXT_swap_control(void) return numFailed; } -int (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalMESA)(int) = NULL; +int (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalMESA)(int) = nullptr; static int Load_MESA_swap_control(void) { @@ -69,7 +69,7 @@ static int Load_MESA_swap_control(void) return numFailed; } -int (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalSGI)(int) = NULL; +int (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalSGI)(int) = nullptr; static int Load_SGI_swap_control(void) { @@ -80,11 +80,11 @@ static int Load_SGI_swap_control(void) return numFailed; } -GLXPbufferSGIX (CODEGEN_FUNCPTR *sf_ptrc_glXCreateGLXPbufferSGIX)(Display*, GLXFBConfigSGIX, unsigned int, unsigned int, int*) = NULL; -void (CODEGEN_FUNCPTR *sf_ptrc_glXDestroyGLXPbufferSGIX)(Display*, GLXPbufferSGIX) = NULL; -void (CODEGEN_FUNCPTR *sf_ptrc_glXGetSelectedEventSGIX)(Display*, GLXDrawable, unsigned long*) = NULL; -int (CODEGEN_FUNCPTR *sf_ptrc_glXQueryGLXPbufferSGIX)(Display*, GLXPbufferSGIX, int, unsigned int*) = NULL; -void (CODEGEN_FUNCPTR *sf_ptrc_glXSelectEventSGIX)(Display*, GLXDrawable, unsigned long) = NULL; +GLXPbufferSGIX (CODEGEN_FUNCPTR *sf_ptrc_glXCreateGLXPbufferSGIX)(Display*, GLXFBConfigSGIX, unsigned int, unsigned int, int*) = nullptr; +void (CODEGEN_FUNCPTR *sf_ptrc_glXDestroyGLXPbufferSGIX)(Display*, GLXPbufferSGIX) = nullptr; +void (CODEGEN_FUNCPTR *sf_ptrc_glXGetSelectedEventSGIX)(Display*, GLXDrawable, unsigned long*) = nullptr; +int (CODEGEN_FUNCPTR *sf_ptrc_glXQueryGLXPbufferSGIX)(Display*, GLXPbufferSGIX, int, unsigned int*) = nullptr; +void (CODEGEN_FUNCPTR *sf_ptrc_glXSelectEventSGIX)(Display*, GLXDrawable, unsigned long) = nullptr; static int Load_SGIX_pbuffer(void) { @@ -107,7 +107,7 @@ static int Load_SGIX_pbuffer(void) return numFailed; } -GLXContext (CODEGEN_FUNCPTR *sf_ptrc_glXCreateContextAttribsARB)(Display*, GLXFBConfig, GLXContext, Bool, const int*) = NULL; +GLXContext (CODEGEN_FUNCPTR *sf_ptrc_glXCreateContextAttribsARB)(Display*, GLXFBConfig, GLXContext, Bool, const int*) = nullptr; static int Load_ARB_create_context(void) { @@ -130,12 +130,12 @@ static sfglx_StrToExtMap ExtensionMap[9] = { {"GLX_EXT_swap_control", &sfglx_ext_EXT_swap_control, Load_EXT_swap_control}, {"GLX_MESA_swap_control", &sfglx_ext_MESA_swap_control, Load_MESA_swap_control}, {"GLX_SGI_swap_control", &sfglx_ext_SGI_swap_control, Load_SGI_swap_control}, - {"GLX_EXT_framebuffer_sRGB", &sfglx_ext_EXT_framebuffer_sRGB, NULL}, - {"GLX_ARB_framebuffer_sRGB", &sfglx_ext_ARB_framebuffer_sRGB, NULL}, - {"GLX_ARB_multisample", &sfglx_ext_ARB_multisample, NULL}, + {"GLX_EXT_framebuffer_sRGB", &sfglx_ext_EXT_framebuffer_sRGB, nullptr}, + {"GLX_ARB_framebuffer_sRGB", &sfglx_ext_ARB_framebuffer_sRGB, nullptr}, + {"GLX_ARB_multisample", &sfglx_ext_ARB_multisample, nullptr}, {"GLX_SGIX_pbuffer", &sfglx_ext_SGIX_pbuffer, Load_SGIX_pbuffer}, {"GLX_ARB_create_context", &sfglx_ext_ARB_create_context, Load_ARB_create_context}, - {"GLX_ARB_create_context_profile", &sfglx_ext_ARB_create_context_profile, NULL} + {"GLX_ARB_create_context_profile", &sfglx_ext_ARB_create_context_profile, nullptr} }; static int g_extensionMapSize = 9; @@ -150,7 +150,7 @@ static sfglx_StrToExtMap* FindExtEntry(const char* extensionName) return currLoc; } - return NULL; + return nullptr; } @@ -170,7 +170,7 @@ static void ClearExtensionVars(void) static void LoadExtByName(const char* extensionName) { - sfglx_StrToExtMap* entry = NULL; + sfglx_StrToExtMap* entry = nullptr; entry = FindExtEntry(extensionName); if (entry) { diff --git a/src/SFML/Window/Unix/JoystickImpl.cpp b/src/SFML/Window/Unix/JoystickImpl.cpp index 2898c6ca..7ca0de03 100644 --- a/src/SFML/Window/Unix/JoystickImpl.cpp +++ b/src/SFML/Window/Unix/JoystickImpl.cpp @@ -112,7 +112,7 @@ namespace return true; } - void updatePluggedList(udev_device* udevDevice = NULL) + void updatePluggedList(udev_device* udevDevice = nullptr) { if (udevDevice) { @@ -258,7 +258,7 @@ namespace FD_SET(monitorFd, &descriptorSet); timeval timeout = {0, 0}; - return (select(monitorFd + 1, &descriptorSet, NULL, NULL, &timeout) > 0) && + return (select(monitorFd + 1, &descriptorSet, nullptr, nullptr, &timeout) > 0) && FD_ISSET(monitorFd, &descriptorSet); } @@ -274,7 +274,7 @@ namespace udev_device* udevDeviceParent = udev_device_get_parent_with_subsystem_devtype(udevDevice, "usb", "usb_device"); if (!udevDeviceParent) - return NULL; + return nullptr; return udev_device_get_sysattr_value(udevDeviceParent, attributeName.c_str()); } @@ -289,7 +289,7 @@ namespace unsigned int value = 0; if (attribute) - value = static_cast(std::strtoul(attribute, NULL, 16)); + value = static_cast(std::strtoul(attribute, nullptr, 16)); return value; } @@ -304,7 +304,7 @@ namespace unsigned int value = 0; if (attribute) - value = static_cast(std::strtoul(attribute, NULL, 16)); + value = static_cast(std::strtoul(attribute, nullptr, 16)); return value; } @@ -466,7 +466,7 @@ void JoystickImpl::initialize() } else { - int error = udev_monitor_filter_add_match_subsystem_devtype(udevMonitor, "input", NULL); + int error = udev_monitor_filter_add_match_subsystem_devtype(udevMonitor, "input", nullptr); if (error < 0) { @@ -528,7 +528,7 @@ bool JoystickImpl::isConnected(unsigned int index) udev_device* udevDevice = udev_monitor_receive_device(udevMonitor); // If we can get the specific device, we check that, - // otherwise just do a full scan if udevDevice == NULL + // otherwise just do a full scan if udevDevice == nullptr updatePluggedList(udevDevice); if (udevDevice) diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index af8ccbb5..7553aa41 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -61,7 +61,7 @@ //////////////////////////////////////////////////////////// namespace { - sf::priv::WindowImplX11* fullscreenWindow = NULL; + sf::priv::WindowImplX11* fullscreenWindow = nullptr; std::vector allWindows; std::mutex allWindowsMutex; sf::String windowManagerName; @@ -381,8 +381,8 @@ namespace priv WindowImplX11::WindowImplX11(WindowHandle handle) : m_window (0), m_screen (0), -m_inputMethod (NULL), -m_inputContext (NULL), +m_inputMethod (nullptr), +m_inputContext (nullptr), m_isExternal (true), m_oldVideoMode (0), m_hiddenCursor (0), @@ -428,8 +428,8 @@ m_lastInputTime (0) WindowImplX11::WindowImplX11(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings) : m_window (0), m_screen (0), -m_inputMethod (NULL), -m_inputContext (NULL), +m_inputMethod (nullptr), +m_inputContext (nullptr), m_isExternal (false), m_oldVideoMode (0), m_hiddenCursor (0), @@ -749,21 +749,21 @@ void WindowImplX11::setTitle(const String& title) m_window, title.toAnsiString().c_str(), title.toAnsiString().c_str(), - NULL, + nullptr, 0, - NULL, - NULL, - NULL); + nullptr, + nullptr, + nullptr); #else XmbSetWMProperties(m_display, m_window, title.toAnsiString().c_str(), title.toAnsiString().c_str(), - NULL, + nullptr, 0, - NULL, - NULL, - NULL); + nullptr, + nullptr, + nullptr); #endif } @@ -982,7 +982,7 @@ void WindowImplX11::requestFocus() // Otherwise: display urgency hint (flashing application logo) // Ensure WM hints exist, allocate if necessary XWMHints* hints = XGetWMHints(m_display, m_window); - if (hints == NULL) + if (hints == nullptr) hints = XAllocWMHints(); // Add urgency (notification) flag to hints @@ -1132,7 +1132,7 @@ void WindowImplX11::resetVideoMode() } // Reset the fullscreen window - fullscreenWindow = NULL; + fullscreenWindow = nullptr; } } @@ -1263,7 +1263,7 @@ void WindowImplX11::setProtocols() void WindowImplX11::initialize() { // Create the input context - m_inputMethod = XOpenIM(m_display, NULL, NULL, NULL); + m_inputMethod = XOpenIM(m_display, nullptr, nullptr, nullptr); if (m_inputMethod) { @@ -1274,11 +1274,11 @@ void WindowImplX11::initialize() m_window, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - NULL); + nullptr); } else { - m_inputContext = NULL; + m_inputContext = nullptr; } if (!m_inputContext) @@ -1346,7 +1346,7 @@ void WindowImplX11::createHiddenCursor() { // Create the cursor's pixmap (1x1 pixels) Pixmap cursorPixmap = XCreatePixmap(m_display, m_window, 1, 1, 1); - GC graphicsContext = XCreateGC(m_display, cursorPixmap, 0, NULL); + GC graphicsContext = XCreateGC(m_display, cursorPixmap, 0, nullptr); XDrawPoint(m_display, cursorPixmap, graphicsContext, 0, 0); XFreeGC(m_display, graphicsContext); @@ -1456,7 +1456,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // If the window has been previously marked urgent (notification) as a result of a focus request, undo that XWMHints* hints = XGetWMHints(m_display, m_window); - if (hints != NULL) + if (hints != nullptr) { // Remove urgency (notification) flag from hints hints->flags &= ~XUrgencyHint; @@ -1571,7 +1571,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) &windowEvent.xkey, reinterpret_cast(keyBuffer), sizeof(keyBuffer), - NULL, + nullptr, &status ); @@ -1593,7 +1593,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) { static XComposeStatus status; char keyBuffer[16]; - if (XLookupString(&windowEvent.xkey, keyBuffer, sizeof(keyBuffer), NULL, &status)) + if (XLookupString(&windowEvent.xkey, keyBuffer, sizeof(keyBuffer), nullptr, &status)) { Event textEvent; textEvent.type = Event::TextEntered; diff --git a/src/SFML/Window/Win32/JoystickImpl.cpp b/src/SFML/Window/Win32/JoystickImpl.cpp index c6defc6f..820e1cee 100644 --- a/src/SFML/Window/Win32/JoystickImpl.cpp +++ b/src/SFML/Window/Win32/JoystickImpl.cpp @@ -56,7 +56,7 @@ namespace { PTCHAR buffer; - if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, reinterpret_cast(&buffer), 0, NULL) == 0) + if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr, error, 0, reinterpret_cast(&buffer), 0, nullptr) == 0) return "Unknown error."; sf::String message = buffer; @@ -106,7 +106,7 @@ namespace TCHAR keyData[256]; DWORD keyDataSize = sizeof(keyData); - result = RegQueryValueEx(currentKey, subkey.c_str(), NULL, NULL, reinterpret_cast(keyData), &keyDataSize); + result = RegQueryValueEx(currentKey, subkey.c_str(), nullptr, nullptr, reinterpret_cast(keyData), &keyDataSize); RegCloseKey(currentKey); if (result != ERROR_SUCCESS) @@ -129,7 +129,7 @@ namespace keyDataSize = sizeof(keyData); - result = RegQueryValueEx(currentKey, REGSTR_VAL_JOYOEMNAME, NULL, NULL, reinterpret_cast(keyData), &keyDataSize); + result = RegQueryValueEx(currentKey, REGSTR_VAL_JOYOEMNAME, nullptr, nullptr, reinterpret_cast(keyData), &keyDataSize); RegCloseKey(currentKey); if (result != ERROR_SUCCESS) diff --git a/src/SFML/Window/Win32/VideoModeImpl.cpp b/src/SFML/Window/Win32/VideoModeImpl.cpp index 87839316..d04f4c27 100644 --- a/src/SFML/Window/Win32/VideoModeImpl.cpp +++ b/src/SFML/Window/Win32/VideoModeImpl.cpp @@ -42,7 +42,7 @@ std::vector VideoModeImpl::getFullscreenModes() // Enumerate all available video modes for the primary display adapter DEVMODE win32Mode; win32Mode.dmSize = sizeof(win32Mode); - for (int count = 0; EnumDisplaySettings(NULL, count, &win32Mode); ++count) + for (int count = 0; EnumDisplaySettings(nullptr, count, &win32Mode); ++count) { // Convert to sf::VideoMode VideoMode mode(win32Mode.dmPelsWidth, win32Mode.dmPelsHeight, win32Mode.dmBitsPerPel); @@ -61,7 +61,7 @@ VideoMode VideoModeImpl::getDesktopMode() { DEVMODE win32Mode; win32Mode.dmSize = sizeof(win32Mode); - EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &win32Mode); + EnumDisplaySettings(nullptr, ENUM_CURRENT_SETTINGS, &win32Mode); return VideoMode(win32Mode.dmPelsWidth, win32Mode.dmPelsHeight, win32Mode.dmBitsPerPel); } diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index 198f7ef2..862bc753 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -64,7 +64,7 @@ String getErrorString(DWORD errorCode) { std::basic_ostringstream > ss; TCHAR errBuff[256]; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorCode, 0, errBuff, sizeof(errBuff), NULL); + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, errorCode, 0, errBuff, sizeof(errBuff), nullptr); ss << errBuff; String errMsg(ss.str()); @@ -74,10 +74,10 @@ String getErrorString(DWORD errorCode) //////////////////////////////////////////////////////////// WglContext::WglContext(WglContext* shared) : -m_window (NULL), -m_pbuffer (NULL), -m_deviceContext(NULL), -m_context (NULL), +m_window (nullptr), +m_pbuffer (nullptr), +m_deviceContext(nullptr), +m_context (nullptr), m_ownsWindow (false) { // Save the creation settings @@ -99,10 +99,10 @@ m_ownsWindow (false) //////////////////////////////////////////////////////////// WglContext::WglContext(WglContext* shared, const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel) : -m_window (NULL), -m_pbuffer (NULL), -m_deviceContext(NULL), -m_context (NULL), +m_window (nullptr), +m_pbuffer (nullptr), +m_deviceContext(nullptr), +m_context (nullptr), m_ownsWindow (false) { // Save the creation settings @@ -124,10 +124,10 @@ m_ownsWindow (false) //////////////////////////////////////////////////////////// WglContext::WglContext(WglContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height) : -m_window (NULL), -m_pbuffer (NULL), -m_deviceContext(NULL), -m_context (NULL), +m_window (nullptr), +m_pbuffer (nullptr), +m_deviceContext(nullptr), +m_context (nullptr), m_ownsWindow (false) { // Save the creation settings @@ -155,8 +155,8 @@ WglContext::~WglContext() { if (currentContext == this) { - if (wglMakeCurrent(m_deviceContext, NULL) == TRUE) - currentContext = NULL; + if (wglMakeCurrent(m_deviceContext, nullptr) == TRUE) + currentContext = nullptr; } wglDeleteContext(m_context); @@ -215,13 +215,13 @@ bool WglContext::makeCurrent(bool current) if (!m_deviceContext || !m_context) return false; - if (wglMakeCurrent(m_deviceContext, current ? m_context : NULL) == FALSE) + if (wglMakeCurrent(m_deviceContext, current ? m_context : nullptr) == FALSE) { err() << "Failed to " << (current ? "activate" : "deactivate") << " OpenGL context: " << getErrorString(GetLastError()).toAnsiString() << std::endl; return false; } - currentContext = (current ? this : NULL); + currentContext = (current ? this : nullptr); return true; } @@ -278,7 +278,7 @@ int WglContext::selectBestPixelFormat(HDC deviceContext, unsigned int bitsPerPix // Let's check how many formats are supporting our requirements int formats[512]; UINT nbFormats; - bool isValid = wglChoosePixelFormatARB(deviceContext, intAttributes, NULL, 512, formats, &nbFormats) != FALSE; + bool isValid = wglChoosePixelFormatARB(deviceContext, intAttributes, nullptr, 512, formats, &nbFormats) != FALSE; if (!isValid) err() << "Failed to enumerate pixel formats: " << getErrorString(GetLastError()).toAnsiString() << std::endl; @@ -536,7 +536,7 @@ void WglContext::createSurface(WglContext* shared, unsigned int width, unsigned err() << "Failed to retrieve pixel buffer device context: " << getErrorString(GetLastError()).toAnsiString() << std::endl; wglDestroyPbufferARB(m_pbuffer); - m_pbuffer = NULL; + m_pbuffer = nullptr; } } else @@ -553,7 +553,7 @@ void WglContext::createSurface(WglContext* shared, unsigned int width, unsigned // with other contexts and thus wglShareLists would always fail // Create the hidden window - m_window = CreateWindowA("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, width, height, NULL, NULL, GetModuleHandle(NULL), NULL); + m_window = CreateWindowA("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, width, height, nullptr, nullptr, GetModuleHandle(nullptr), nullptr); ShowWindow(m_window, SW_HIDE); m_deviceContext = GetDC(m_window); @@ -589,7 +589,7 @@ void WglContext::createContext(WglContext* shared) ContextSettings settings = m_settings; // Get the context to share display lists with - HGLRC sharedContext = shared ? shared->m_context : NULL; + HGLRC sharedContext = shared ? shared->m_context : nullptr; // Create the OpenGL context -- first try using wglCreateContextAttribsARB while (!m_context && m_settings.majorVersion) @@ -638,13 +638,13 @@ void WglContext::createContext(WglContext* shared) if (currentContext == shared) { - if (wglMakeCurrent(shared->m_deviceContext, NULL) == FALSE) + if (wglMakeCurrent(shared->m_deviceContext, nullptr) == FALSE) { err() << "Failed to deactivate shared context before sharing: " << getErrorString(GetLastError()).toAnsiString() << std::endl; return; } - currentContext = NULL; + currentContext = nullptr; } } @@ -708,13 +708,13 @@ void WglContext::createContext(WglContext* shared) if (currentContext == shared) { - if (wglMakeCurrent(shared->m_deviceContext, NULL) == FALSE) + if (wglMakeCurrent(shared->m_deviceContext, nullptr) == FALSE) { err() << "Failed to deactivate shared context before sharing: " << getErrorString(GetLastError()).toAnsiString() << std::endl; return; } - currentContext = NULL; + currentContext = nullptr; } if (wglShareLists(sharedContext, m_context) == FALSE) diff --git a/src/SFML/Window/Win32/WglContext.hpp b/src/SFML/Window/Win32/WglContext.hpp index d3a284df..36450a24 100644 --- a/src/SFML/Window/Win32/WglContext.hpp +++ b/src/SFML/Window/Win32/WglContext.hpp @@ -47,7 +47,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Create a new default context /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// //////////////////////////////////////////////////////////// WglContext(WglContext* shared); @@ -151,7 +151,7 @@ private: //////////////////////////////////////////////////////////// /// \brief Create the context's drawing surface /// - /// \param shared Shared context (can be NULL) + /// \param shared Shared context (can be nullptr) /// \param width Back buffer width, in pixels /// \param height Back buffer height, in pixels /// \param bitsPerPixel Pixel depth, in bits per pixel @@ -171,7 +171,7 @@ private: //////////////////////////////////////////////////////////// /// \brief Create the context /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// //////////////////////////////////////////////////////////// void createContext(WglContext* shared); diff --git a/src/SFML/Window/Win32/WglExtensions.cpp b/src/SFML/Window/Win32/WglExtensions.cpp index 3c037ab7..08bfa54c 100644 --- a/src/SFML/Window/Win32/WglExtensions.cpp +++ b/src/SFML/Window/Win32/WglExtensions.cpp @@ -46,8 +46,8 @@ int sfwgl_ext_ARB_pbuffer = sfwgl_LOAD_FAILED; int sfwgl_ext_ARB_create_context = sfwgl_LOAD_FAILED; int sfwgl_ext_ARB_create_context_profile = sfwgl_LOAD_FAILED; -int (CODEGEN_FUNCPTR *sf_ptrc_wglGetSwapIntervalEXT)(void) = NULL; -BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglSwapIntervalEXT)(int) = NULL; +int (CODEGEN_FUNCPTR *sf_ptrc_wglGetSwapIntervalEXT)(void) = nullptr; +BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglSwapIntervalEXT)(int) = nullptr; static int Load_EXT_swap_control(void) { @@ -61,9 +61,9 @@ static int Load_EXT_swap_control(void) return numFailed; } -BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglChoosePixelFormatARB)(HDC, const int*, const FLOAT*, UINT, int*, UINT*) = NULL; -BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribfvARB)(HDC, int, int, UINT, const int*, FLOAT*) = NULL; -BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int*, int*) = NULL; +BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglChoosePixelFormatARB)(HDC, const int*, const FLOAT*, UINT, int*, UINT*) = nullptr; +BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribfvARB)(HDC, int, int, UINT, const int*, FLOAT*) = nullptr; +BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int*, int*) = nullptr; static int Load_ARB_pixel_format(void) { @@ -80,11 +80,11 @@ static int Load_ARB_pixel_format(void) return numFailed; } -HPBUFFERARB (CODEGEN_FUNCPTR *sf_ptrc_wglCreatePbufferARB)(HDC, int, int, int, const int*) = NULL; -BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglDestroyPbufferARB)(HPBUFFERARB) = NULL; -HDC (CODEGEN_FUNCPTR *sf_ptrc_wglGetPbufferDCARB)(HPBUFFERARB) = NULL; -BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglQueryPbufferARB)(HPBUFFERARB, int, int*) = NULL; -int (CODEGEN_FUNCPTR *sf_ptrc_wglReleasePbufferDCARB)(HPBUFFERARB, HDC) = NULL; +HPBUFFERARB (CODEGEN_FUNCPTR *sf_ptrc_wglCreatePbufferARB)(HDC, int, int, int, const int*) = nullptr; +BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglDestroyPbufferARB)(HPBUFFERARB) = nullptr; +HDC (CODEGEN_FUNCPTR *sf_ptrc_wglGetPbufferDCARB)(HPBUFFERARB) = nullptr; +BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglQueryPbufferARB)(HPBUFFERARB, int, int*) = nullptr; +int (CODEGEN_FUNCPTR *sf_ptrc_wglReleasePbufferDCARB)(HPBUFFERARB, HDC) = nullptr; static int Load_ARB_pbuffer() { @@ -107,7 +107,7 @@ static int Load_ARB_pbuffer() return numFailed; } -HGLRC (CODEGEN_FUNCPTR *sf_ptrc_wglCreateContextAttribsARB)(HDC, HGLRC, const int*) = NULL; +HGLRC (CODEGEN_FUNCPTR *sf_ptrc_wglCreateContextAttribsARB)(HDC, HGLRC, const int*) = nullptr; static int Load_ARB_create_context(void) { @@ -119,7 +119,7 @@ static int Load_ARB_create_context(void) } -static const char* (CODEGEN_FUNCPTR *sf_ptrc_wglGetExtensionsStringARB)(HDC) = NULL; +static const char* (CODEGEN_FUNCPTR *sf_ptrc_wglGetExtensionsStringARB)(HDC) = nullptr; typedef int (*PFN_LOADFUNCPOINTERS)(void); typedef struct sfwgl_StrToExtMap_s @@ -131,13 +131,13 @@ typedef struct sfwgl_StrToExtMap_s static sfwgl_StrToExtMap ExtensionMap[8] = { {"WGL_EXT_swap_control", &sfwgl_ext_EXT_swap_control, Load_EXT_swap_control}, - {"WGL_EXT_framebuffer_sRGB", &sfwgl_ext_EXT_framebuffer_sRGB, NULL}, - {"WGL_ARB_framebuffer_sRGB", &sfwgl_ext_ARB_framebuffer_sRGB, NULL}, - {"WGL_ARB_multisample", &sfwgl_ext_ARB_multisample, NULL}, + {"WGL_EXT_framebuffer_sRGB", &sfwgl_ext_EXT_framebuffer_sRGB, nullptr}, + {"WGL_ARB_framebuffer_sRGB", &sfwgl_ext_ARB_framebuffer_sRGB, nullptr}, + {"WGL_ARB_multisample", &sfwgl_ext_ARB_multisample, nullptr}, {"WGL_ARB_pixel_format", &sfwgl_ext_ARB_pixel_format, Load_ARB_pixel_format}, {"WGL_ARB_pbuffer", &sfwgl_ext_ARB_pbuffer, Load_ARB_pbuffer}, {"WGL_ARB_create_context", &sfwgl_ext_ARB_create_context, Load_ARB_create_context}, - {"WGL_ARB_create_context_profile", &sfwgl_ext_ARB_create_context_profile, NULL} + {"WGL_ARB_create_context_profile", &sfwgl_ext_ARB_create_context_profile, nullptr} }; static int g_extensionMapSize = 8; @@ -152,7 +152,7 @@ static sfwgl_StrToExtMap* FindExtEntry(const char* extensionName) return currLoc; } - return NULL; + return nullptr; } @@ -171,7 +171,7 @@ static void ClearExtensionVars(void) static void LoadExtByName(const char* extensionName) { - sfwgl_StrToExtMap* entry = NULL; + sfwgl_StrToExtMap* entry = nullptr; entry = FindExtEntry(extensionName); if (entry) { diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 9c55180d..e9fc32db 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -65,7 +65,7 @@ namespace unsigned int windowCount = 0; // Windows owned by SFML unsigned int handleCount = 0; // All window handles const wchar_t* className = L"SFML_Window"; - sf::priv::WindowImplWin32* fullscreenWindow = NULL; + sf::priv::WindowImplWin32* fullscreenWindow = nullptr; void setProcessDpiAware() { @@ -131,8 +131,8 @@ namespace priv WindowImplWin32::WindowImplWin32(WindowHandle handle) : m_handle (handle), m_callback (0), -m_cursor (NULL), -m_icon (NULL), +m_cursor (nullptr), +m_icon (nullptr), m_keyRepeatEnabled(true), m_lastSize (0, 0), m_resizing (false), @@ -161,10 +161,10 @@ m_cursorGrabbed (false) //////////////////////////////////////////////////////////// WindowImplWin32::WindowImplWin32(VideoMode mode, const String& title, Uint32 style, const ContextSettings& /*settings*/) : -m_handle (NULL), +m_handle (nullptr), m_callback (0), -m_cursor (NULL), -m_icon (NULL), +m_cursor (nullptr), +m_icon (nullptr), m_keyRepeatEnabled(true), m_lastSize (mode.width, mode.height), m_resizing (false), @@ -181,12 +181,12 @@ m_cursorGrabbed (m_fullscreen) registerWindowClass(); // Compute position and size - HDC screenDC = GetDC(NULL); + HDC screenDC = GetDC(nullptr); int left = (GetDeviceCaps(screenDC, HORZRES) - static_cast(mode.width)) / 2; int top = (GetDeviceCaps(screenDC, VERTRES) - static_cast(mode.height)) / 2; int width = mode.width; int height = mode.height; - ReleaseDC(NULL, screenDC); + ReleaseDC(nullptr, screenDC); // Choose the window style according to the Style parameter DWORD win32Style = WS_VISIBLE; @@ -211,7 +211,7 @@ m_cursorGrabbed (m_fullscreen) } // Create the window - m_handle = CreateWindowW(className, title.toWideString().c_str(), win32Style, left, top, width, height, NULL, NULL, GetModuleHandle(NULL), this); + m_handle = CreateWindowW(className, title.toWideString().c_str(), win32Style, left, top, width, height, nullptr, nullptr, GetModuleHandle(nullptr), this); // If we're the first window handle, we only need to poll for joysticks when WM_DEVICECHANGE message is received if (m_handle) @@ -262,7 +262,7 @@ WindowImplWin32::~WindowImplWin32() // Unregister window class if we were the last window if (windowCount == 0) - UnregisterClassW(className, GetModuleHandleW(NULL)); + UnregisterClassW(className, GetModuleHandleW(nullptr)); } else { @@ -286,7 +286,7 @@ void WindowImplWin32::processEvents() if (!m_callback) { MSG message; - while (PeekMessageW(&message, NULL, 0, 0, PM_REMOVE)) + while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&message); DispatchMessageW(&message); @@ -308,7 +308,7 @@ Vector2i WindowImplWin32::getPosition() const //////////////////////////////////////////////////////////// void WindowImplWin32::setPosition(const Vector2i& position) { - SetWindowPos(m_handle, NULL, position.x, position.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + SetWindowPos(m_handle, nullptr, position.x, position.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); if(m_cursorGrabbed) grabCursor(true); @@ -335,7 +335,7 @@ void WindowImplWin32::setSize(const Vector2u& size) int width = rectangle.right - rectangle.left; int height = rectangle.bottom - rectangle.top; - SetWindowPos(m_handle, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER); + SetWindowPos(m_handle, nullptr, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER); } @@ -364,7 +364,7 @@ void WindowImplWin32::setIcon(unsigned int width, unsigned int height, const Uin } // Create the icon from the pixel array - m_icon = CreateIcon(GetModuleHandleW(NULL), width, height, 1, 32, NULL, iconPixels.data()); + m_icon = CreateIcon(GetModuleHandleW(nullptr), width, height, 1, 32, nullptr, iconPixels.data()); // Set it as both big and small icon of the window if (m_icon) @@ -390,9 +390,9 @@ void WindowImplWin32::setVisible(bool visible) void WindowImplWin32::setMouseCursorVisible(bool visible) { if (visible) - m_cursor = LoadCursorW(NULL, IDC_ARROW); + m_cursor = LoadCursorW(nullptr, IDC_ARROW); else - m_cursor = NULL; + m_cursor = nullptr; SetCursor(m_cursor); } @@ -417,8 +417,8 @@ void WindowImplWin32::setKeyRepeatEnabled(bool enabled) void WindowImplWin32::requestFocus() { // Allow focus stealing only within the same process; compare PIDs of current and foreground window - DWORD thisPid = GetWindowThreadProcessId(m_handle, NULL); - DWORD foregroundPid = GetWindowThreadProcessId(GetForegroundWindow(), NULL); + DWORD thisPid = GetWindowThreadProcessId(m_handle, nullptr); + DWORD foregroundPid = GetWindowThreadProcessId(GetForegroundWindow(), nullptr); if (thisPid == foregroundPid) { @@ -455,11 +455,11 @@ void WindowImplWin32::registerWindowClass() windowClass.lpfnWndProc = &WindowImplWin32::globalOnEvent; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; - windowClass.hInstance = GetModuleHandleW(NULL); - windowClass.hIcon = NULL; + windowClass.hInstance = GetModuleHandleW(nullptr); + windowClass.hIcon = nullptr; windowClass.hCursor = 0; windowClass.hbrBackground = 0; - windowClass.lpszMenuName = NULL; + windowClass.lpszMenuName = nullptr; windowClass.lpszClassName = className; RegisterClassW(&windowClass); } @@ -501,8 +501,8 @@ void WindowImplWin32::cleanup() // Restore the previous video mode (in case we were running in fullscreen) if (fullscreenWindow == this) { - ChangeDisplaySettingsW(NULL, 0); - fullscreenWindow = NULL; + ChangeDisplaySettingsW(nullptr, 0); + fullscreenWindow = nullptr; } // Unhide the mouse cursor (in case it was hidden) @@ -535,12 +535,12 @@ void WindowImplWin32::grabCursor(bool grabbed) { RECT rect; GetClientRect(m_handle, &rect); - MapWindowPoints(m_handle, NULL, reinterpret_cast(&rect), 2); + MapWindowPoints(m_handle, nullptr, reinterpret_cast(&rect), 2); ClipCursor(&rect); } else { - ClipCursor(NULL); + ClipCursor(nullptr); } } @@ -549,7 +549,7 @@ void WindowImplWin32::grabCursor(bool grabbed) void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) { // Don't process any message until window is created - if (m_handle == NULL) + if (m_handle == nullptr) return; switch (message) @@ -1111,7 +1111,7 @@ LRESULT CALLBACK WindowImplWin32::globalOnEvent(HWND handle, UINT message, WPARA } // Get the WindowImpl instance corresponding to the window handle - WindowImplWin32* window = handle ? reinterpret_cast(GetWindowLongPtr(handle, GWLP_USERDATA)) : NULL; + WindowImplWin32* window = handle ? reinterpret_cast(GetWindowLongPtr(handle, GWLP_USERDATA)) : nullptr; // Forward the event to the appropriate function if (window) diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 1657dc99..2e1481b0 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -34,7 +34,7 @@ namespace { - const sf::Window* fullscreenWindow = NULL; + const sf::Window* fullscreenWindow = nullptr; } @@ -153,14 +153,14 @@ void Window::close() // Update the fullscreen window if (this == fullscreenWindow) - fullscreenWindow = NULL; + fullscreenWindow = nullptr; } //////////////////////////////////////////////////////////// bool Window::isOpen() const { - return m_impl != NULL; + return m_impl != nullptr; } diff --git a/src/SFML/Window/iOS/EaglContext.hpp b/src/SFML/Window/iOS/EaglContext.hpp index 8eed8f81..5150a721 100644 --- a/src/SFML/Window/iOS/EaglContext.hpp +++ b/src/SFML/Window/iOS/EaglContext.hpp @@ -55,7 +55,7 @@ public: //////////////////////////////////////////////////////////// /// \brief Create a new context, not associated to a window /// - /// \param shared Context to share the new one with (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) /// //////////////////////////////////////////////////////////// EaglContext(EaglContext* shared); @@ -138,8 +138,8 @@ private: //////////////////////////////////////////////////////////// /// \brief Create the context /// - /// \param shared Context to share the new one with (can be NULL) - /// \param window Window to attach the context to (can be NULL) + /// \param shared Context to share the new one with (can be nullptr) + /// \param window Window to attach the context to (can be nullptr) /// \param bitsPerPixel Pixel depth, in bits per pixel /// \param settings Creation parameters /// diff --git a/src/SFML/Window/iOS/SFAppDelegate.mm b/src/SFML/Window/iOS/SFAppDelegate.mm index 5e202d38..98c671f2 100644 --- a/src/SFML/Window/iOS/SFAppDelegate.mm +++ b/src/SFML/Window/iOS/SFAppDelegate.mm @@ -33,7 +33,7 @@ namespace { // Save the global instance of the delegate - SFAppDelegate* delegateInstance = NULL; + SFAppDelegate* delegateInstance = nullptr; // Current touches positions std::vector touchPositions; @@ -64,7 +64,7 @@ namespace - (void)runUserMain { // Arguments intentionally dropped, see comments in main in sfml-main - sfmlMain(0, NULL); + sfmlMain(0, nullptr); } diff --git a/src/SFML/Window/iOS/SFView.mm b/src/SFML/Window/iOS/SFView.mm index b4ae496d..c62e812c 100644 --- a/src/SFML/Window/iOS/SFView.mm +++ b/src/SFML/Window/iOS/SFView.mm @@ -183,7 +183,7 @@ if (self) { - self.context = NULL; + self.context = nullptr; self.touches = [NSMutableArray array]; // Configure the EAGL layer From 24db1dba1a00a9bcb7021f5641b44914d7114c07 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Tue, 4 Apr 2017 01:13:07 +0200 Subject: [PATCH 14/18] Converted applicable enumerations to strongly typed enumerations. --- examples/cocoa/CocoaAppDelegate.mm | 4 +- examples/ftp/Ftp.cpp | 2 +- examples/opengl/OpenGL.cpp | 10 +- examples/pong/Pong.cpp | 10 +- examples/shader/Shader.cpp | 18 +- examples/sockets/TCP.cpp | 14 +- examples/sockets/UDP.cpp | 10 +- examples/sound/Sound.cpp | 4 +- examples/sound_capture/SoundCapture.cpp | 2 +- examples/voip/Client.cpp | 4 +- examples/voip/Server.cpp | 10 +- examples/window/Window.cpp | 6 +- include/SFML/Audio/SoundSource.hpp | 2 +- include/SFML/Graphics/BlendMode.hpp | 6 +- include/SFML/Graphics/PrimitiveType.hpp | 10 +- include/SFML/Graphics/Shader.hpp | 2 +- include/SFML/Graphics/Texture.hpp | 4 +- include/SFML/Network/Ftp.hpp | 10 +- include/SFML/Network/Http.hpp | 6 +- include/SFML/Network/Socket.hpp | 4 +- include/SFML/Window/Event.hpp | 4 +- include/SFML/Window/Joystick.hpp | 9 +- include/SFML/Window/Keyboard.hpp | 209 +++++------ include/SFML/Window/Mouse.hpp | 6 +- include/SFML/Window/Sensor.hpp | 2 +- src/SFML/Audio/SoundSource.cpp | 8 +- src/SFML/Audio/SoundStream.cpp | 26 +- src/SFML/Graphics/BlendMode.cpp | 24 +- src/SFML/Graphics/RenderStates.cpp | 4 +- src/SFML/Graphics/RenderTarget.cpp | 32 +- src/SFML/Graphics/Shader.cpp | 12 +- src/SFML/Graphics/Shape.cpp | 4 +- src/SFML/Graphics/Sprite.cpp | 2 +- src/SFML/Graphics/Text.cpp | 8 +- src/SFML/Graphics/Texture.cpp | 4 +- src/SFML/Graphics/VertexArray.cpp | 2 +- src/SFML/Main/MainAndroid.cpp | 14 +- src/SFML/Network/Ftp.cpp | 36 +- src/SFML/Network/Http.cpp | 24 +- src/SFML/Network/IpAddress.cpp | 4 +- src/SFML/Network/Socket.cpp | 4 +- src/SFML/Network/TcpListener.cpp | 14 +- src/SFML/Network/TcpSocket.cpp | 34 +- src/SFML/Network/UdpSocket.cpp | 18 +- src/SFML/Network/Unix/SocketImpl.cpp | 18 +- src/SFML/Network/Win32/SocketImpl.cpp | 18 +- src/SFML/System/Android/Activity.hpp | 2 +- src/SFML/Window/Android/InputImpl.cpp | 2 +- src/SFML/Window/Android/SensorImpl.cpp | 18 +- src/SFML/Window/Android/WindowImplAndroid.cpp | 162 ++++----- src/SFML/Window/FreeBSD/JoystickImpl.cpp | 20 +- src/SFML/Window/Joystick.cpp | 4 +- src/SFML/Window/JoystickImpl.hpp | 8 +- src/SFML/Window/OSX/HIDInputManager.hpp | 10 +- src/SFML/Window/OSX/HIDInputManager.mm | 338 +++++++++--------- src/SFML/Window/OSX/InputImpl.mm | 2 +- src/SFML/Window/OSX/JoystickImpl.cpp | 36 +- .../Window/OSX/SFKeyboardModifiersHelper.mm | 8 +- src/SFML/Window/OSX/SFOpenGLView+keyboard.mm | 8 +- src/SFML/Window/OSX/SFOpenGLView+mouse.mm | 16 +- src/SFML/Window/OSX/WindowImplCocoa.mm | 34 +- src/SFML/Window/SensorManager.cpp | 26 +- src/SFML/Window/SensorManager.hpp | 2 +- src/SFML/Window/Unix/InputImpl.cpp | 220 ++++++------ src/SFML/Window/Unix/JoystickImpl.cpp | 32 +- src/SFML/Window/Unix/WindowImplX11.cpp | 270 +++++++------- src/SFML/Window/Win32/InputImpl.cpp | 214 +++++------ src/SFML/Window/Win32/JoystickImpl.cpp | 36 +- src/SFML/Window/Win32/WindowImplWin32.cpp | 264 +++++++------- src/SFML/Window/Window.cpp | 2 +- src/SFML/Window/WindowImpl.cpp | 23 +- src/SFML/Window/WindowImpl.hpp | 8 +- src/SFML/Window/iOS/SensorImpl.mm | 46 +-- src/SFML/Window/iOS/WindowImplUIKit.mm | 4 +- 74 files changed, 1242 insertions(+), 1251 deletions(-) diff --git a/examples/cocoa/CocoaAppDelegate.mm b/examples/cocoa/CocoaAppDelegate.mm index 3996b3a3..fa230ddd 100644 --- a/examples/cocoa/CocoaAppDelegate.mm +++ b/examples/cocoa/CocoaAppDelegate.mm @@ -161,10 +161,10 @@ struct SFMLmainWindow // Scaling /* /!\ we do this at 60fps so choose low scaling factor! /!\ */ - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) self.mainWindow->sprite.scale(1.01f, 1.01f); - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down)) self.mainWindow->sprite.scale(0.99f, 0.99f); // Clear the window, display some stuff and display it into our view. diff --git a/examples/ftp/Ftp.cpp b/examples/ftp/Ftp.cpp index 4a346cc9..a2abbc65 100644 --- a/examples/ftp/Ftp.cpp +++ b/examples/ftp/Ftp.cpp @@ -13,7 +13,7 @@ //////////////////////////////////////////////////////////// std::ostream& operator <<(std::ostream& stream, const sf::Ftp::Response& response) { - return stream << response.getStatus() << response.getMessage(); + return stream << static_cast(response.getStatus()) << response.getMessage(); } diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index fb3f77c6..6318fd1b 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -161,21 +161,21 @@ int main() while (window.pollEvent(event)) { // Close window: exit - if (event.type == sf::Event::Closed) + if (event.type == sf::Event::Type::Closed) { exit = true; window.close(); } // Escape key: exit - if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) + if ((event.type == sf::Event::Type::KeyPressed) && (event.key.code == sf::Keyboard::Key::Escape)) { exit = true; window.close(); } // Return key: toggle mipmapping - if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Return)) + if ((event.type == sf::Event::Type::KeyPressed) && (event.key.code == sf::Keyboard::Key::Return)) { if (mipmapEnabled) { @@ -194,14 +194,14 @@ int main() } // Space key: toggle sRGB conversion - if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space)) + if ((event.type == sf::Event::Type::KeyPressed) && (event.key.code == sf::Keyboard::Key::Space)) { sRgb = !sRgb; window.close(); } // Adjust the viewport when the window is resized - if (event.type == sf::Event::Resized) + if (event.type == sf::Event::Type::Resized) { // Make the window the active window for OpenGL calls window.setActive(true); diff --git a/examples/pong/Pong.cpp b/examples/pong/Pong.cpp index 9fdcede0..1d0200ea 100644 --- a/examples/pong/Pong.cpp +++ b/examples/pong/Pong.cpp @@ -91,15 +91,15 @@ int main() while (window.pollEvent(event)) { // Window closed or escape key pressed: exit - if ((event.type == sf::Event::Closed) || - ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))) + if ((event.type == sf::Event::Type::Closed) || + ((event.type == sf::Event::Type::KeyPressed) && (event.key.code == sf::Keyboard::Key::Escape))) { window.close(); break; } // Space key pressed: play - if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space)) + if ((event.type == sf::Event::Type::KeyPressed) && (event.key.code == sf::Keyboard::Key::Space)) { if (!isPlaying) { @@ -128,12 +128,12 @@ int main() float deltaTime = clock.restart().asSeconds(); // Move the player's paddle - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up) && (leftPaddle.getPosition().y - paddleSize.y / 2 > 5.f)) { leftPaddle.move(0.f, -paddleSpeed * deltaTime); } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down) && (leftPaddle.getPosition().y + paddleSize.y / 2 < gameHeight - 5.f)) { leftPaddle.move(0.f, paddleSpeed * deltaTime); diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index 1d87cf17..fed5ee32 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -30,7 +30,7 @@ public: m_sprite.setTexture(m_texture); // Load the shader - if (!m_shader.loadFromFile("resources/pixelate.frag", sf::Shader::Fragment)) + if (!m_shader.loadFromFile("resources/pixelate.frag", sf::Shader::Type::Fragment)) return false; m_shader.setUniform("texture", sf::Shader::CurrentTexture); @@ -135,7 +135,7 @@ public: bool onLoad() { // Create the points - m_points.setPrimitiveType(sf::Points); + m_points.setPrimitiveType(sf::PrimitiveType::Points); for (int i = 0; i < 40000; ++i) { float x = static_cast(std::rand() % 800); @@ -214,7 +214,7 @@ public: } // Load the shader - if (!m_shader.loadFromFile("resources/edge.frag", sf::Shader::Fragment)) + if (!m_shader.loadFromFile("resources/edge.frag", sf::Shader::Type::Fragment)) return false; m_shader.setUniform("texture", sf::Shader::CurrentTexture); @@ -268,7 +268,7 @@ public: Geometry() : Effect("geometry shader billboards"), - m_pointCloud(sf::Points, 10000) + m_pointCloud(sf::PrimitiveType::Points, 10000) { } @@ -397,20 +397,20 @@ int main() while (window.pollEvent(event)) { // Close window: exit - if (event.type == sf::Event::Closed) + if (event.type == sf::Event::Type::Closed) window.close(); - if (event.type == sf::Event::KeyPressed) + if (event.type == sf::Event::Type::KeyPressed) { switch (event.key.code) { // Escape key: exit - case sf::Keyboard::Escape: + case sf::Keyboard::Key::Escape: window.close(); break; // Left arrow key: previous shader - case sf::Keyboard::Left: + case sf::Keyboard::Key::Left: if (current == 0) current = effects.size() - 1; else @@ -419,7 +419,7 @@ int main() break; // Right arrow key: next shader - case sf::Keyboard::Right: + case sf::Keyboard::Key::Right: if (current == effects.size() - 1) current = 0; else diff --git a/examples/sockets/TCP.cpp b/examples/sockets/TCP.cpp index 64fb7f91..09720bfc 100644 --- a/examples/sockets/TCP.cpp +++ b/examples/sockets/TCP.cpp @@ -17,26 +17,26 @@ void runTcpServer(unsigned short port) sf::TcpListener listener; // Listen to the given port for incoming connections - if (listener.listen(port) != sf::Socket::Done) + if (listener.listen(port) != sf::Socket::Status::Done) return; std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl; // Wait for a connection sf::TcpSocket socket; - if (listener.accept(socket) != sf::Socket::Done) + if (listener.accept(socket) != sf::Socket::Status::Done) return; std::cout << "Client connected: " << socket.getRemoteAddress() << std::endl; // Send a message to the connected client const char out[] = "Hi, I'm the server"; - if (socket.send(out, sizeof(out)) != sf::Socket::Done) + if (socket.send(out, sizeof(out)) != sf::Socket::Status::Done) return; std::cout << "Message sent to the client: \"" << out << "\"" << std::endl; // Receive a message back from the client char in[128]; std::size_t received; - if (socket.receive(in, sizeof(in), received) != sf::Socket::Done) + if (socket.receive(in, sizeof(in), received) != sf::Socket::Status::Done) return; std::cout << "Answer received from the client: \"" << in << "\"" << std::endl; } @@ -62,20 +62,20 @@ void runTcpClient(unsigned short port) sf::TcpSocket socket; // Connect to the server - if (socket.connect(server, port) != sf::Socket::Done) + if (socket.connect(server, port) != sf::Socket::Status::Done) return; std::cout << "Connected to server " << server << std::endl; // Receive a message from the server char in[128]; std::size_t received; - if (socket.receive(in, sizeof(in), received) != sf::Socket::Done) + if (socket.receive(in, sizeof(in), received) != sf::Socket::Status::Done) return; std::cout << "Message received from the server: \"" << in << "\"" << std::endl; // Send an answer to the server const char out[] = "Hi, I'm a client"; - if (socket.send(out, sizeof(out)) != sf::Socket::Done) + if (socket.send(out, sizeof(out)) != sf::Socket::Status::Done) return; std::cout << "Message sent to the server: \"" << out << "\"" << std::endl; } diff --git a/examples/sockets/UDP.cpp b/examples/sockets/UDP.cpp index 37a07c53..e7e05d74 100644 --- a/examples/sockets/UDP.cpp +++ b/examples/sockets/UDP.cpp @@ -16,7 +16,7 @@ void runUdpServer(unsigned short port) sf::UdpSocket socket; // Listen to messages on the specified port - if (socket.bind(port) != sf::Socket::Done) + if (socket.bind(port) != sf::Socket::Status::Done) return; std::cout << "Server is listening to port " << port << ", waiting for a message... " << std::endl; @@ -25,13 +25,13 @@ void runUdpServer(unsigned short port) std::size_t received; sf::IpAddress sender; unsigned short senderPort; - if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done) + if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Status::Done) return; std::cout << "Message received from client " << sender << ": \"" << in << "\"" << std::endl; // Send an answer to the client const char out[] = "Hi, I'm the server"; - if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done) + if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Status::Done) return; std::cout << "Message sent to the client: \"" << out << "\"" << std::endl; } @@ -57,7 +57,7 @@ void runUdpClient(unsigned short port) // Send a message to the server const char out[] = "Hi, I'm a client"; - if (socket.send(out, sizeof(out), server, port) != sf::Socket::Done) + if (socket.send(out, sizeof(out), server, port) != sf::Socket::Status::Done) return; std::cout << "Message sent to the server: \"" << out << "\"" << std::endl; @@ -66,7 +66,7 @@ void runUdpClient(unsigned short port) std::size_t received; sf::IpAddress sender; unsigned short senderPort; - if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done) + if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Status::Done) return; std::cout << "Message received from " << sender << ": \"" << in << "\"" << std::endl; } diff --git a/examples/sound/Sound.cpp b/examples/sound/Sound.cpp index e71aa0d0..2bf03f42 100644 --- a/examples/sound/Sound.cpp +++ b/examples/sound/Sound.cpp @@ -29,7 +29,7 @@ void playSound() sound.play(); // Loop while the sound is playing - while (sound.getStatus() == sf::Sound::Playing) + while (sound.getStatus() == sf::Sound::Status::Playing) { // Leave some CPU time for other processes sf::sleep(sf::milliseconds(100)); @@ -63,7 +63,7 @@ void playMusic(const std::string& filename) music.play(); // Loop while the music is playing - while (music.getStatus() == sf::Music::Playing) + while (music.getStatus() == sf::Music::Status::Playing) { // Leave some CPU time for other processes sf::sleep(sf::milliseconds(100)); diff --git a/examples/sound_capture/SoundCapture.cpp b/examples/sound_capture/SoundCapture.cpp index 19f114b4..cdeb43cf 100644 --- a/examples/sound_capture/SoundCapture.cpp +++ b/examples/sound_capture/SoundCapture.cpp @@ -72,7 +72,7 @@ int main() sound.play(); // Wait until finished - while (sound.getStatus() == sf::Sound::Playing) + while (sound.getStatus() == sf::Sound::Status::Playing) { // Display the playing position std::cout << "\rPlaying... " << sound.getPlayingOffset().asSeconds() << " sec "; diff --git a/examples/voip/Client.cpp b/examples/voip/Client.cpp index d66e0e23..93879dcf 100644 --- a/examples/voip/Client.cpp +++ b/examples/voip/Client.cpp @@ -52,7 +52,7 @@ private: //////////////////////////////////////////////////////////// virtual bool onStart() { - if (m_socket.connect(m_host, m_port) == sf::Socket::Done) + if (m_socket.connect(m_host, m_port) == sf::Socket::Status::Done) { std::cout << "Connected to server " << m_host << std::endl; return true; @@ -75,7 +75,7 @@ private: packet.append(samples, sampleCount * sizeof(sf::Int16)); // Send the audio packet to the server - return m_socket.send(packet) == sf::Socket::Done; + return m_socket.send(packet) == sf::Socket::Status::Done; } //////////////////////////////////////////////////////////// diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index f1a6359d..c5848ff2 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -43,12 +43,12 @@ public: if (!m_hasFinished) { // Listen to the given port for incoming connections - if (m_listener.listen(port) != sf::Socket::Done) + if (m_listener.listen(port) != sf::Socket::Status::Done) return; std::cout << "Server is listening to port " << port << ", waiting for connections... " << std::endl; // Wait for a connection - if (m_listener.accept(m_client) != sf::Socket::Done) + if (m_listener.accept(m_client) != sf::Socket::Status::Done) return; std::cout << "Client connected: " << m_client.getRemoteAddress() << std::endl; @@ -117,7 +117,7 @@ private: { // Get waiting audio data from the network sf::Packet packet; - if (m_client.receive(packet) != sf::Socket::Done) + if (m_client.receive(packet) != sf::Socket::Status::Done) break; // Extract the message ID @@ -177,7 +177,7 @@ void doServer(unsigned short port) audioStream.start(port); // Loop until the sound playback is finished - while (audioStream.getStatus() != sf::SoundStream::Stopped) + while (audioStream.getStatus() != sf::SoundStream::Status::Stopped) { // Leave some CPU time for other threads sf::sleep(sf::milliseconds(100)); @@ -193,7 +193,7 @@ void doServer(unsigned short port) audioStream.play(); // Loop until the sound playback is finished - while (audioStream.getStatus() != sf::SoundStream::Stopped) + while (audioStream.getStatus() != sf::SoundStream::Status::Stopped) { // Leave some CPU time for other threads sf::sleep(sf::milliseconds(100)); diff --git a/examples/window/Window.cpp b/examples/window/Window.cpp index 3fcea52c..bb090d4b 100644 --- a/examples/window/Window.cpp +++ b/examples/window/Window.cpp @@ -112,15 +112,15 @@ int main() while (window.pollEvent(event)) { // Close window: exit - if (event.type == sf::Event::Closed) + if (event.type == sf::Event::Type::Closed) window.close(); // Escape key: exit - if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)) + if ((event.type == sf::Event::Type::KeyPressed) && (event.key.code == sf::Keyboard::Key::Escape)) window.close(); // Resize event: adjust the viewport - if (event.type == sf::Event::Resized) + if (event.type == sf::Event::Type::Resized) glViewport(0, 0, event.size.width, event.size.height); } diff --git a/include/SFML/Audio/SoundSource.hpp b/include/SFML/Audio/SoundSource.hpp index edcaaa29..16e4d871 100644 --- a/include/SFML/Audio/SoundSource.hpp +++ b/include/SFML/Audio/SoundSource.hpp @@ -47,7 +47,7 @@ public: /// \brief Enumeration of the sound source states /// //////////////////////////////////////////////////////////// - enum Status + enum class Status : unsigned char { Stopped, ///< Sound is not playing Paused, ///< Sound is paused diff --git a/include/SFML/Graphics/BlendMode.hpp b/include/SFML/Graphics/BlendMode.hpp index 3ba0a40f..edd32896 100644 --- a/include/SFML/Graphics/BlendMode.hpp +++ b/include/SFML/Graphics/BlendMode.hpp @@ -46,7 +46,7 @@ struct SFML_GRAPHICS_API BlendMode /// The factors are mapped directly to their OpenGL equivalents, /// specified by glBlendFunc() or glBlendFuncSeparate(). //////////////////////////////////////////////////////// - enum Factor + enum class Factor : unsigned char { Zero, ///< (0, 0, 0, 0) One, ///< (1, 1, 1, 1) @@ -66,7 +66,7 @@ struct SFML_GRAPHICS_API BlendMode /// The equations are mapped directly to their OpenGL equivalents, /// specified by glBlendEquation() or glBlendEquationSeparate(). //////////////////////////////////////////////////////// - enum Equation + enum class Equation : unsigned char { Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor Subtract, ///< Pixel = Src * SrcFactor - Dst * DstFactor @@ -92,7 +92,7 @@ struct SFML_GRAPHICS_API BlendMode /// \param blendEquation Specifies how to combine the source and destination colors and alpha. /// //////////////////////////////////////////////////////////// - BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Add); + BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Equation::Add); //////////////////////////////////////////////////////////// /// \brief Construct the blend mode given the factors and equation. diff --git a/include/SFML/Graphics/PrimitiveType.hpp b/include/SFML/Graphics/PrimitiveType.hpp index 33f9e466..ba20e7ba 100644 --- a/include/SFML/Graphics/PrimitiveType.hpp +++ b/include/SFML/Graphics/PrimitiveType.hpp @@ -36,20 +36,14 @@ namespace sf /// and view. /// //////////////////////////////////////////////////////////// -enum PrimitiveType +enum class PrimitiveType : unsigned char { Points, ///< List of individual points Lines, ///< List of individual lines LineStrip, ///< List of connected lines, a point uses the previous point to form a line Triangles, ///< List of individual triangles TriangleStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle - TriangleFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle - Quads, ///< List of individual quads (deprecated, don't work with OpenGL ES) - - // Deprecated names - LinesStrip = LineStrip, ///< \deprecated Use LineStrip instead - TrianglesStrip = TriangleStrip, ///< \deprecated Use TriangleStrip instead - TrianglesFan = TriangleFan ///< \deprecated Use TriangleFan instead + TriangleFan ///< List of connected triangles, a point uses the common center and the previous point to form a triangle }; } // namespace sf diff --git a/include/SFML/Graphics/Shader.hpp b/include/SFML/Graphics/Shader.hpp index 114dbdc8..bc4d8d44 100644 --- a/include/SFML/Graphics/Shader.hpp +++ b/include/SFML/Graphics/Shader.hpp @@ -57,7 +57,7 @@ public: /// \brief Types of shaders /// //////////////////////////////////////////////////////////// - enum Type + enum class Type : unsigned char { Vertex, ///< %Vertex shader Geometry, ///< Geometry shader diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index 99ae3725..f3a63d26 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -52,7 +52,7 @@ public: /// \brief Types of texture coordinates that can be used for rendering /// //////////////////////////////////////////////////////////// - enum CoordinateType + enum class CoordinateType : unsigned char { Normalized, ///< Texture coordinates in range [0 .. 1] Pixels ///< Texture coordinates in range [0 .. size] @@ -568,7 +568,7 @@ public: /// \param coordinateType Type of texture coordinates to use /// //////////////////////////////////////////////////////////// - static void bind(const Texture* texture, CoordinateType coordinateType = Normalized); + static void bind(const Texture* texture, CoordinateType coordinateType = CoordinateType::Normalized); //////////////////////////////////////////////////////////// /// \brief Get the maximum texture size allowed diff --git a/include/SFML/Network/Ftp.hpp b/include/SFML/Network/Ftp.hpp index 3600a9d8..38a1808d 100644 --- a/include/SFML/Network/Ftp.hpp +++ b/include/SFML/Network/Ftp.hpp @@ -52,7 +52,7 @@ public: /// \brief Enumeration of transfer modes /// //////////////////////////////////////////////////////////// - enum TransferMode + enum class TransferMode : unsigned char { Binary, ///< Binary mode (file is transfered as a sequence of bytes) Ascii, ///< Text mode using ASCII encoding @@ -71,7 +71,7 @@ public: /// \brief Status codes possibly returned by a FTP response /// //////////////////////////////////////////////////////////// - enum Status + enum class Status : unsigned short { // 1xx: the requested action is being initiated, // expect another reply before proceeding with a new command @@ -143,7 +143,7 @@ public: /// \param message Response message /// //////////////////////////////////////////////////////////// - explicit Response(Status code = InvalidResponse, const std::string& message = ""); + explicit Response(Status code = Status::InvalidResponse, const std::string& message = ""); //////////////////////////////////////////////////////////// /// \brief Check if the status code means a success @@ -465,7 +465,7 @@ public: /// \see upload /// //////////////////////////////////////////////////////////// - Response download(const std::string& remoteFile, const std::string& localPath, TransferMode mode = Binary); + Response download(const std::string& remoteFile, const std::string& localPath, TransferMode mode = TransferMode::Binary); //////////////////////////////////////////////////////////// /// \brief Upload a file to the server @@ -484,7 +484,7 @@ public: /// \see download /// //////////////////////////////////////////////////////////// - Response upload(const std::string& localFile, const std::string& remotePath, TransferMode mode = Binary); + Response upload(const std::string& localFile, const std::string& remotePath, TransferMode mode = TransferMode::Binary); //////////////////////////////////////////////////////////// /// \brief Send a command to the FTP server diff --git a/include/SFML/Network/Http.hpp b/include/SFML/Network/Http.hpp index d165a7c1..8b10ffee 100644 --- a/include/SFML/Network/Http.hpp +++ b/include/SFML/Network/Http.hpp @@ -59,7 +59,7 @@ public: /// \brief Enumerate the available HTTP methods for a request /// //////////////////////////////////////////////////////////// - enum Method + enum class Method : unsigned char { Get, ///< Request in get mode, standard method to retrieve a page Post, ///< Request in post mode, usually to send data to a page @@ -79,7 +79,7 @@ public: /// \param body Content of the request's body /// //////////////////////////////////////////////////////////// - Request(const std::string& uri = "/", Method method = Get, const std::string& body = ""); + Request(const std::string& uri = "/", Method method = Method::Get, const std::string& body = ""); //////////////////////////////////////////////////////////// /// \brief Set the value of a field @@ -198,7 +198,7 @@ public: /// \brief Enumerate all the valid status codes for a response /// //////////////////////////////////////////////////////////// - enum Status + enum class Status : unsigned short { // 2xx: success Ok = 200, ///< Most common code returned when operation was successful diff --git a/include/SFML/Network/Socket.hpp b/include/SFML/Network/Socket.hpp index 0b111716..717c5af2 100644 --- a/include/SFML/Network/Socket.hpp +++ b/include/SFML/Network/Socket.hpp @@ -50,7 +50,7 @@ public: /// \brief Status codes that may be returned by socket functions /// //////////////////////////////////////////////////////////// - enum Status + enum class Status : unsigned char { Done, ///< The socket has sent / received the data NotReady, ///< The socket is not ready to send / receive data yet @@ -111,7 +111,7 @@ protected: /// \brief Types of protocols that the socket can use /// //////////////////////////////////////////////////////////// - enum Type + enum class Type : unsigned char { Tcp, ///< TCP protocol Udp ///< UDP protocol diff --git a/include/SFML/Window/Event.hpp b/include/SFML/Window/Event.hpp index 7bfd610f..36cce57e 100644 --- a/include/SFML/Window/Event.hpp +++ b/include/SFML/Window/Event.hpp @@ -184,7 +184,7 @@ public: /// \brief Enumeration of the different types of events /// //////////////////////////////////////////////////////////// - enum EventType + enum class Type : unsigned char { Closed, ///< The window requested to be closed (no data) Resized, ///< The window was resized (data in event.size) @@ -216,7 +216,7 @@ public: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - EventType type; ///< Type of the event + Type type; ///< Type of the event union { diff --git a/include/SFML/Window/Joystick.hpp b/include/SFML/Window/Joystick.hpp index dda73699..75ff38d4 100644 --- a/include/SFML/Window/Joystick.hpp +++ b/include/SFML/Window/Joystick.hpp @@ -49,15 +49,14 @@ public: enum { Count = 8, ///< Maximum number of supported joysticks - ButtonCount = 32, ///< Maximum number of supported buttons - AxisCount = 8 ///< Maximum number of supported axes + ButtonCount = 32 ///< Maximum number of supported buttons }; //////////////////////////////////////////////////////////// /// \brief Axes supported by SFML joysticks /// //////////////////////////////////////////////////////////// - enum Axis + enum class Axis : unsigned char { X, ///< The X axis Y, ///< The Y axis @@ -66,7 +65,9 @@ public: U, ///< The U axis V, ///< The V axis PovX, ///< The X axis of the point-of-view hat - PovY ///< The Y axis of the point-of-view hat + PovY, ///< The Y axis of the point-of-view hat + + Count ///< Maximum number of supported axes }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/Window/Keyboard.hpp b/include/SFML/Window/Keyboard.hpp index b35c7a02..7366463f 100644 --- a/include/SFML/Window/Keyboard.hpp +++ b/include/SFML/Window/Keyboard.hpp @@ -45,112 +45,113 @@ public: /// \brief Key codes /// //////////////////////////////////////////////////////////// - enum Key + enum class Key : unsigned char { - Unknown = -1, ///< Unhandled key - A = 0, ///< The A key - B, ///< The B key - C, ///< The C key - D, ///< The D key - E, ///< The E key - F, ///< The F key - G, ///< The G key - H, ///< The H key - I, ///< The I key - J, ///< The J key - K, ///< The K key - L, ///< The L key - M, ///< The M key - N, ///< The N key - O, ///< The O key - P, ///< The P key - Q, ///< The Q key - R, ///< The R key - S, ///< The S key - T, ///< The T key - U, ///< The U key - V, ///< The V key - W, ///< The W key - X, ///< The X key - Y, ///< The Y key - Z, ///< The Z key - Num0, ///< The 0 key - Num1, ///< The 1 key - Num2, ///< The 2 key - Num3, ///< The 3 key - Num4, ///< The 4 key - Num5, ///< The 5 key - Num6, ///< The 6 key - Num7, ///< The 7 key - Num8, ///< The 8 key - Num9, ///< The 9 key - Escape, ///< The Escape key - LControl, ///< The left Control key - LShift, ///< The left Shift key - LAlt, ///< The left Alt key - LSystem, ///< The left OS specific key: window (Windows and Linux), apple (MacOS X), ... - RControl, ///< The right Control key - RShift, ///< The right Shift key - RAlt, ///< The right Alt key - RSystem, ///< The right OS specific key: window (Windows and Linux), apple (MacOS X), ... - Menu, ///< The Menu key - LBracket, ///< The [ key - RBracket, ///< The ] key - SemiColon, ///< The ; key - Comma, ///< The , key - Period, ///< The . key - Quote, ///< The ' key - Slash, ///< The / key - BackSlash, ///< The \ key - Tilde, ///< The ~ key - Equal, ///< The = key - Dash, ///< The - key - Space, ///< The Space key - Return, ///< The Return key - BackSpace, ///< The Backspace key - Tab, ///< The Tabulation key - PageUp, ///< The Page up key - PageDown, ///< The Page down key - End, ///< The End key - Home, ///< The Home key - Insert, ///< The Insert key - Delete, ///< The Delete key - Add, ///< The + key - Subtract, ///< The - key - Multiply, ///< The * key - Divide, ///< The / key - Left, ///< Left arrow - Right, ///< Right arrow - Up, ///< Up arrow - Down, ///< Down arrow - Numpad0, ///< The numpad 0 key - Numpad1, ///< The numpad 1 key - Numpad2, ///< The numpad 2 key - Numpad3, ///< The numpad 3 key - Numpad4, ///< The numpad 4 key - Numpad5, ///< The numpad 5 key - Numpad6, ///< The numpad 6 key - Numpad7, ///< The numpad 7 key - Numpad8, ///< The numpad 8 key - Numpad9, ///< The numpad 9 key - F1, ///< The F1 key - F2, ///< The F2 key - F3, ///< The F3 key - F4, ///< The F4 key - F5, ///< The F5 key - F6, ///< The F6 key - F7, ///< The F7 key - F8, ///< The F8 key - F9, ///< The F9 key - F10, ///< The F10 key - F11, ///< The F11 key - F12, ///< The F12 key - F13, ///< The F13 key - F14, ///< The F14 key - F15, ///< The F15 key - Pause, ///< The Pause key + Unknown = static_cast(-1), ///< Unhandled key - KeyCount ///< Keep last -- the total number of keyboard keys + A = 0, ///< The A key + B, ///< The B key + C, ///< The C key + D, ///< The D key + E, ///< The E key + F, ///< The F key + G, ///< The G key + H, ///< The H key + I, ///< The I key + J, ///< The J key + K, ///< The K key + L, ///< The L key + M, ///< The M key + N, ///< The N key + O, ///< The O key + P, ///< The P key + Q, ///< The Q key + R, ///< The R key + S, ///< The S key + T, ///< The T key + U, ///< The U key + V, ///< The V key + W, ///< The W key + X, ///< The X key + Y, ///< The Y key + Z, ///< The Z key + Num0, ///< The 0 key + Num1, ///< The 1 key + Num2, ///< The 2 key + Num3, ///< The 3 key + Num4, ///< The 4 key + Num5, ///< The 5 key + Num6, ///< The 6 key + Num7, ///< The 7 key + Num8, ///< The 8 key + Num9, ///< The 9 key + Escape, ///< The Escape key + LControl, ///< The left Control key + LShift, ///< The left Shift key + LAlt, ///< The left Alt key + LSystem, ///< The left OS specific key: window (Windows and Linux), apple (MacOS X), ... + RControl, ///< The right Control key + RShift, ///< The right Shift key + RAlt, ///< The right Alt key + RSystem, ///< The right OS specific key: window (Windows and Linux), apple (MacOS X), ... + Menu, ///< The Menu key + LBracket, ///< The [ key + RBracket, ///< The ] key + SemiColon, ///< The ; key + Comma, ///< The , key + Period, ///< The . key + Quote, ///< The ' key + Slash, ///< The / key + BackSlash, ///< The \ key + Tilde, ///< The ~ key + Equal, ///< The = key + Dash, ///< The - key + Space, ///< The Space key + Return, ///< The Return key + BackSpace, ///< The Backspace key + Tab, ///< The Tabulation key + PageUp, ///< The Page up key + PageDown, ///< The Page down key + End, ///< The End key + Home, ///< The Home key + Insert, ///< The Insert key + Delete, ///< The Delete key + Add, ///< The + key + Subtract, ///< The - key + Multiply, ///< The * key + Divide, ///< The / key + Left, ///< Left arrow + Right, ///< Right arrow + Up, ///< Up arrow + Down, ///< Down arrow + Numpad0, ///< The numpad 0 key + Numpad1, ///< The numpad 1 key + Numpad2, ///< The numpad 2 key + Numpad3, ///< The numpad 3 key + Numpad4, ///< The numpad 4 key + Numpad5, ///< The numpad 5 key + Numpad6, ///< The numpad 6 key + Numpad7, ///< The numpad 7 key + Numpad8, ///< The numpad 8 key + Numpad9, ///< The numpad 9 key + F1, ///< The F1 key + F2, ///< The F2 key + F3, ///< The F3 key + F4, ///< The F4 key + F5, ///< The F5 key + F6, ///< The F6 key + F7, ///< The F7 key + F8, ///< The F8 key + F9, ///< The F9 key + F10, ///< The F10 key + F11, ///< The F11 key + F12, ///< The F12 key + F13, ///< The F13 key + F14, ///< The F14 key + F15, ///< The F15 key + Pause, ///< The Pause key + + Count ///< Keep last -- the total number of keyboard keys }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/Window/Mouse.hpp b/include/SFML/Window/Mouse.hpp index 53d5281f..e1a14346 100644 --- a/include/SFML/Window/Mouse.hpp +++ b/include/SFML/Window/Mouse.hpp @@ -48,7 +48,7 @@ public: /// \brief Mouse buttons /// //////////////////////////////////////////////////////////// - enum Button + enum class Button : unsigned char { Left, ///< The left mouse button Right, ///< The right mouse button @@ -56,14 +56,14 @@ public: XButton1, ///< The first extra mouse button XButton2, ///< The second extra mouse button - ButtonCount ///< Keep last -- the total number of mouse buttons + Count ///< Keep last -- the total number of mouse buttons }; //////////////////////////////////////////////////////////// /// \brief Mouse wheels /// //////////////////////////////////////////////////////////// - enum Wheel + enum class Wheel : unsigned char { VerticalWheel, ///< The vertical mouse wheel HorizontalWheel ///< The horizontal mouse wheel diff --git a/include/SFML/Window/Sensor.hpp b/include/SFML/Window/Sensor.hpp index 9bef9703..922816de 100644 --- a/include/SFML/Window/Sensor.hpp +++ b/include/SFML/Window/Sensor.hpp @@ -47,7 +47,7 @@ public: /// \brief Sensor type /// //////////////////////////////////////////////////////////// - enum Type + enum class Type : unsigned char { Accelerometer, ///< Measures the raw acceleration (m/s^2) Gyroscope, ///< Measures the raw rotation rates (degrees/s) diff --git a/src/SFML/Audio/SoundSource.cpp b/src/SFML/Audio/SoundSource.cpp index b2b4059d..001d3b3a 100644 --- a/src/SFML/Audio/SoundSource.cpp +++ b/src/SFML/Audio/SoundSource.cpp @@ -198,12 +198,12 @@ SoundSource::Status SoundSource::getStatus() const switch (status) { case AL_INITIAL: - case AL_STOPPED: return Stopped; - case AL_PAUSED: return Paused; - case AL_PLAYING: return Playing; + case AL_STOPPED: return Status::Stopped; + case AL_PAUSED: return Status::Paused; + case AL_PLAYING: return Status::Playing; } - return Stopped; + return Status::Stopped; } } // namespace sf diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index e6d6afc4..43d921fb 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -41,7 +41,7 @@ namespace sf //////////////////////////////////////////////////////////// SoundStream::SoundStream() : m_threadMutex (), -m_threadStartState(Stopped), +m_threadStartState(Status::Stopped), m_isStreaming (false), m_buffers (), m_channelCount (0), @@ -104,7 +104,7 @@ void SoundStream::play() } bool isStreaming = false; - Status threadStartState = Stopped; + Status threadStartState = Status::Stopped; { std::lock_guard lock(m_threadMutex); @@ -114,15 +114,15 @@ void SoundStream::play() } - if (isStreaming && (threadStartState == Paused)) + if (isStreaming && (threadStartState == Status::Paused)) { // If the sound is paused, resume it std::lock_guard lock(m_threadMutex); - m_threadStartState = Playing; + m_threadStartState = Status::Playing; alCheck(alSourcePlay(m_source)); return; } - else if (isStreaming && (threadStartState == Playing)) + else if (isStreaming && (threadStartState == Status::Playing)) { // If the sound is playing, stop it and continue as if it was stopped stop(); @@ -130,7 +130,7 @@ void SoundStream::play() // Start updating the stream in a separate thread to avoid blocking the application m_isStreaming = true; - m_threadStartState = Playing; + m_threadStartState = Status::Playing; m_thread = std::thread([this] { streamData(); @@ -148,7 +148,7 @@ void SoundStream::pause() if (!m_isStreaming) return; - m_threadStartState = Paused; + m_threadStartState = Status::Paused; } alCheck(alSourcePause(m_source)); @@ -196,7 +196,7 @@ SoundStream::Status SoundStream::getStatus() const Status status = SoundSource::getStatus(); // To compensate for the lag between play() and alSourceplay() - if (status == Stopped) + if (status == Status::Stopped) { std::lock_guard lock(m_threadMutex); @@ -223,7 +223,7 @@ void SoundStream::setPlayingOffset(Time timeOffset) // Restart streaming m_samplesProcessed = static_cast(timeOffset.asSeconds() * m_sampleRate * m_channelCount); - if (oldStatus == Stopped) + if (oldStatus == Status::Stopped) return; m_isStreaming = true; @@ -275,7 +275,7 @@ void SoundStream::streamData() std::lock_guard lock(m_threadMutex); // Check if the thread was launched Stopped - if (m_threadStartState == Stopped) + if (m_threadStartState == Status::Stopped) { m_isStreaming = false; return; @@ -297,7 +297,7 @@ void SoundStream::streamData() std::lock_guard lock(m_threadMutex); // Check if the thread was launched Paused - if (m_threadStartState == Paused) + if (m_threadStartState == Status::Paused) alCheck(alSourcePause(m_source)); } @@ -310,7 +310,7 @@ void SoundStream::streamData() } // The stream has been interrupted! - if (SoundSource::getStatus() == Stopped) + if (SoundSource::getStatus() == Status::Stopped) { if (!requestStop) { @@ -384,7 +384,7 @@ void SoundStream::streamData() } // Leave some time for the other threads if the stream is still playing - if (SoundSource::getStatus() != Stopped) + if (SoundSource::getStatus() != Status::Stopped) sleep(milliseconds(10)); } diff --git a/src/SFML/Graphics/BlendMode.cpp b/src/SFML/Graphics/BlendMode.cpp index ab69dcd3..a71d9668 100644 --- a/src/SFML/Graphics/BlendMode.cpp +++ b/src/SFML/Graphics/BlendMode.cpp @@ -33,22 +33,22 @@ namespace sf //////////////////////////////////////////////////////////// // Commonly used blending modes //////////////////////////////////////////////////////////// -const BlendMode BlendAlpha(BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, BlendMode::Add, - BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add); -const BlendMode BlendAdd(BlendMode::SrcAlpha, BlendMode::One, BlendMode::Add, - BlendMode::One, BlendMode::One, BlendMode::Add); -const BlendMode BlendMultiply(BlendMode::DstColor, BlendMode::Zero); -const BlendMode BlendNone(BlendMode::One, BlendMode::Zero); +const BlendMode BlendAlpha(BlendMode::Factor::SrcAlpha, BlendMode::Factor::OneMinusSrcAlpha, BlendMode::Equation::Add, + BlendMode::Factor::One, BlendMode::Factor::OneMinusSrcAlpha, BlendMode::Equation::Add); +const BlendMode BlendAdd(BlendMode::Factor::SrcAlpha, BlendMode::Factor::One, BlendMode::Equation::Add, + BlendMode::Factor::One, BlendMode::Factor::One, BlendMode::Equation::Add); +const BlendMode BlendMultiply(BlendMode::Factor::DstColor, BlendMode::Factor::Zero); +const BlendMode BlendNone(BlendMode::Factor::One, BlendMode::Factor::Zero); //////////////////////////////////////////////////////////// BlendMode::BlendMode() : -colorSrcFactor(BlendMode::SrcAlpha), -colorDstFactor(BlendMode::OneMinusSrcAlpha), -colorEquation (BlendMode::Add), -alphaSrcFactor(BlendMode::One), -alphaDstFactor(BlendMode::OneMinusSrcAlpha), -alphaEquation (BlendMode::Add) +colorSrcFactor(BlendMode::Factor::SrcAlpha), +colorDstFactor(BlendMode::Factor::OneMinusSrcAlpha), +colorEquation (BlendMode::Equation::Add), +alphaSrcFactor(BlendMode::Factor::One), +alphaDstFactor(BlendMode::Factor::OneMinusSrcAlpha), +alphaEquation (BlendMode::Equation::Add) { } diff --git a/src/SFML/Graphics/RenderStates.cpp b/src/SFML/Graphics/RenderStates.cpp index 01a0f09b..41d4465a 100644 --- a/src/SFML/Graphics/RenderStates.cpp +++ b/src/SFML/Graphics/RenderStates.cpp @@ -35,8 +35,8 @@ namespace sf // We cannot use the default constructor here, because it accesses BlendAlpha, which is also global (and dynamically // initialized). Initialization order of global objects in different translation units is not defined. const RenderStates RenderStates::Default(BlendMode( - BlendMode::SrcAlpha, BlendMode::OneMinusSrcAlpha, BlendMode::Add, - BlendMode::One, BlendMode::OneMinusSrcAlpha, BlendMode::Add)); + BlendMode::Factor::SrcAlpha, BlendMode::Factor::OneMinusSrcAlpha, BlendMode::Equation::Add, + BlendMode::Factor::One, BlendMode::Factor::OneMinusSrcAlpha, BlendMode::Equation::Add)); //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 0b5a6af1..bffab1ae 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -43,16 +43,16 @@ namespace { switch (blendFactor) { - case sf::BlendMode::Zero: return GL_ZERO; - case sf::BlendMode::One: return GL_ONE; - case sf::BlendMode::SrcColor: return GL_SRC_COLOR; - case sf::BlendMode::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR; - case sf::BlendMode::DstColor: return GL_DST_COLOR; - case sf::BlendMode::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR; - case sf::BlendMode::SrcAlpha: return GL_SRC_ALPHA; - case sf::BlendMode::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA; - case sf::BlendMode::DstAlpha: return GL_DST_ALPHA; - case sf::BlendMode::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA; + case sf::BlendMode::Factor::Zero: return GL_ZERO; + case sf::BlendMode::Factor::One: return GL_ONE; + case sf::BlendMode::Factor::SrcColor: return GL_SRC_COLOR; + case sf::BlendMode::Factor::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR; + case sf::BlendMode::Factor::DstColor: return GL_DST_COLOR; + case sf::BlendMode::Factor::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR; + case sf::BlendMode::Factor::SrcAlpha: return GL_SRC_ALPHA; + case sf::BlendMode::Factor::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA; + case sf::BlendMode::Factor::DstAlpha: return GL_DST_ALPHA; + case sf::BlendMode::Factor::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA; } sf::err() << "Invalid value for sf::BlendMode::Factor! Fallback to sf::BlendMode::Zero." << std::endl; @@ -66,9 +66,9 @@ namespace { switch (blendEquation) { - case sf::BlendMode::Add: return GLEXT_GL_FUNC_ADD; - case sf::BlendMode::Subtract: return GLEXT_GL_FUNC_SUBTRACT; - case sf::BlendMode::ReverseSubtract: return GLEXT_GL_FUNC_REVERSE_SUBTRACT; + case sf::BlendMode::Equation::Add: return GLEXT_GL_FUNC_ADD; + case sf::BlendMode::Equation::Subtract: return GLEXT_GL_FUNC_SUBTRACT; + case sf::BlendMode::Equation::ReverseSubtract: return GLEXT_GL_FUNC_REVERSE_SUBTRACT; } sf::err() << "Invalid value for sf::BlendMode::Equation! Fallback to sf::BlendMode::Add." << std::endl; @@ -282,7 +282,7 @@ void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, // Find the OpenGL primitive type constexpr GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS}; - GLenum mode = modes[type]; + GLenum mode = modes[static_cast(type)]; // Draw the primitives glCheck(glDrawArrays(mode, 0, vertexCount)); @@ -460,7 +460,7 @@ void RenderTarget::applyBlendMode(const BlendMode& mode) glCheck(GLEXT_glBlendEquation(equationToGlConstant(mode.colorEquation))); } } - else if ((mode.colorEquation != BlendMode::Add) || (mode.alphaEquation != BlendMode::Add)) + else if ((mode.colorEquation != BlendMode::Equation::Add) || (mode.alphaEquation != BlendMode::Equation::Add)) { static std::once_flag warned; std::call_once(warned, [] @@ -487,7 +487,7 @@ void RenderTarget::applyTransform(const Transform& transform) //////////////////////////////////////////////////////////// void RenderTarget::applyTexture(const Texture* texture) { - Texture::bind(texture, Texture::Pixels); + Texture::bind(texture, Texture::CoordinateType::Pixels); m_cache.lastTextureId = texture ? texture->m_cacheId : 0; } diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 86511d4e..4bdec8dd 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -227,9 +227,9 @@ bool Shader::loadFromFile(const std::string& filename, Type type) } // Compile the shader program - if (type == Vertex) + if (type == Type::Vertex) return compile(shader.data(), nullptr, nullptr); - else if (type == Geometry) + else if (type == Type::Geometry) return compile(nullptr, shader.data(), nullptr); else return compile(nullptr, nullptr, shader.data()); @@ -296,9 +296,9 @@ bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::st bool Shader::loadFromMemory(const std::string& shader, Type type) { // Compile the shader program - if (type == Vertex) + if (type == Type::Vertex) return compile(shader.c_str(), nullptr, nullptr); - else if (type == Geometry) + else if (type == Type::Geometry) return compile(nullptr, shader.c_str(), nullptr); else return compile(nullptr, nullptr, shader.c_str()); @@ -333,9 +333,9 @@ bool Shader::loadFromStream(InputStream& stream, Type type) } // Compile the shader program - if (type == Vertex) + if (type == Type::Vertex) return compile(shader.data(), nullptr, nullptr); - else if (type == Geometry) + else if (type == Type::Geometry) return compile(nullptr, shader.data(), nullptr); else return compile(nullptr, nullptr, shader.data()); diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index 634286c9..90a870d9 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -163,8 +163,8 @@ m_textureRect (), m_fillColor (255, 255, 255), m_outlineColor (255, 255, 255), m_outlineThickness(0), -m_vertices (TriangleFan), -m_outlineVertices (TriangleStrip), +m_vertices (PrimitiveType::TriangleFan), +m_outlineVertices (PrimitiveType::TriangleStrip), m_insideBounds (), m_bounds () { diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index bad0059a..aa509235 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -140,7 +140,7 @@ void Sprite::draw(RenderTarget& target, RenderStates states) const { states.transform *= getTransform(); states.texture = m_texture; - target.draw(m_vertices, 4, TriangleStrip, states); + target.draw(m_vertices, 4, PrimitiveType::TriangleStrip, states); } } diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index c830e0bd..579de64f 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -81,8 +81,8 @@ m_style (Regular), m_fillColor (255, 255, 255), m_outlineColor (0, 0, 0), m_outlineThickness (0), -m_vertices (Triangles), -m_outlineVertices (Triangles), +m_vertices (PrimitiveType::Triangles), +m_outlineVertices (PrimitiveType::Triangles), m_bounds (), m_geometryNeedUpdate(false) { @@ -99,8 +99,8 @@ m_style (Regular), m_fillColor (255, 255, 255), m_outlineColor (0, 0, 0), m_outlineThickness (0), -m_vertices (Triangles), -m_outlineVertices (Triangles), +m_vertices (PrimitiveType::Triangles), +m_outlineVertices (PrimitiveType::Triangles), m_bounds (), m_geometryNeedUpdate(true) { diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index bd066972..7ca3d765 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -717,7 +717,7 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType) glCheck(glBindTexture(GL_TEXTURE_2D, texture->m_texture)); // Check if we need to define a special texture matrix - if ((coordinateType == Pixels) || texture->m_pixelsFlipped) + if ((coordinateType == CoordinateType::Pixels) || texture->m_pixelsFlipped) { GLfloat matrix[16] = {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, @@ -726,7 +726,7 @@ void Texture::bind(const Texture* texture, CoordinateType coordinateType) // If non-normalized coordinates (= pixels) are requested, we need to // setup scale factors that convert the range [0 .. size] to [0 .. 1] - if (coordinateType == Pixels) + if (coordinateType == CoordinateType::Pixels) { matrix[0] = 1.f / texture->m_actualSize.x; matrix[5] = 1.f / texture->m_actualSize.y; diff --git a/src/SFML/Graphics/VertexArray.cpp b/src/SFML/Graphics/VertexArray.cpp index d64fa72a..b9d57039 100644 --- a/src/SFML/Graphics/VertexArray.cpp +++ b/src/SFML/Graphics/VertexArray.cpp @@ -34,7 +34,7 @@ namespace sf //////////////////////////////////////////////////////////// VertexArray::VertexArray() : m_vertices (), -m_primitiveType(Points) +m_primitiveType(PrimitiveType::Points) { } diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 7db2082a..a828921f 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -248,7 +248,7 @@ static void onResume(ANativeActivity* activity) // Send an event to warn people the activity has been resumed sf::Event event; - event.type = sf::Event::MouseEntered; + event.type = sf::Event::Type::MouseEntered; states->forwardEvent(event); } @@ -263,7 +263,7 @@ static void onPause(ANativeActivity* activity) // Send an event to warn people the activity has been paused sf::Event event; - event.type = sf::Event::MouseLeft; + event.type = sf::Event::Type::MouseLeft; states->forwardEvent(event); } @@ -290,7 +290,7 @@ static void onDestroy(ANativeActivity* activity) if (!states->mainOver) { sf::Event event; - event.type = sf::Event::Closed; + event.type = sf::Event::Type::Closed; states->forwardEvent(event); } @@ -332,7 +332,7 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind // Notify SFML mechanism sf::Event event; - event.type = sf::Event::GainedFocus; + event.type = sf::Event::Type::GainedFocus; states->forwardEvent(event); // Wait for the event to be taken into account by SFML @@ -357,7 +357,7 @@ static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* wi // Notify SFML mechanism sf::Event event; - event.type = sf::Event::LostFocus; + event.type = sf::Event::Type::LostFocus; states->forwardEvent(event); // Wait for the event to be taken into account by SFML @@ -432,7 +432,7 @@ static void onContentRectChanged(ANativeActivity* activity, const ARect* rect) if (states->window != nullptr) { // Send an event to warn people about the window move/resize sf::Event event; - event.type = sf::Event::Resized; + event.type = sf::Event::Type::Resized; event.size.width = ANativeWindow_getWidth(states->window); event.size.height = ANativeWindow_getHeight(states->window); @@ -476,7 +476,7 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_ states->inputQueue = nullptr; states->config = nullptr; - for (unsigned int i = 0; i < sf::Mouse::ButtonCount; i++) + for (auto i = 0u; i < static_cast(sf::Mouse::Button::Count); i++) states->isButtonPressed[i] = false; states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index 1882da86..275cb79f 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -77,7 +77,7 @@ m_message(message) //////////////////////////////////////////////////////////// bool Ftp::Response::isOk() const { - return m_status < 400; + return static_cast(m_status) < 400; } @@ -151,8 +151,8 @@ Ftp::~Ftp() Ftp::Response Ftp::connect(const IpAddress& server, unsigned short port, Time timeout) { // Connect to the server - if (m_commandSocket.connect(server, port, timeout) != Socket::Done) - return Response(Response::ConnectionFailed); + if (m_commandSocket.connect(server, port, timeout) != Socket::Status::Done) + return Response(Response::Status::ConnectionFailed); // Get the response to the connection return getResponse(); @@ -209,7 +209,7 @@ Ftp::ListingResponse Ftp::getDirectoryListing(const std::string& directory) // Open a data channel on default port (20) using ASCII transfer mode std::ostringstream directoryData; DataChannel data(*this); - Response response = data.open(Ascii); + Response response = data.open(TransferMode::Ascii); if (response.isOk()) { // Tell the server to send us the listing @@ -300,7 +300,7 @@ Ftp::Response Ftp::download(const std::string& remoteFile, const std::string& lo // Create the file and truncate it if necessary std::ofstream file((path + filename).c_str(), std::ios_base::binary | std::ios_base::trunc); if (!file) - return Response(Response::InvalidFile); + return Response(Response::Status::InvalidFile); // Receive the file data data.receive(file); @@ -327,7 +327,7 @@ Ftp::Response Ftp::upload(const std::string& localFile, const std::string& remot // Get the contents of the file to send std::ifstream file(localFile.c_str(), std::ios_base::binary); if (!file) - return Response(Response::InvalidFile); + return Response(Response::Status::InvalidFile); // Extract the filename from the file path std::string filename = localFile; @@ -372,8 +372,8 @@ Ftp::Response Ftp::sendCommand(const std::string& command, const std::string& pa commandStr = command + "\r\n"; // Send it to the server - if (m_commandSocket.send(commandStr.c_str(), commandStr.length()) != Socket::Done) - return Response(Response::ConnectionClosed); + if (m_commandSocket.send(commandStr.c_str(), commandStr.length()) != Socket::Status::Done) + return Response(Response::Status::ConnectionClosed); // Get the response return getResponse(); @@ -398,8 +398,8 @@ Ftp::Response Ftp::getResponse() if (m_receiveBuffer.empty()) { - if (m_commandSocket.receive(buffer, sizeof(buffer), length) != Socket::Done) - return Response(Response::ConnectionClosed); + if (m_commandSocket.receive(buffer, sizeof(buffer), length) != Socket::Status::Done) + return Response(Response::Status::ConnectionClosed); } else { @@ -513,7 +513,7 @@ Ftp::Response Ftp::getResponse() else { // Error: cannot extract the code, and we are not in a multiline response - return Response(Response::InvalidResponse); + return Response(Response::Status::InvalidResponse); } } } @@ -565,15 +565,15 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode) static_cast(data[3])); // Connect the data channel to the server - if (m_dataSocket.connect(address, port) == Socket::Done) + if (m_dataSocket.connect(address, port) == Socket::Status::Done) { // Translate the transfer mode to the corresponding FTP parameter std::string modeStr; switch (mode) { - case Ftp::Binary: modeStr = "I"; break; - case Ftp::Ascii: modeStr = "A"; break; - case Ftp::Ebcdic: modeStr = "E"; break; + case Ftp::TransferMode::Binary: modeStr = "I"; break; + case Ftp::TransferMode::Ascii: modeStr = "A"; break; + case Ftp::TransferMode::Ebcdic: modeStr = "E"; break; } // Set the transfer mode @@ -582,7 +582,7 @@ Ftp::Response Ftp::DataChannel::open(Ftp::TransferMode mode) else { // Failed to connect to the server - response = Ftp::Response(Ftp::Response::ConnectionFailed); + response = Ftp::Response(Ftp::Response::Status::ConnectionFailed); } } } @@ -597,7 +597,7 @@ void Ftp::DataChannel::receive(std::ostream& stream) // Receive data char buffer[1024]; std::size_t received; - while (m_dataSocket.receive(buffer, sizeof(buffer), received) == Socket::Done) + while (m_dataSocket.receive(buffer, sizeof(buffer), received) == Socket::Status::Done) { stream.write(buffer, static_cast(received)); @@ -636,7 +636,7 @@ void Ftp::DataChannel::send(std::istream& stream) if (count > 0) { // we could read more data from the stream: send them - if (m_dataSocket.send(buffer, count) != Socket::Done) + if (m_dataSocket.send(buffer, count) != Socket::Status::Done) break; } else diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index 3d0bd3d7..fe9446c5 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -106,11 +106,11 @@ std::string Http::Request::prepare() const std::string method; switch (m_method) { - case Get: method = "GET"; break; - case Post: method = "POST"; break; - case Head: method = "HEAD"; break; - case Put: method = "PUT"; break; - case Delete: method = "DELETE"; break; + case Method::Get: method = "GET"; break; + case Method::Post: method = "POST"; break; + case Method::Head: method = "HEAD"; break; + case Method::Put: method = "PUT"; break; + case Method::Delete: method = "DELETE"; break; } // Write the first line containing the request type @@ -142,7 +142,7 @@ bool Http::Request::hasField(const std::string& field) const //////////////////////////////////////////////////////////// Http::Response::Response() : -m_status (ConnectionFailed), +m_status (Status::ConnectionFailed), m_majorVersion(0), m_minorVersion(0) { @@ -213,7 +213,7 @@ void Http::Response::parse(const std::string& data) else { // Invalid HTTP version - m_status = InvalidResponse; + m_status = Status::InvalidResponse; return; } } @@ -227,7 +227,7 @@ void Http::Response::parse(const std::string& data) else { // Invalid status code - m_status = InvalidResponse; + m_status = Status::InvalidResponse; return; } @@ -367,7 +367,7 @@ Http::Response Http::sendRequest(const Http::Request& request, Time timeout) out << toSend.m_body.size(); toSend.setField("Content-Length", out.str()); } - if ((toSend.m_method == Request::Post) && !toSend.hasField("Content-Type")) + if ((toSend.m_method == Request::Method::Post) && !toSend.hasField("Content-Type")) { toSend.setField("Content-Type", "application/x-www-form-urlencoded"); } @@ -380,7 +380,7 @@ Http::Response Http::sendRequest(const Http::Request& request, Time timeout) Response received; // Connect the socket to the host - if (m_connection.connect(m_host, m_port, timeout) == Socket::Done) + if (m_connection.connect(m_host, m_port, timeout) == Socket::Status::Done) { // Convert the request to string and send it through the connected socket std::string requestStr = toSend.prepare(); @@ -388,13 +388,13 @@ Http::Response Http::sendRequest(const Http::Request& request, Time timeout) if (!requestStr.empty()) { // Send it through the socket - if (m_connection.send(requestStr.c_str(), requestStr.size()) == Socket::Done) + if (m_connection.send(requestStr.c_str(), requestStr.size()) == Socket::Status::Done) { // Wait for the server's response std::string receivedStr; std::size_t size = 0; char buffer[1024]; - while (m_connection.receive(buffer, sizeof(buffer), size) == Socket::Done) + while (m_connection.receive(buffer, sizeof(buffer), size) == Socket::Status::Done) { receivedStr.append(buffer, buffer + size); } diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 923e5c53..fbeeebe1 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -150,9 +150,9 @@ IpAddress IpAddress::getPublicAddress(Time timeout) // (not very hard: the web page contains only our IP address). Http server("www.sfml-dev.org"); - Http::Request request("/ip-provider.php", Http::Request::Get); + Http::Request request("/ip-provider.php", Http::Request::Method::Get); Http::Response page = server.sendRequest(request, timeout); - if (page.getStatus() == Http::Response::Ok) + if (page.getStatus() == Http::Response::Status::Ok) return IpAddress(page.getBody()); // Something failed: return an invalid address diff --git a/src/SFML/Network/Socket.cpp b/src/SFML/Network/Socket.cpp index ad6d9930..30db4d85 100644 --- a/src/SFML/Network/Socket.cpp +++ b/src/SFML/Network/Socket.cpp @@ -81,7 +81,7 @@ void Socket::create() // Don't create the socket if it already exists if (m_socket == priv::SocketImpl::invalidSocket()) { - SocketHandle handle = socket(PF_INET, m_type == Tcp ? SOCK_STREAM : SOCK_DGRAM, 0); + SocketHandle handle = socket(PF_INET, m_type == Type::Tcp ? SOCK_STREAM : SOCK_DGRAM, 0); if (handle == priv::SocketImpl::invalidSocket()) { @@ -106,7 +106,7 @@ void Socket::create(SocketHandle handle) // Set the current blocking state setBlocking(m_isBlocking); - if (m_type == Tcp) + if (m_type == Type::Tcp) { // Disable the Nagle algorithm (i.e. removes buffering of TCP packets) int yes = 1; diff --git a/src/SFML/Network/TcpListener.cpp b/src/SFML/Network/TcpListener.cpp index 713301e1..d1caf230 100644 --- a/src/SFML/Network/TcpListener.cpp +++ b/src/SFML/Network/TcpListener.cpp @@ -35,7 +35,7 @@ namespace sf { //////////////////////////////////////////////////////////// TcpListener::TcpListener() : -Socket(Tcp) +Socket(Type::Tcp) { } @@ -68,7 +68,7 @@ Socket::Status TcpListener::listen(unsigned short port, const IpAddress& address // Check if the address is valid if ((address == IpAddress::None) || (address == IpAddress::Broadcast)) - return Error; + return Status::Error; // Bind the socket to the specified port sockaddr_in addr = priv::SocketImpl::createAddress(address.toInteger(), port); @@ -76,7 +76,7 @@ Socket::Status TcpListener::listen(unsigned short port, const IpAddress& address { // Not likely to happen, but... err() << "Failed to bind listener socket to port " << port << std::endl; - return Error; + return Status::Error; } // Listen to the bound port @@ -84,10 +84,10 @@ Socket::Status TcpListener::listen(unsigned short port, const IpAddress& address { // Oops, socket is deaf err() << "Failed to listen to port " << port << std::endl; - return Error; + return Status::Error; } - return Done; + return Status::Done; } @@ -106,7 +106,7 @@ Socket::Status TcpListener::accept(TcpSocket& socket) if (getHandle() == priv::SocketImpl::invalidSocket()) { err() << "Failed to accept a new connection, the socket is not listening" << std::endl; - return Error; + return Status::Error; } // Accept a new connection @@ -122,7 +122,7 @@ Socket::Status TcpListener::accept(TcpSocket& socket) socket.close(); socket.create(remote); - return Done; + return Status::Done; } } // namespace sf diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index 944ca79b..ea01f34f 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -52,7 +52,7 @@ namespace sf { //////////////////////////////////////////////////////////// TcpSocket::TcpSocket() : -Socket(Tcp) +Socket(Type::Tcp) { } @@ -133,7 +133,7 @@ Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short return priv::SocketImpl::getErrorStatus(); // Connection succeeded - return Done; + return Status::Done; } else { @@ -151,7 +151,7 @@ Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short { // We got instantly connected! (it may no happen a lot...) setBlocking(blocking); - return Done; + return Status::Done; } // Get the error status @@ -162,7 +162,7 @@ Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short return status; // Otherwise, wait until something happens to our socket (success, timeout or error) - if (status == Socket::NotReady) + if (status == Status::NotReady) { // Setup the selector fd_set selector; @@ -182,7 +182,7 @@ Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short if (getRemoteAddress() != IpAddress::None) { // Connection accepted - status = Done; + status = Status::Done; } else { @@ -235,7 +235,7 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size, std::size_t& if (!data || (size == 0)) { err() << "Cannot send data over the network (no data to send)" << std::endl; - return Error; + return Status::Error; } // Loop until every byte has been sent @@ -250,14 +250,14 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size, std::size_t& { Status status = priv::SocketImpl::getErrorStatus(); - if ((status == NotReady) && sent) - return Partial; + if ((status == Status::NotReady) && sent) + return Status::Partial; return status; } } - return Done; + return Status::Done; } @@ -271,7 +271,7 @@ Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& rec if (!data) { err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl; - return Error; + return Status::Error; } // Receive a chunk of bytes @@ -281,11 +281,11 @@ Socket::Status TcpSocket::receive(void* data, std::size_t size, std::size_t& rec if (sizeReceived > 0) { received = static_cast(sizeReceived); - return Done; + return Status::Done; } else if (sizeReceived == 0) { - return Socket::Disconnected; + return Status::Disconnected; } else { @@ -326,11 +326,11 @@ Socket::Status TcpSocket::send(Packet& packet) Status status = send(blockToSend.data() + packet.m_sendPos, blockToSend.size() - packet.m_sendPos, sent); // In the case of a partial send, record the location to resume from - if (status == Partial) + if (status == Status::Partial) { packet.m_sendPos += sent; } - else if (status == Done) + else if (status == Status::Done) { packet.m_sendPos = 0; } @@ -358,7 +358,7 @@ Socket::Status TcpSocket::receive(Packet& packet) Status status = receive(data, sizeof(m_pendingPacket.Size) - m_pendingPacket.SizeReceived, received); m_pendingPacket.SizeReceived += received; - if (status != Done) + if (status != Status::Done) return status; } @@ -378,7 +378,7 @@ Socket::Status TcpSocket::receive(Packet& packet) // Receive a chunk of data std::size_t sizeToGet = std::min(static_cast(packetSize - m_pendingPacket.Data.size()), sizeof(buffer)); Status status = receive(buffer, sizeToGet, received); - if (status != Done) + if (status != Status::Done) return status; // Append it into the packet @@ -397,7 +397,7 @@ Socket::Status TcpSocket::receive(Packet& packet) // Clear the pending packet data m_pendingPacket = PendingPacket(); - return Done; + return Status::Done; } diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index 29ba0982..3d1170c9 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -37,7 +37,7 @@ namespace sf { //////////////////////////////////////////////////////////// UdpSocket::UdpSocket() : -Socket (Udp), +Socket (Type::Udp), m_buffer(MaxDatagramSize) { @@ -71,17 +71,17 @@ Socket::Status UdpSocket::bind(unsigned short port, const IpAddress& address) // Check if the address is valid if ((address == IpAddress::None) || (address == IpAddress::Broadcast)) - return Error; + return Status::Error; // Bind the socket sockaddr_in addr = priv::SocketImpl::createAddress(address.toInteger(), port); if (::bind(getHandle(), reinterpret_cast(&addr), sizeof(addr)) == -1) { err() << "Failed to bind socket to port " << port << std::endl; - return Error; + return Status::Error; } - return Done; + return Status::Done; } @@ -104,7 +104,7 @@ Socket::Status UdpSocket::send(const void* data, std::size_t size, const IpAddre { err() << "Cannot send data over the network " << "(the number of bytes to send is greater than sf::UdpSocket::MaxDatagramSize)" << std::endl; - return Error; + return Status::Error; } // Build the target address @@ -117,7 +117,7 @@ Socket::Status UdpSocket::send(const void* data, std::size_t size, const IpAddre if (sent < 0) return priv::SocketImpl::getErrorStatus(); - return Done; + return Status::Done; } @@ -133,7 +133,7 @@ Socket::Status UdpSocket::receive(void* data, std::size_t size, std::size_t& rec if (!data) { err() << "Cannot receive data from the network (the destination buffer is invalid)" << std::endl; - return Error; + return Status::Error; } // Data that will be filled with the other computer's address @@ -152,7 +152,7 @@ Socket::Status UdpSocket::receive(void* data, std::size_t size, std::size_t& rec remoteAddress = IpAddress(ntohl(address.sin_addr.s_addr)); remotePort = ntohs(address.sin_port); - return Done; + return Status::Done; } @@ -187,7 +187,7 @@ Socket::Status UdpSocket::receive(Packet& packet, IpAddress& remoteAddress, unsi // If we received valid data, we can copy it to the user packet packet.clear(); - if ((status == Done) && (received > 0)) + if ((status == Status::Done) && (received > 0)) packet.onReceive(m_buffer.data(), received); return status; diff --git a/src/SFML/Network/Unix/SocketImpl.cpp b/src/SFML/Network/Unix/SocketImpl.cpp index 0c1457f8..9536c31e 100644 --- a/src/SFML/Network/Unix/SocketImpl.cpp +++ b/src/SFML/Network/Unix/SocketImpl.cpp @@ -92,18 +92,18 @@ Socket::Status SocketImpl::getErrorStatus() // so we have to make a special case for them in order // to avoid having double values in the switch case if ((errno == EAGAIN) || (errno == EINPROGRESS)) - return Socket::NotReady; + return Socket::Status::NotReady; switch (errno) { - case EWOULDBLOCK: return Socket::NotReady; - case ECONNABORTED: return Socket::Disconnected; - case ECONNRESET: return Socket::Disconnected; - case ETIMEDOUT: return Socket::Disconnected; - case ENETRESET: return Socket::Disconnected; - case ENOTCONN: return Socket::Disconnected; - case EPIPE: return Socket::Disconnected; - default: return Socket::Error; + case EWOULDBLOCK: return Socket::Status::NotReady; + case ECONNABORTED: return Socket::Status::Disconnected; + case ECONNRESET: return Socket::Status::Disconnected; + case ETIMEDOUT: return Socket::Status::Disconnected; + case ENETRESET: return Socket::Status::Disconnected; + case ENOTCONN: return Socket::Status::Disconnected; + case EPIPE: return Socket::Status::Disconnected; + default: return Socket::Status::Error; } } diff --git a/src/SFML/Network/Win32/SocketImpl.cpp b/src/SFML/Network/Win32/SocketImpl.cpp index 0e9f6ae2..19f20005 100644 --- a/src/SFML/Network/Win32/SocketImpl.cpp +++ b/src/SFML/Network/Win32/SocketImpl.cpp @@ -73,15 +73,15 @@ Socket::Status SocketImpl::getErrorStatus() { switch (WSAGetLastError()) { - case WSAEWOULDBLOCK: return Socket::NotReady; - case WSAEALREADY: return Socket::NotReady; - case WSAECONNABORTED: return Socket::Disconnected; - case WSAECONNRESET: return Socket::Disconnected; - case WSAETIMEDOUT: return Socket::Disconnected; - case WSAENETRESET: return Socket::Disconnected; - case WSAENOTCONN: return Socket::Disconnected; - case WSAEISCONN: return Socket::Done; // when connecting a non-blocking socket - default: return Socket::Error; + case WSAEWOULDBLOCK: return Socket::Status::NotReady; + case WSAEALREADY: return Socket::Status::NotReady; + case WSAECONNABORTED: return Socket::Status::Disconnected; + case WSAECONNRESET: return Socket::Status::Disconnected; + case WSAETIMEDOUT: return Socket::Status::Disconnected; + case WSAENETRESET: return Socket::Status::Disconnected; + case WSAENOTCONN: return Socket::Status::Disconnected; + case WSAEISCONN: return Socket::Status::Done; // when connecting a non-blocking socket + default: return Socket::Status::Error; } } diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp index 94df7afd..422c697e 100644 --- a/src/SFML/System/Android/Activity.hpp +++ b/src/SFML/System/Android/Activity.hpp @@ -76,7 +76,7 @@ struct ActivityStates std::map touchEvents; Vector2i mousePosition; - bool isButtonPressed[Mouse::ButtonCount]; + bool isButtonPressed[static_cast(Mouse::Button::Count)]; bool mainOver; diff --git a/src/SFML/Window/Android/InputImpl.cpp b/src/SFML/Window/Android/InputImpl.cpp index 1ab1e1f0..fbe9f288 100644 --- a/src/SFML/Window/Android/InputImpl.cpp +++ b/src/SFML/Window/Android/InputImpl.cpp @@ -141,7 +141,7 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) priv::ActivityStates* states = priv::getActivity(nullptr); std::lock_guard lock(states->mutex); - return states->isButtonPressed[button]; + return states->isButtonPressed[static_cast(button)]; } diff --git a/src/SFML/Window/Android/SensorImpl.cpp b/src/SFML/Window/Android/SensorImpl.cpp index 902a410f..b38dec2e 100644 --- a/src/SFML/Window/Android/SensorImpl.cpp +++ b/src/SFML/Window/Android/SensorImpl.cpp @@ -137,7 +137,7 @@ ASensor const* SensorImpl::getDefaultSensor(Sensor::Type sensor) ASENSOR_TYPE_MAGNETIC_FIELD, ASENSOR_TYPE_GRAVITY, ASENSOR_TYPE_LINEAR_ACCELERATION, ASENSOR_TYPE_ORIENTATION}; - int type = types[sensor]; + int type = types[static_cast(sensor)]; // Retrieve the default sensor matching this type return ASensorManager_getDefaultSensor(sensorManager, type); @@ -151,48 +151,48 @@ int SensorImpl::processSensorEvents(int fd, int events, void* data) while (ASensorEventQueue_getEvents(sensorEventQueue, &event, 1) > 0) { - unsigned int type = Sensor::Count; + unsigned int type = Sensor::Type::Count; Vector3f data; switch (event.type) { case ASENSOR_TYPE_ACCELEROMETER: - type = Sensor::Accelerometer; + type = Sensor::Type::Accelerometer; data.x = event.acceleration.x; data.y = event.acceleration.y; data.z = event.acceleration.z; break; case ASENSOR_TYPE_GYROSCOPE: - type = Sensor::Gyroscope; + type = Sensor::Type::Gyroscope; data.x = event.vector.x; data.y = event.vector.y; data.z = event.vector.z; break; case ASENSOR_TYPE_MAGNETIC_FIELD: - type = Sensor::Magnetometer; + type = Sensor::Type::Magnetometer; data.x = event.magnetic.x; data.y = event.magnetic.y; data.z = event.magnetic.z; break; case ASENSOR_TYPE_GRAVITY: - type = Sensor::Gravity; + type = Sensor::Type::Gravity; data.x = event.vector.x; data.y = event.vector.y; data.z = event.vector.z; break; case ASENSOR_TYPE_LINEAR_ACCELERATION: - type = Sensor::UserAcceleration; + type = Sensor::Type::UserAcceleration; data.x = event.acceleration.x; data.y = event.acceleration.y; data.z = event.acceleration.z; break; case ASENSOR_TYPE_ORIENTATION: - type = Sensor::Orientation; + type = Sensor::Type::Orientation; data.x = event.vector.x; data.y = event.vector.y; data.z = event.vector.z; @@ -200,7 +200,7 @@ int SensorImpl::processSensorEvents(int fd, int events, void* data) } // An unknown sensor event has been detected, we don't know how to process it - if (type == Sensor::Count) + if (type == Sensor::Type::Count) continue; sensorData[type] = data; diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index 5c0f4305..62d56ed0 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -211,14 +211,14 @@ void WindowImplAndroid::forwardEvent(const Event& event) { ActivityStates* states = getActivity(nullptr); - if (event.type == Event::GainedFocus) + if (event.type == Event::Type::GainedFocus) { WindowImplAndroid::singleInstance->m_size.x = ANativeWindow_getWidth(states->window); WindowImplAndroid::singleInstance->m_size.y = ANativeWindow_getHeight(states->window); WindowImplAndroid::singleInstance->m_windowBeingCreated = true; WindowImplAndroid::singleInstance->m_hasFocus = true; } - else if (event.type == Event::LostFocus) + else if (event.type == Event::Type::LostFocus) { WindowImplAndroid::singleInstance->m_windowBeingDestroyed = true; WindowImplAndroid::singleInstance->m_hasFocus = false; @@ -352,7 +352,7 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates* s // Create and send our mouse wheel event Event event; - event.type = Event::MouseWheelMoved; + event.type = Event::Type::MouseWheelMoved; event.mouseWheel.delta = static_cast(delta); event.mouseWheel.x = AMotionEvent_getX(_event, 0); event.mouseWheel.y = AMotionEvent_getY(_event, 0); @@ -384,16 +384,16 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates* stat switch (action) { case AKEY_EVENT_ACTION_DOWN: - event.type = Event::KeyPressed; + event.type = Event::Type::KeyPressed; forwardEvent(event); return 1; case AKEY_EVENT_ACTION_UP: - event.type = Event::KeyReleased; + event.type = Event::Type::KeyReleased; forwardEvent(event); if (int unicode = getUnicode(_event)) { - event.type = Event::TextEntered; + event.type = Event::Type::TextEntered; event.text.unicode = unicode; forwardEvent(event); } @@ -401,9 +401,9 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates* stat case AKEY_EVENT_ACTION_MULTIPLE: // Since complex inputs don't get separate key down/up events // both have to be faked at once - event.type = Event::KeyPressed; + event.type = Event::Type::KeyPressed; forwardEvent(event); - event.type = Event::KeyReleased; + event.type = Event::Type::KeyReleased; forwardEvent(event); // This requires some special treatment, since this might represent @@ -416,7 +416,7 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates* stat } else if (int unicode = getUnicode(_event)) // This is a repeated sequence { - event.type = Event::TextEntered; + event.type = Event::Type::TextEntered; event.text.unicode = unicode; int32_t repeats = AKeyEvent_getRepeatCount(_event); @@ -439,9 +439,9 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates* s Event event; if (device == AINPUT_SOURCE_MOUSE) - event.type = Event::MouseMoved; + event.type = Event::Type::MouseMoved; else if (device & AINPUT_SOURCE_TOUCHSCREEN) - event.type = Event::TouchMoved; + event.type = Event::Type::TouchMoved; int pointerCount = AMotionEvent_getPointerCount(_event); @@ -495,17 +495,17 @@ int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Act { if (device == AINPUT_SOURCE_MOUSE) { - event.type = Event::MouseButtonPressed; + event.type = Event::Type::MouseButtonPressed; event.mouseButton.button = static_cast(id); event.mouseButton.x = x; event.mouseButton.y = y; - if (id >= 0 && id < Mouse::ButtonCount) + if (id >= 0 && id < Mouse::Button::Count) states->isButtonPressed[id] = true; } else if (device & AINPUT_SOURCE_TOUCHSCREEN) { - event.type = Event::TouchBegan; + event.type = Event::Type::TouchBegan; event.touch.finger = id; event.touch.x = x; event.touch.y = y; @@ -517,17 +517,17 @@ int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Act { if (device == AINPUT_SOURCE_MOUSE) { - event.type = Event::MouseButtonReleased; + event.type = Event::Type::MouseButtonReleased; event.mouseButton.button = static_cast(id); event.mouseButton.x = x; event.mouseButton.y = y; - if (id >= 0 && id < Mouse::ButtonCount) + if (id >= 0 && id < Mouse::Button::Count) states->isButtonPressed[id] = false; } else if (device & AINPUT_SOURCE_TOUCHSCREEN) { - event.type = Event::TouchEnded; + event.type = Event::Type::TouchEnded; event.touch.finger = id; event.touch.x = x; event.touch.y = y; @@ -549,20 +549,20 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(int32_t key) case AKEYCODE_UNKNOWN: case AKEYCODE_SOFT_LEFT: case AKEYCODE_SOFT_RIGHT: - case AKEYCODE_HOME: return Keyboard::Unknown; - case AKEYCODE_BACK: return Keyboard::Escape; + case AKEYCODE_HOME: return Keyboard::Key::Unknown; + case AKEYCODE_BACK: return Keyboard::Key::Escape; case AKEYCODE_CALL: - case AKEYCODE_ENDCALL: return Keyboard::Unknown; - case AKEYCODE_0: return Keyboard::Num0; - case AKEYCODE_1: return Keyboard::Num1; - case AKEYCODE_2: return Keyboard::Num2; - case AKEYCODE_3: return Keyboard::Num3; - case AKEYCODE_4: return Keyboard::Num4; - case AKEYCODE_5: return Keyboard::Num5; - case AKEYCODE_6: return Keyboard::Num6; - case AKEYCODE_7: return Keyboard::Num7; - case AKEYCODE_8: return Keyboard::Num8; - case AKEYCODE_9: return Keyboard::Num9; + case AKEYCODE_ENDCALL: return Keyboard::Key::Unknown; + case AKEYCODE_0: return Keyboard::Key::Num0; + case AKEYCODE_1: return Keyboard::Key::Num1; + case AKEYCODE_2: return Keyboard::Key::Num2; + case AKEYCODE_3: return Keyboard::Key::Num3; + case AKEYCODE_4: return Keyboard::Key::Num4; + case AKEYCODE_5: return Keyboard::Key::Num5; + case AKEYCODE_6: return Keyboard::Key::Num6; + case AKEYCODE_7: return Keyboard::Key::Num7; + case AKEYCODE_8: return Keyboard::Key::Num8; + case AKEYCODE_9: return Keyboard::Key::Num9; case AKEYCODE_STAR: case AKEYCODE_POUND: case AKEYCODE_DPAD_UP: @@ -574,55 +574,55 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(int32_t key) case AKEYCODE_VOLUME_DOWN: case AKEYCODE_POWER: case AKEYCODE_CAMERA: - case AKEYCODE_CLEAR: return Keyboard::Unknown; - case AKEYCODE_A: return Keyboard::A; - case AKEYCODE_B: return Keyboard::B; - case AKEYCODE_C: return Keyboard::C; - case AKEYCODE_D: return Keyboard::D; - case AKEYCODE_E: return Keyboard::E; - case AKEYCODE_F: return Keyboard::F; - case AKEYCODE_G: return Keyboard::G; - case AKEYCODE_H: return Keyboard::H; - case AKEYCODE_I: return Keyboard::I; - case AKEYCODE_J: return Keyboard::J; - case AKEYCODE_K: return Keyboard::K; - case AKEYCODE_L: return Keyboard::L; - case AKEYCODE_M: return Keyboard::M; - case AKEYCODE_N: return Keyboard::N; - case AKEYCODE_O: return Keyboard::O; - case AKEYCODE_P: return Keyboard::P; - case AKEYCODE_Q: return Keyboard::Q; - case AKEYCODE_R: return Keyboard::R; - case AKEYCODE_S: return Keyboard::S; - case AKEYCODE_T: return Keyboard::T; - case AKEYCODE_U: return Keyboard::U; - case AKEYCODE_V: return Keyboard::V; - case AKEYCODE_W: return Keyboard::W; - case AKEYCODE_X: return Keyboard::X; - case AKEYCODE_Y: return Keyboard::Y; - case AKEYCODE_Z: return Keyboard::Z; - case AKEYCODE_COMMA: return Keyboard::Comma; - case AKEYCODE_PERIOD: return Keyboard::Period; - case AKEYCODE_ALT_LEFT: return Keyboard::LAlt; - case AKEYCODE_ALT_RIGHT: return Keyboard::RAlt; - case AKEYCODE_SHIFT_LEFT: return Keyboard::LShift; - case AKEYCODE_SHIFT_RIGHT: return Keyboard::RShift; - case AKEYCODE_TAB: return Keyboard::Tab; - case AKEYCODE_SPACE: return Keyboard::Space; + case AKEYCODE_CLEAR: return Keyboard::Key::Unknown; + case AKEYCODE_A: return Keyboard::Key::A; + case AKEYCODE_B: return Keyboard::Key::B; + case AKEYCODE_C: return Keyboard::Key::C; + case AKEYCODE_D: return Keyboard::Key::D; + case AKEYCODE_E: return Keyboard::Key::E; + case AKEYCODE_F: return Keyboard::Key::F; + case AKEYCODE_G: return Keyboard::Key::G; + case AKEYCODE_H: return Keyboard::Key::H; + case AKEYCODE_I: return Keyboard::Key::I; + case AKEYCODE_J: return Keyboard::Key::J; + case AKEYCODE_K: return Keyboard::Key::K; + case AKEYCODE_L: return Keyboard::Key::L; + case AKEYCODE_M: return Keyboard::Key::M; + case AKEYCODE_N: return Keyboard::Key::N; + case AKEYCODE_O: return Keyboard::Key::O; + case AKEYCODE_P: return Keyboard::Key::P; + case AKEYCODE_Q: return Keyboard::Key::Q; + case AKEYCODE_R: return Keyboard::Key::R; + case AKEYCODE_S: return Keyboard::Key::S; + case AKEYCODE_T: return Keyboard::Key::T; + case AKEYCODE_U: return Keyboard::Key::U; + case AKEYCODE_V: return Keyboard::Key::V; + case AKEYCODE_W: return Keyboard::Key::W; + case AKEYCODE_X: return Keyboard::Key::X; + case AKEYCODE_Y: return Keyboard::Key::Y; + case AKEYCODE_Z: return Keyboard::Key::Z; + case AKEYCODE_COMMA: return Keyboard::Key::Comma; + case AKEYCODE_PERIOD: return Keyboard::Key::Period; + case AKEYCODE_ALT_LEFT: return Keyboard::Key::LAlt; + case AKEYCODE_ALT_RIGHT: return Keyboard::Key::RAlt; + case AKEYCODE_SHIFT_LEFT: return Keyboard::Key::LShift; + case AKEYCODE_SHIFT_RIGHT: return Keyboard::Key::RShift; + case AKEYCODE_TAB: return Keyboard::Key::Tab; + case AKEYCODE_SPACE: return Keyboard::Key::Space; case AKEYCODE_SYM: case AKEYCODE_EXPLORER: - case AKEYCODE_ENVELOPE: return Keyboard::Unknown; - case AKEYCODE_ENTER: return Keyboard::Return; - case AKEYCODE_DEL: return Keyboard::Delete; - case AKEYCODE_GRAVE: return Keyboard::Tilde; - case AKEYCODE_MINUS: return Keyboard::Subtract; - case AKEYCODE_EQUALS: return Keyboard::Equal; - case AKEYCODE_LEFT_BRACKET: return Keyboard::LBracket; - case AKEYCODE_RIGHT_BRACKET: return Keyboard::RBracket; - case AKEYCODE_BACKSLASH: return Keyboard::BackSlash; - case AKEYCODE_SEMICOLON: return Keyboard::SemiColon; - case AKEYCODE_APOSTROPHE: return Keyboard::Quote; - case AKEYCODE_SLASH: return Keyboard::Slash; + case AKEYCODE_ENVELOPE: return Keyboard::Key::Unknown; + case AKEYCODE_ENTER: return Keyboard::Key::Return; + case AKEYCODE_DEL: return Keyboard::Key::Delete; + case AKEYCODE_GRAVE: return Keyboard::Key::Tilde; + case AKEYCODE_MINUS: return Keyboard::Key::Subtract; + case AKEYCODE_EQUALS: return Keyboard::Key::Equal; + case AKEYCODE_LEFT_BRACKET: return Keyboard::Key::LBracket; + case AKEYCODE_RIGHT_BRACKET: return Keyboard::Key::RBracket; + case AKEYCODE_BACKSLASH: return Keyboard::Key::BackSlash; + case AKEYCODE_SEMICOLON: return Keyboard::Key::SemiColon; + case AKEYCODE_APOSTROPHE: return Keyboard::Key::Quote; + case AKEYCODE_SLASH: return Keyboard::Key::Slash; case AKEYCODE_AT: case AKEYCODE_NUM: case AKEYCODE_HEADSETHOOK: @@ -637,9 +637,9 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(int32_t key) case AKEYCODE_MEDIA_PREVIOUS: case AKEYCODE_MEDIA_REWIND: case AKEYCODE_MEDIA_FAST_FORWARD: - case AKEYCODE_MUTE: return Keyboard::Unknown; - case AKEYCODE_PAGE_UP: return Keyboard::PageUp; - case AKEYCODE_PAGE_DOWN: return Keyboard::PageDown; + case AKEYCODE_MUTE: return Keyboard::Key::Unknown; + case AKEYCODE_PAGE_UP: return Keyboard::Key::PageUp; + case AKEYCODE_PAGE_DOWN: return Keyboard::Key::PageDown; case AKEYCODE_PICTSYMBOLS: case AKEYCODE_SWITCH_CHARSET: case AKEYCODE_BUTTON_A: @@ -656,7 +656,7 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(int32_t key) case AKEYCODE_BUTTON_THUMBR: case AKEYCODE_BUTTON_START: case AKEYCODE_BUTTON_SELECT: - case AKEYCODE_BUTTON_MODE: return Keyboard::Unknown; + case AKEYCODE_BUTTON_MODE: return Keyboard::Key::Unknown; } } diff --git a/src/SFML/Window/FreeBSD/JoystickImpl.cpp b/src/SFML/Window/FreeBSD/JoystickImpl.cpp index dd8c659d..6edd5f2b 100644 --- a/src/SFML/Window/FreeBSD/JoystickImpl.cpp +++ b/src/SFML/Window/FreeBSD/JoystickImpl.cpp @@ -138,20 +138,20 @@ namespace { switch (usage) { - case HUG_X: return sf::Joystick::X; - case HUG_Y: return sf::Joystick::Y; - case HUG_Z: return sf::Joystick::Z; - case HUG_RZ: return sf::Joystick::R; - case HUG_RX: return sf::Joystick::U; - case HUG_RY: return sf::Joystick::V; + case HUG_X: return static_cast(sf::Joystick::Axis::X); + case HUG_Y: return static_cast(sf::Joystick::Axis::Y); + case HUG_Z: return static_cast(sf::Joystick::Axis::Z); + case HUG_RZ: return static_cast(sf::Joystick::Axis::R); + case HUG_RX: return static_cast(sf::Joystick::Axis::U); + case HUG_RY: return static_cast(sf::Joystick::Axis::V); default: return -1; } } void hatValueToSfml(int value, sf::priv::JoystickState& state) { - state.axes[sf::Joystick::PovX] = hatValueMap[value].first; - state.axes[sf::Joystick::PovY] = hatValueMap[value].second; + state.axes[static_cast(sf::Joystick::Axis::PovX)] = hatValueMap[value].first; + state.axes[static_cast(sf::Joystick::Axis::PovY)] = hatValueMap[value].second; } } @@ -266,8 +266,8 @@ JoystickCaps JoystickImpl::getCapabilities() const if (usage == HUG_HAT_SWITCH) { - caps.axes[Joystick::PovX] = true; - caps.axes[Joystick::PovY] = true; + caps.axes[static_cast(Joystick::Axis::PovX)] = true; + caps.axes[static_cast(Joystick::Axis::PovY)] = true; } else if (axis != -1) { diff --git a/src/SFML/Window/Joystick.cpp b/src/SFML/Window/Joystick.cpp index 9d5c69fe..4d87a9c5 100644 --- a/src/SFML/Window/Joystick.cpp +++ b/src/SFML/Window/Joystick.cpp @@ -48,7 +48,7 @@ unsigned int Joystick::getButtonCount(unsigned int joystick) //////////////////////////////////////////////////////////// bool Joystick::hasAxis(unsigned int joystick, Axis axis) { - return priv::JoystickManager::getInstance().getCapabilities(joystick).axes[axis]; + return priv::JoystickManager::getInstance().getCapabilities(joystick).axes[static_cast(axis)]; } @@ -62,7 +62,7 @@ bool Joystick::isButtonPressed(unsigned int joystick, unsigned int button) //////////////////////////////////////////////////////////// float Joystick::getAxisPosition(unsigned int joystick, Axis axis) { - return priv::JoystickManager::getInstance().getState(joystick).axes[axis]; + return priv::JoystickManager::getInstance().getState(joystick).axes[static_cast(axis)]; } diff --git a/src/SFML/Window/JoystickImpl.hpp b/src/SFML/Window/JoystickImpl.hpp index 18063967..6cf6c1f0 100644 --- a/src/SFML/Window/JoystickImpl.hpp +++ b/src/SFML/Window/JoystickImpl.hpp @@ -47,11 +47,11 @@ struct JoystickCaps JoystickCaps() { buttonCount = 0; - std::fill(axes, axes + Joystick::AxisCount, false); + std::fill(std::begin(axes), std::end(axes), false); } unsigned int buttonCount; ///< Number of buttons supported by the joystick - bool axes[Joystick::AxisCount]; ///< Support for each axis + bool axes[static_cast(Joystick::Axis::Count)]; ///< Support for each axis }; @@ -64,12 +64,12 @@ struct JoystickState JoystickState() { connected = false; - std::fill(axes, axes + Joystick::AxisCount, 0.f); + std::fill(std::begin(axes), std::end(axes), 0.f); std::fill(buttons, buttons + Joystick::ButtonCount, false); } bool connected; ///< Is the joystick currently connected? - float axes[Joystick::AxisCount]; ///< Position of each axis, in range [-100, 100] + float axes[static_cast(Joystick::Axis::Count)]; ///< Position of each axis, in range [-100, 100] bool buttons[Joystick::ButtonCount]; ///< Status of each button (true = pressed) }; diff --git a/src/SFML/Window/OSX/HIDInputManager.hpp b/src/SFML/Window/OSX/HIDInputManager.hpp index 1b80ad2b..28d059d4 100644 --- a/src/SFML/Window/OSX/HIDInputManager.hpp +++ b/src/SFML/Window/OSX/HIDInputManager.hpp @@ -212,12 +212,12 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool m_isValid; ///< If any error occurs this variable is false - CFDataRef m_layoutData; ///< CFData containing the layout - UCKeyboardLayout* m_layout; ///< Current Keyboard Layout - IOHIDManagerRef m_manager; ///< HID Manager + bool m_isValid; ///< If any error occurs this variable is false + CFDataRef m_layoutData; ///< CFData containing the layout + UCKeyboardLayout* m_layout; ///< Current Keyboard Layout + IOHIDManagerRef m_manager; ///< HID Manager - IOHIDElements m_keys[Keyboard::KeyCount]; ///< All the keys on any connected keyboard + IOHIDElements m_keys[static_cast(Keyboard::Key::Count)]; ///< All the keys on any connected keyboard //////////////////////////////////////////////////////////// /// m_keys' index corresponds to sf::Keyboard::Key enum. diff --git a/src/SFML/Window/OSX/HIDInputManager.mm b/src/SFML/Window/OSX/HIDInputManager.mm index d4bf5101..61545318 100644 --- a/src/SFML/Window/OSX/HIDInputManager.mm +++ b/src/SFML/Window/OSX/HIDInputManager.mm @@ -45,7 +45,7 @@ HIDInputManager& HIDInputManager::getInstance() //////////////////////////////////////////////////////////// bool HIDInputManager::isKeyPressed(Keyboard::Key key) { - return isPressed(m_keys[key]); + return isPressed(m_keys[static_cast(key)]); } @@ -252,7 +252,7 @@ void HIDInputManager::loadKey(IOHIDElementRef key) // Translation went fine // The corresponding SFML key code - Keyboard::Key code = Keyboard::Unknown; // KeyCound means 'none' + Keyboard::Key code = Keyboard::Key::Unknown; // First we look if the key down is from a list of characters // that depend on keyboard localization @@ -261,18 +261,18 @@ void HIDInputManager::loadKey(IOHIDElementRef key) // The key is not a localized one so we try to find a // corresponding code through virtual key code - if (code == Keyboard::Unknown) + if (code == Keyboard::Key::Unknown) code = nonLocalizedKeys(virtualCode); // A code was found, wonderful! - if (code != Keyboard::Unknown) + if (code != Keyboard::Key::Unknown) { // Ok, everything went fine. Now we have a unique // corresponding sf::Keyboard::Key to one IOHIDElementRef - m_keys[code].push_back(key); + m_keys[static_cast(code)].push_back(key); // And don't forget to keep the reference alive for our usage - CFRetain(m_keys[code].back()); + CFRetain(m_keys[static_cast(code)].back()); } //////////////////////////////////////////////////////////// @@ -317,12 +317,12 @@ void HIDInputManager::freeUp() if (m_manager != 0) CFRelease(m_manager); - for (unsigned int i = 0; i < Keyboard::KeyCount; ++i) + for (auto& key : m_keys) { - for (IOHIDElements::iterator it = m_keys[i].begin(); it != m_keys[i].end(); ++it) - CFRelease(*it); + for (auto& element : key) + CFRelease(element); - m_keys[i].clear(); + key.clear(); } } @@ -608,85 +608,85 @@ Keyboard::Key HIDInputManager::localizedKeys(UniChar ch) switch (ch) { case 'a': - case 'A': return sf::Keyboard::A; + case 'A': return sf::Keyboard::Key::A; case 'b': - case 'B': return sf::Keyboard::B; + case 'B': return sf::Keyboard::Key::B; case 'c': - case 'C': return sf::Keyboard::C; + case 'C': return sf::Keyboard::Key::C; case 'd': - case 'D': return sf::Keyboard::D; + case 'D': return sf::Keyboard::Key::D; case 'e': - case 'E': return sf::Keyboard::E; + case 'E': return sf::Keyboard::Key::E; case 'f': - case 'F': return sf::Keyboard::F; + case 'F': return sf::Keyboard::Key::F; case 'g': - case 'G': return sf::Keyboard::G; + case 'G': return sf::Keyboard::Key::G; case 'h': - case 'H': return sf::Keyboard::H; + case 'H': return sf::Keyboard::Key::H; case 'i': - case 'I': return sf::Keyboard::I; + case 'I': return sf::Keyboard::Key::I; case 'j': - case 'J': return sf::Keyboard::J; + case 'J': return sf::Keyboard::Key::J; case 'k': - case 'K': return sf::Keyboard::K; + case 'K': return sf::Keyboard::Key::K; case 'l': - case 'L': return sf::Keyboard::L; + case 'L': return sf::Keyboard::Key::L; case 'm': - case 'M': return sf::Keyboard::M; + case 'M': return sf::Keyboard::Key::M; case 'n': - case 'N': return sf::Keyboard::N; + case 'N': return sf::Keyboard::Key::N; case 'o': - case 'O': return sf::Keyboard::O; + case 'O': return sf::Keyboard::Key::O; case 'p': - case 'P': return sf::Keyboard::P; + case 'P': return sf::Keyboard::Key::P; case 'q': - case 'Q': return sf::Keyboard::Q; + case 'Q': return sf::Keyboard::Key::Q; case 'r': - case 'R': return sf::Keyboard::R; + case 'R': return sf::Keyboard::Key::R; case 's': - case 'S': return sf::Keyboard::S; + case 'S': return sf::Keyboard::Key::S; case 't': - case 'T': return sf::Keyboard::T; + case 'T': return sf::Keyboard::Key::T; case 'u': - case 'U': return sf::Keyboard::U; + case 'U': return sf::Keyboard::Key::U; case 'v': - case 'V': return sf::Keyboard::V; + case 'V': return sf::Keyboard::Key::V; case 'w': - case 'W': return sf::Keyboard::W; + case 'W': return sf::Keyboard::Key::W; case 'x': - case 'X': return sf::Keyboard::X; + case 'X': return sf::Keyboard::Key::X; case 'y': - case 'Y': return sf::Keyboard::Y; + case 'Y': return sf::Keyboard::Key::Y; case 'z': - case 'Z': return sf::Keyboard::Z; + case 'Z': return sf::Keyboard::Key::Z; // The key is not 'localized'. - default: return sf::Keyboard::Unknown; + default: return sf::Keyboard::Key::Unknown; } } @@ -699,167 +699,167 @@ Keyboard::Key HIDInputManager::nonLocalizedKeys(UniChar virtualKeycode) switch (virtualKeycode) { // These cases should not be used but anyway... - case 0x00: return sf::Keyboard::A; - case 0x0b: return sf::Keyboard::B; - case 0x08: return sf::Keyboard::C; - case 0x02: return sf::Keyboard::D; - case 0x0e: return sf::Keyboard::E; - case 0x03: return sf::Keyboard::F; - case 0x05: return sf::Keyboard::G; - case 0x04: return sf::Keyboard::H; - case 0x22: return sf::Keyboard::I; - case 0x26: return sf::Keyboard::J; - case 0x28: return sf::Keyboard::K; - case 0x25: return sf::Keyboard::L; - case 0x2e: return sf::Keyboard::M; - case 0x2d: return sf::Keyboard::N; - case 0x1f: return sf::Keyboard::O; - case 0x23: return sf::Keyboard::P; - case 0x0c: return sf::Keyboard::Q; - case 0x0f: return sf::Keyboard::R; - case 0x01: return sf::Keyboard::S; - case 0x11: return sf::Keyboard::T; - case 0x20: return sf::Keyboard::U; - case 0x09: return sf::Keyboard::V; - case 0x0d: return sf::Keyboard::W; - case 0x07: return sf::Keyboard::X; - case 0x10: return sf::Keyboard::Y; - case 0x06: return sf::Keyboard::Z; + case 0x00: return sf::Keyboard::Key::A; + case 0x0b: return sf::Keyboard::Key::B; + case 0x08: return sf::Keyboard::Key::C; + case 0x02: return sf::Keyboard::Key::D; + case 0x0e: return sf::Keyboard::Key::E; + case 0x03: return sf::Keyboard::Key::F; + case 0x05: return sf::Keyboard::Key::G; + case 0x04: return sf::Keyboard::Key::H; + case 0x22: return sf::Keyboard::Key::I; + case 0x26: return sf::Keyboard::Key::J; + case 0x28: return sf::Keyboard::Key::K; + case 0x25: return sf::Keyboard::Key::L; + case 0x2e: return sf::Keyboard::Key::M; + case 0x2d: return sf::Keyboard::Key::N; + case 0x1f: return sf::Keyboard::Key::O; + case 0x23: return sf::Keyboard::Key::P; + case 0x0c: return sf::Keyboard::Key::Q; + case 0x0f: return sf::Keyboard::Key::R; + case 0x01: return sf::Keyboard::Key::S; + case 0x11: return sf::Keyboard::Key::T; + case 0x20: return sf::Keyboard::Key::U; + case 0x09: return sf::Keyboard::Key::V; + case 0x0d: return sf::Keyboard::Key::W; + case 0x07: return sf::Keyboard::Key::X; + case 0x10: return sf::Keyboard::Key::Y; + case 0x06: return sf::Keyboard::Key::Z; // These cases should not be used but anyway... - case 0x1d: return sf::Keyboard::Num0; - case 0x12: return sf::Keyboard::Num1; - case 0x13: return sf::Keyboard::Num2; - case 0x14: return sf::Keyboard::Num3; - case 0x15: return sf::Keyboard::Num4; - case 0x17: return sf::Keyboard::Num5; - case 0x16: return sf::Keyboard::Num6; - case 0x1a: return sf::Keyboard::Num7; - case 0x1c: return sf::Keyboard::Num8; - case 0x19: return sf::Keyboard::Num9; + case 0x1d: return sf::Keyboard::Key::Num0; + case 0x12: return sf::Keyboard::Key::Num1; + case 0x13: return sf::Keyboard::Key::Num2; + case 0x14: return sf::Keyboard::Key::Num3; + case 0x15: return sf::Keyboard::Key::Num4; + case 0x17: return sf::Keyboard::Key::Num5; + case 0x16: return sf::Keyboard::Key::Num6; + case 0x1a: return sf::Keyboard::Key::Num7; + case 0x1c: return sf::Keyboard::Key::Num8; + case 0x19: return sf::Keyboard::Key::Num9; - case 0x35: return sf::Keyboard::Escape; + case 0x35: return sf::Keyboard::Key::Escape; // Modifier keys : never happen with keyDown/keyUp methods (?) - case 0x3b: return sf::Keyboard::LControl; - case 0x38: return sf::Keyboard::LShift; - case 0x3a: return sf::Keyboard::LAlt; - case 0x37: return sf::Keyboard::LSystem; - case 0x3e: return sf::Keyboard::RControl; - case 0x3c: return sf::Keyboard::RShift; - case 0x3d: return sf::Keyboard::RAlt; - case 0x36: return sf::Keyboard::RSystem; + case 0x3b: return sf::Keyboard::Key::LControl; + case 0x38: return sf::Keyboard::Key::LShift; + case 0x3a: return sf::Keyboard::Key::LAlt; + case 0x37: return sf::Keyboard::Key::LSystem; + case 0x3e: return sf::Keyboard::Key::RControl; + case 0x3c: return sf::Keyboard::Key::RShift; + case 0x3d: return sf::Keyboard::Key::RAlt; + case 0x36: return sf::Keyboard::Key::RSystem; - case 0x7f: return sf::Keyboard::Menu; - case NSMenuFunctionKey: return sf::Keyboard::Menu; + case 0x7f: return sf::Keyboard::Key::Menu; + case NSMenuFunctionKey: return sf::Keyboard::Key::Menu; - case 0x21: return sf::Keyboard::LBracket; - case 0x1e: return sf::Keyboard::RBracket; - case 0x29: return sf::Keyboard::SemiColon; - case 0x2b: return sf::Keyboard::Comma; - case 0x41: /* keypad */ return sf::Keyboard::Period; - case 0x2f: /* keyboard */ return sf::Keyboard::Period; - case 0x27: return sf::Keyboard::Quote; - case 0x2c: return sf::Keyboard::Slash; - case 0x2a: return sf::Keyboard::BackSlash; + case 0x21: return sf::Keyboard::Key::LBracket; + case 0x1e: return sf::Keyboard::Key::RBracket; + case 0x29: return sf::Keyboard::Key::SemiColon; + case 0x2b: return sf::Keyboard::Key::Comma; + case 0x41: /* keypad */ return sf::Keyboard::Key::Period; + case 0x2f: /* keyboard */ return sf::Keyboard::Key::Period; + case 0x27: return sf::Keyboard::Key::Quote; + case 0x2c: return sf::Keyboard::Key::Slash; + case 0x2a: return sf::Keyboard::Key::BackSlash; - // sf::Keyboard::Tilde might be in conflict with some other key. + // sf::Keyboard::Key::Tilde might be in conflict with some other key. // 0x0a is for "Non-US Backslash" according to HID Calibrator, // a sample provided by Apple. - case 0x0a: return sf::Keyboard::Tilde; + case 0x0a: return sf::Keyboard::Key::Tilde; - case 0x51: /* keypad */ return sf::Keyboard::Equal; - case 0x18: /* keyboard */ return sf::Keyboard::Equal; - case 0x32: return sf::Keyboard::Dash; - case 0x31: return sf::Keyboard::Space; - case 0x4c: /* keypad */ return sf::Keyboard::Return; - case 0x24: /* keyboard */ return sf::Keyboard::Return; - case 0x33: return sf::Keyboard::BackSpace; - case 0x30: return sf::Keyboard::Tab; + case 0x51: /* keypad */ return sf::Keyboard::Key::Equal; + case 0x18: /* keyboard */ return sf::Keyboard::Key::Equal; + case 0x32: return sf::Keyboard::Key::Dash; + case 0x31: return sf::Keyboard::Key::Space; + case 0x4c: /* keypad */ return sf::Keyboard::Key::Return; + case 0x24: /* keyboard */ return sf::Keyboard::Key::Return; + case 0x33: return sf::Keyboard::Key::BackSpace; + case 0x30: return sf::Keyboard::Key::Tab; // Duplicates (see next section). - case 0x74: return sf::Keyboard::PageUp; - case 0x79: return sf::Keyboard::PageDown; - case 0x77: return sf::Keyboard::End; - case 0x73: return sf::Keyboard::Home; + case 0x74: return sf::Keyboard::Key::PageUp; + case 0x79: return sf::Keyboard::Key::PageDown; + case 0x77: return sf::Keyboard::Key::End; + case 0x73: return sf::Keyboard::Key::Home; - case NSPageUpFunctionKey: return sf::Keyboard::PageUp; - case NSPageDownFunctionKey: return sf::Keyboard::PageDown; - case NSEndFunctionKey: return sf::Keyboard::End; - case NSHomeFunctionKey: return sf::Keyboard::Home; + case NSPageUpFunctionKey: return sf::Keyboard::Key::PageUp; + case NSPageDownFunctionKey: return sf::Keyboard::Key::PageDown; + case NSEndFunctionKey: return sf::Keyboard::Key::End; + case NSHomeFunctionKey: return sf::Keyboard::Key::Home; - case 0x72: return sf::Keyboard::Insert; - case NSInsertFunctionKey: return sf::Keyboard::Insert; - case 0x75: return sf::Keyboard::Delete; - case NSDeleteFunctionKey: return sf::Keyboard::Delete; + case 0x72: return sf::Keyboard::Key::Insert; + case NSInsertFunctionKey: return sf::Keyboard::Key::Insert; + case 0x75: return sf::Keyboard::Key::Delete; + case NSDeleteFunctionKey: return sf::Keyboard::Key::Delete; - case 0x45: return sf::Keyboard::Add; - case 0x4e: return sf::Keyboard::Subtract; - case 0x43: return sf::Keyboard::Multiply; - case 0x4b: return sf::Keyboard::Divide; + case 0x45: return sf::Keyboard::Key::Add; + case 0x4e: return sf::Keyboard::Key::Subtract; + case 0x43: return sf::Keyboard::Key::Multiply; + case 0x4b: return sf::Keyboard::Key::Divide; // Duplicates (see next section). - case 0x7b: return sf::Keyboard::Left; - case 0x7c: return sf::Keyboard::Right; - case 0x7e: return sf::Keyboard::Up; - case 0x7d: return sf::Keyboard::Down; + case 0x7b: return sf::Keyboard::Key::Left; + case 0x7c: return sf::Keyboard::Key::Right; + case 0x7e: return sf::Keyboard::Key::Up; + case 0x7d: return sf::Keyboard::Key::Down; - case NSLeftArrowFunctionKey: return sf::Keyboard::Left; - case NSRightArrowFunctionKey: return sf::Keyboard::Right; - case NSUpArrowFunctionKey: return sf::Keyboard::Up; - case NSDownArrowFunctionKey: return sf::Keyboard::Down; + case NSLeftArrowFunctionKey: return sf::Keyboard::Key::Left; + case NSRightArrowFunctionKey: return sf::Keyboard::Key::Right; + case NSUpArrowFunctionKey: return sf::Keyboard::Key::Up; + case NSDownArrowFunctionKey: return sf::Keyboard::Key::Down; - case 0x52: return sf::Keyboard::Numpad0; - case 0x53: return sf::Keyboard::Numpad1; - case 0x54: return sf::Keyboard::Numpad2; - case 0x55: return sf::Keyboard::Numpad3; - case 0x56: return sf::Keyboard::Numpad4; - case 0x57: return sf::Keyboard::Numpad5; - case 0x58: return sf::Keyboard::Numpad6; - case 0x59: return sf::Keyboard::Numpad7; - case 0x5b: return sf::Keyboard::Numpad8; - case 0x5c: return sf::Keyboard::Numpad9; + case 0x52: return sf::Keyboard::Key::Numpad0; + case 0x53: return sf::Keyboard::Key::Numpad1; + case 0x54: return sf::Keyboard::Key::Numpad2; + case 0x55: return sf::Keyboard::Key::Numpad3; + case 0x56: return sf::Keyboard::Key::Numpad4; + case 0x57: return sf::Keyboard::Key::Numpad5; + case 0x58: return sf::Keyboard::Key::Numpad6; + case 0x59: return sf::Keyboard::Key::Numpad7; + case 0x5b: return sf::Keyboard::Key::Numpad8; + case 0x5c: return sf::Keyboard::Key::Numpad9; // Duplicates (see next section). - case 0x7a: return sf::Keyboard::F1; - case 0x78: return sf::Keyboard::F2; - case 0x63: return sf::Keyboard::F3; - case 0x76: return sf::Keyboard::F4; - case 0x60: return sf::Keyboard::F5; - case 0x61: return sf::Keyboard::F6; - case 0x62: return sf::Keyboard::F7; - case 0x64: return sf::Keyboard::F8; - case 0x65: return sf::Keyboard::F9; - case 0x6d: return sf::Keyboard::F10; - case 0x67: return sf::Keyboard::F11; - case 0x6f: return sf::Keyboard::F12; - case 0x69: return sf::Keyboard::F13; - case 0x6b: return sf::Keyboard::F14; - case 0x71: return sf::Keyboard::F15; + case 0x7a: return sf::Keyboard::Key::F1; + case 0x78: return sf::Keyboard::Key::F2; + case 0x63: return sf::Keyboard::Key::F3; + case 0x76: return sf::Keyboard::Key::F4; + case 0x60: return sf::Keyboard::Key::F5; + case 0x61: return sf::Keyboard::Key::F6; + case 0x62: return sf::Keyboard::Key::F7; + case 0x64: return sf::Keyboard::Key::F8; + case 0x65: return sf::Keyboard::Key::F9; + case 0x6d: return sf::Keyboard::Key::F10; + case 0x67: return sf::Keyboard::Key::F11; + case 0x6f: return sf::Keyboard::Key::F12; + case 0x69: return sf::Keyboard::Key::F13; + case 0x6b: return sf::Keyboard::Key::F14; + case 0x71: return sf::Keyboard::Key::F15; - case NSF1FunctionKey: return sf::Keyboard::F1; - case NSF2FunctionKey: return sf::Keyboard::F2; - case NSF3FunctionKey: return sf::Keyboard::F3; - case NSF4FunctionKey: return sf::Keyboard::F4; - case NSF5FunctionKey: return sf::Keyboard::F5; - case NSF6FunctionKey: return sf::Keyboard::F6; - case NSF7FunctionKey: return sf::Keyboard::F7; - case NSF8FunctionKey: return sf::Keyboard::F8; - case NSF9FunctionKey: return sf::Keyboard::F9; - case NSF10FunctionKey: return sf::Keyboard::F10; - case NSF11FunctionKey: return sf::Keyboard::F11; - case NSF12FunctionKey: return sf::Keyboard::F12; - case NSF13FunctionKey: return sf::Keyboard::F13; - case NSF14FunctionKey: return sf::Keyboard::F14; - case NSF15FunctionKey: return sf::Keyboard::F15; + case NSF1FunctionKey: return sf::Keyboard::Key::F1; + case NSF2FunctionKey: return sf::Keyboard::Key::F2; + case NSF3FunctionKey: return sf::Keyboard::Key::F3; + case NSF4FunctionKey: return sf::Keyboard::Key::F4; + case NSF5FunctionKey: return sf::Keyboard::Key::F5; + case NSF6FunctionKey: return sf::Keyboard::Key::F6; + case NSF7FunctionKey: return sf::Keyboard::Key::F7; + case NSF8FunctionKey: return sf::Keyboard::Key::F8; + case NSF9FunctionKey: return sf::Keyboard::Key::F9; + case NSF10FunctionKey: return sf::Keyboard::Key::F10; + case NSF11FunctionKey: return sf::Keyboard::Key::F11; + case NSF12FunctionKey: return sf::Keyboard::Key::F12; + case NSF13FunctionKey: return sf::Keyboard::Key::F13; + case NSF14FunctionKey: return sf::Keyboard::Key::F14; + case NSF15FunctionKey: return sf::Keyboard::Key::F15; - case NSPauseFunctionKey: return sf::Keyboard::Pause; + case NSPauseFunctionKey: return sf::Keyboard::Key::Pause; // keycode 0x1b is not bound to any key. // This key is ' on CH-FR, ) on FR and - on US layouts. // An unknown key. - default: return sf::Keyboard::Unknown; + default: return sf::Keyboard::Key::Unknown; } } diff --git a/src/SFML/Window/OSX/InputImpl.mm b/src/SFML/Window/OSX/InputImpl.mm index 24f2aaf2..0324ed7c 100644 --- a/src/SFML/Window/OSX/InputImpl.mm +++ b/src/SFML/Window/OSX/InputImpl.mm @@ -140,7 +140,7 @@ void InputImpl::setVirtualKeyboardVisible(bool /*visible*/) bool InputImpl::isMouseButtonPressed(Mouse::Button button) { NSUInteger state = [NSEvent pressedMouseButtons]; - NSUInteger flag = 1 << button; + NSUInteger flag = 1 << static_cast(button); return (state & flag) != 0; } diff --git a/src/SFML/Window/OSX/JoystickImpl.cpp b/src/SFML/Window/OSX/JoystickImpl.cpp index 5740cd7a..22e04277 100644 --- a/src/SFML/Window/OSX/JoystickImpl.cpp +++ b/src/SFML/Window/OSX/JoystickImpl.cpp @@ -249,12 +249,12 @@ bool JoystickImpl::open(unsigned int index) case kIOHIDElementTypeInput_Misc: switch (IOHIDElementGetUsage(element)) { - case kHIDUsage_GD_X: m_axis[Joystick::X] = element; break; - case kHIDUsage_GD_Y: m_axis[Joystick::Y] = element; break; - case kHIDUsage_GD_Z: m_axis[Joystick::Z] = element; break; - case kHIDUsage_GD_Rx: m_axis[Joystick::U] = element; break; - case kHIDUsage_GD_Ry: m_axis[Joystick::V] = element; break; - case kHIDUsage_GD_Rz: m_axis[Joystick::R] = element; break; + case kHIDUsage_GD_X: m_axis[Joystick::Axis::X] = element; break; + case kHIDUsage_GD_Y: m_axis[Joystick::Axis::Y] = element; break; + case kHIDUsage_GD_Z: m_axis[Joystick::Axis::Z] = element; break; + case kHIDUsage_GD_Rx: m_axis[Joystick::Axis::U] = element; break; + case kHIDUsage_GD_Ry: m_axis[Joystick::Axis::V] = element; break; + case kHIDUsage_GD_Rz: m_axis[Joystick::Axis::R] = element; break; default: break; // kHIDUsage_GD_Vx, kHIDUsage_GD_Vy, kHIDUsage_GD_Vz are ignored. } @@ -281,8 +281,8 @@ bool JoystickImpl::open(unsigned int index) // Retain all these objects for personal use for (ButtonsVector::iterator it(m_buttons.begin()); it != m_buttons.end(); ++it) CFRetain(*it); - for (AxisMap::iterator it(m_axis.begin()); it != m_axis.end(); ++it) - CFRetain(it->second); + for (auto& axis : m_axis) + CFRetain(axis.second); // Note: we didn't retain element in the switch because we might have multiple // Axis X (for example) and we want to keep only the last one. So to prevent @@ -302,8 +302,8 @@ void JoystickImpl::close() CFRelease(*it); m_buttons.clear(); - for (AxisMap::iterator it(m_axis.begin()); it != m_axis.end(); ++it) - CFRelease(it->second); + for (auto& axis : m_axis) + CFRelease(axis.second); m_axis.clear(); // And we unregister this joystick @@ -320,8 +320,8 @@ JoystickCaps JoystickImpl::getCapabilities() const caps.buttonCount = m_buttons.size(); // Axis: - for (AxisMap::const_iterator it(m_axis.begin()); it != m_axis.end(); ++it) { - caps.axes[it->first] = true; + for (const auto& axis : m_axis) { + caps.axes[static_cast(axis.first)] = true; } return caps; @@ -339,7 +339,7 @@ Joystick::Identification JoystickImpl::getIdentification() const JoystickState JoystickImpl::update() { static const JoystickState disconnectedState; // return this if joystick was disconnected - JoystickState state; // otherwise return that + JoystickState state; // otherwise return that state.connected = true; // Note: free up is done in close() which is called, if required, @@ -396,10 +396,10 @@ JoystickState JoystickImpl::update() } // Update axes' state - for (AxisMap::iterator it = m_axis.begin(); it != m_axis.end(); ++it) + for (auto& axis : m_axis) { IOHIDValueRef value = 0; - IOHIDDeviceGetValue(IOHIDElementGetDevice(it->second), it->second, &value); + IOHIDDeviceGetValue(IOHIDElementGetDevice(axis.second), axis.second, &value); // Check for plug out. if (!value) @@ -418,13 +418,13 @@ JoystickState JoystickImpl::update() // This method might not be very accurate (the "0 position" can be // slightly shift with some device) but we don't care because most // of devices are so sensitive that this is not relevant. - double physicalMax = IOHIDElementGetPhysicalMax(it->second); - double physicalMin = IOHIDElementGetPhysicalMin(it->second); + double physicalMax = IOHIDElementGetPhysicalMax(axis.second); + double physicalMin = IOHIDElementGetPhysicalMin(axis.second); double scaledMin = -100; double scaledMax = 100; double physicalValue = IOHIDValueGetScaledValue(value, kIOHIDValueScaleTypePhysical); float scaledValue = (((physicalValue - physicalMin) * (scaledMax - scaledMin)) / (physicalMax - physicalMin)) + scaledMin; - state.axes[it->first] = scaledValue; + state.axes[static_cast(axis.first)] = scaledValue; } return state; diff --git a/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm b/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm index eec7e203..acd69af2 100644 --- a/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm +++ b/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm @@ -157,7 +157,7 @@ void handleModifiersChanged(NSUInteger modifiers, sf::priv::WindowImplCocoa& req modifiers, NSLeftShiftKeyMask, NSRightShiftKeyMask, state.leftShiftWasDown, state.rightShiftWasDown, - sf::Keyboard::LShift, sf::Keyboard::RShift, + sf::Keyboard::Key::LShift, sf::Keyboard::Key::RShift, requester ); @@ -166,7 +166,7 @@ void handleModifiersChanged(NSUInteger modifiers, sf::priv::WindowImplCocoa& req modifiers, NSLeftCommandKeyMask, NSRightCommandKeyMask, state.leftCommandWasDown, state.rightCommandWasDown, - sf::Keyboard::LSystem, sf::Keyboard::RSystem, + sf::Keyboard::Key::LSystem, sf::Keyboard::Key::RSystem, requester ); @@ -175,7 +175,7 @@ void handleModifiersChanged(NSUInteger modifiers, sf::priv::WindowImplCocoa& req modifiers, NSLeftAlternateKeyMask, NSRightAlternateKeyMask, state.leftAlternateWasDown, state.rightAlternateWasDown, - sf::Keyboard::LAlt, sf::Keyboard::RAlt, + sf::Keyboard::Key::LAlt, sf::Keyboard::Key::RAlt, requester ); @@ -184,7 +184,7 @@ void handleModifiersChanged(NSUInteger modifiers, sf::priv::WindowImplCocoa& req modifiers, NSLeftControlKeyMask, NSRightControlKeyMask, state.leftControlWasDown, state.rightControlWasDown, - sf::Keyboard::LControl, sf::Keyboard::RControl, + sf::Keyboard::Key::LControl, sf::Keyboard::Key::RControl, requester ); } diff --git a/src/SFML/Window/OSX/SFOpenGLView+keyboard.mm b/src/SFML/Window/OSX/SFOpenGLView+keyboard.mm index aab4d9b8..26ac345a 100644 --- a/src/SFML/Window/OSX/SFOpenGLView+keyboard.mm +++ b/src/SFML/Window/OSX/SFOpenGLView+keyboard.mm @@ -86,7 +86,7 @@ { sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent]; - if (key.code != sf::Keyboard::Unknown) // The key is recognized. + if (key.code != sf::Keyboard::Key::Unknown) // The key is recognized. m_requester->keyDown(key); } @@ -158,7 +158,7 @@ sf::Event::KeyEvent key = [SFOpenGLView convertNSKeyEventToSFMLEvent:theEvent]; - if (key.code != sf::Keyboard::Unknown) // The key is recognized. + if (key.code != sf::Keyboard::Key::Unknown) // The key is recognized. m_requester->keyUp(key); } @@ -181,7 +181,7 @@ +(sf::Event::KeyEvent)convertNSKeyEventToSFMLEvent:(NSEvent*)event { // Key code - sf::Keyboard::Key key = sf::Keyboard::Unknown; + sf::Keyboard::Key key = sf::Keyboard::Key::Unknown; // First we look if the key down is from a list of characters // that depend on keyboard localization. @@ -191,7 +191,7 @@ // If the key is not a localized one, we try to find a corresponding code // through virtual key code. - if (key == sf::Keyboard::Unknown) + if (key == sf::Keyboard::Key::Unknown) key = sf::priv::HIDInputManager::nonLocalizedKeys([event keyCode]); return keyEventWithModifiers([event modifierFlags], key); diff --git a/src/SFML/Window/OSX/SFOpenGLView+mouse.mm b/src/SFML/Window/OSX/SFOpenGLView+mouse.mm index fa65aa6e..0d82286c 100644 --- a/src/SFML/Window/OSX/SFOpenGLView+mouse.mm +++ b/src/SFML/Window/OSX/SFOpenGLView+mouse.mm @@ -116,7 +116,7 @@ { NSPoint loc = [self cursorPositionFromEvent:theEvent]; - if (button != sf::Mouse::ButtonCount) + if (button != sf::Mouse::Button::Count) m_requester->mouseDownAt(button, loc.x, loc.y); } } @@ -161,7 +161,7 @@ { NSPoint loc = [self cursorPositionFromEvent:theEvent]; - if (button != sf::Mouse::ButtonCount) + if (button != sf::Mouse::Button::Count) m_requester->mouseUpAt(button, loc.x, loc.y); } } @@ -389,12 +389,12 @@ { switch ([event buttonNumber]) { - case 0: return sf::Mouse::Left; - case 1: return sf::Mouse::Right; - case 2: return sf::Mouse::Middle; - case 3: return sf::Mouse::XButton1; - case 4: return sf::Mouse::XButton2; - default: return sf::Mouse::ButtonCount; // Never happens! (hopefully) + case 0: return sf::Mouse::Button::Left; + case 1: return sf::Mouse::Button::Right; + case 2: return sf::Mouse::Button::Middle; + case 3: return sf::Mouse::Button::XButton1; + case 4: return sf::Mouse::Button::XButton2; + default: return sf::Mouse::Button::Count; // Never happens! (hopefully) } } diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index b294881a..a3e91c7c 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -209,7 +209,7 @@ void WindowImplCocoa::setUpProcess(void) void WindowImplCocoa::windowClosed(void) { Event event; - event.type = Event::Closed; + event.type = Event::Type::Closed; pushEvent(event); } @@ -219,7 +219,7 @@ void WindowImplCocoa::windowClosed(void) void WindowImplCocoa::windowResized(unsigned int width, unsigned int height) { Event event; - event.type = Event::Resized; + event.type = Event::Type::Resized; event.size.width = width; event.size.height = height; scaleOutWidthHeight(event.size, m_delegate); @@ -235,7 +235,7 @@ void WindowImplCocoa::windowLostFocus(void) showMouseCursor(); // Make sure the cursor is visible Event event; - event.type = Event::LostFocus; + event.type = Event::Type::LostFocus; pushEvent(event); } @@ -248,7 +248,7 @@ void WindowImplCocoa::windowGainedFocus(void) hideMouseCursor(); // Restore user's setting Event event; - event.type = Event::GainedFocus; + event.type = Event::Type::GainedFocus; pushEvent(event); } @@ -261,7 +261,7 @@ void WindowImplCocoa::windowGainedFocus(void) void WindowImplCocoa::mouseDownAt(Mouse::Button button, int x, int y) { Event event; - event.type = Event::MouseButtonPressed; + event.type = Event::Type::MouseButtonPressed; event.mouseButton.button = button; event.mouseButton.x = x; event.mouseButton.y = y; @@ -275,7 +275,7 @@ void WindowImplCocoa::mouseDownAt(Mouse::Button button, int x, int y) void WindowImplCocoa::mouseUpAt(Mouse::Button button, int x, int y) { Event event; - event.type = Event::MouseButtonReleased; + event.type = Event::Type::MouseButtonReleased; event.mouseButton.button = button; event.mouseButton.x = x; event.mouseButton.y = y; @@ -289,7 +289,7 @@ void WindowImplCocoa::mouseUpAt(Mouse::Button button, int x, int y) void WindowImplCocoa::mouseMovedAt(int x, int y) { Event event; - event.type = Event::MouseMoved; + event.type = Event::Type::MouseMoved; event.mouseMove.x = x; event.mouseMove.y = y; scaleOutXY(event.mouseMove, m_delegate); @@ -302,23 +302,23 @@ void WindowImplCocoa::mouseWheelScrolledAt(float deltaX, float deltaY, int x, in { Event event; - event.type = Event::MouseWheelMoved; + event.type = Event::Type::MouseWheelMoved; event.mouseWheel.delta = deltaY; event.mouseWheel.x = x; event.mouseWheel.y = y; scaleOutXY(event.mouseWheel, m_delegate); pushEvent(event); - event.type = Event::MouseWheelScrolled; - event.mouseWheelScroll.wheel = Mouse::VerticalWheel; + event.type = Event::Type::MouseWheelScrolled; + event.mouseWheelScroll.wheel = Mouse::Wheel::VerticalWheel; event.mouseWheelScroll.delta = deltaY; event.mouseWheelScroll.x = x; event.mouseWheelScroll.y = y; scaleOutXY(event.mouseWheelScroll, m_delegate); pushEvent(event); - event.type = Event::MouseWheelScrolled; - event.mouseWheelScroll.wheel = Mouse::HorizontalWheel; + event.type = Event::Type::MouseWheelScrolled; + event.mouseWheelScroll.wheel = Mouse::Wheel::HorizontalWheel; event.mouseWheelScroll.delta = deltaX; event.mouseWheelScroll.x = x; event.mouseWheelScroll.y = y; @@ -333,7 +333,7 @@ void WindowImplCocoa::mouseMovedIn(void) hideMouseCursor(); // Restore user's setting Event event; - event.type = Event::MouseEntered; + event.type = Event::Type::MouseEntered; pushEvent(event); } @@ -345,7 +345,7 @@ void WindowImplCocoa::mouseMovedOut(void) showMouseCursor(); // Make sure the cursor is visible Event event; - event.type = Event::MouseLeft; + event.type = Event::Type::MouseLeft; pushEvent(event); } @@ -359,7 +359,7 @@ void WindowImplCocoa::mouseMovedOut(void) void WindowImplCocoa::keyDown(Event::KeyEvent key) { Event event; - event.type = Event::KeyPressed; + event.type = Event::Type::KeyPressed; event.key = key; pushEvent(event); @@ -370,7 +370,7 @@ void WindowImplCocoa::keyDown(Event::KeyEvent key) void WindowImplCocoa::keyUp(Event::KeyEvent key) { Event event; - event.type = Event::KeyReleased; + event.type = Event::Type::KeyReleased; event.key = key; pushEvent(event); @@ -381,7 +381,7 @@ void WindowImplCocoa::keyUp(Event::KeyEvent key) void WindowImplCocoa::textEntered(unichar charcode) { Event event; - event.type = Event::TextEntered; + event.type = Event::Type::TextEntered; event.text.unicode = charcode; pushEvent(event); diff --git a/src/SFML/Window/SensorManager.cpp b/src/SFML/Window/SensorManager.cpp index 409eace6..3dc10ac8 100644 --- a/src/SFML/Window/SensorManager.cpp +++ b/src/SFML/Window/SensorManager.cpp @@ -44,17 +44,17 @@ SensorManager& SensorManager::getInstance() //////////////////////////////////////////////////////////// bool SensorManager::isAvailable(Sensor::Type sensor) { - return m_sensors[sensor].available; + return m_sensors[static_cast(sensor)].available; } //////////////////////////////////////////////////////////// void SensorManager::setEnabled(Sensor::Type sensor, bool enabled) { - if (m_sensors[sensor].available) + if (m_sensors[static_cast(sensor)].available) { - m_sensors[sensor].enabled = enabled; - m_sensors[sensor].sensor.setEnabled(enabled); + m_sensors[static_cast(sensor)].enabled = enabled; + m_sensors[static_cast(sensor)].sensor.setEnabled(enabled); } else { @@ -66,25 +66,25 @@ void SensorManager::setEnabled(Sensor::Type sensor, bool enabled) //////////////////////////////////////////////////////////// bool SensorManager::isEnabled(Sensor::Type sensor) const { - return m_sensors[sensor].enabled; + return m_sensors[static_cast(sensor)].enabled; } //////////////////////////////////////////////////////////// Vector3f SensorManager::getValue(Sensor::Type sensor) const { - return m_sensors[sensor].value; + return m_sensors[static_cast(sensor)].value; } //////////////////////////////////////////////////////////// void SensorManager::update() { - for (int i = 0; i < Sensor::Count; ++i) + for (auto& sensor : m_sensors) { // Only process available sensors - if (m_sensors[i].available) - m_sensors[i].value = m_sensors[i].sensor.update(); + if (sensor.available) + sensor.value = sensor.sensor.update(); } } @@ -96,7 +96,7 @@ SensorManager::SensorManager() SensorImpl::initialize(); // Per sensor initialization - for (int i = 0; i < Sensor::Count; ++i) + for (auto i = 0u; i < static_cast(Sensor::Type::Count); ++i) { // Check which sensors are available m_sensors[i].available = SensorImpl::isAvailable(static_cast(i)); @@ -114,10 +114,10 @@ SensorManager::SensorManager() SensorManager::~SensorManager() { // Per sensor cleanup - for (int i = 0; i < Sensor::Count; ++i) + for (auto& sensor : m_sensors) { - if (m_sensors[i].available) - m_sensors[i].sensor.close(); + if (sensor.available) + sensor.sensor.close(); } // Global sensor cleanup diff --git a/src/SFML/Window/SensorManager.hpp b/src/SFML/Window/SensorManager.hpp index 08bcea4d..7f75fbaa 100644 --- a/src/SFML/Window/SensorManager.hpp +++ b/src/SFML/Window/SensorManager.hpp @@ -127,7 +127,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Item m_sensors[Sensor::Count]; ///< Sensors information and state + Item m_sensors[static_cast(Sensor::Type::Count)]; ///< Sensors information and state }; } // namespace priv diff --git a/src/SFML/Window/Unix/InputImpl.cpp b/src/SFML/Window/Unix/InputImpl.cpp index e5510316..6a01d8c2 100644 --- a/src/SFML/Window/Unix/InputImpl.cpp +++ b/src/SFML/Window/Unix/InputImpl.cpp @@ -44,114 +44,110 @@ bool InputImpl::isKeyPressed(Keyboard::Key key) KeySym keysym = 0; switch (key) { - case Keyboard::LShift: keysym = XK_Shift_L; break; - case Keyboard::RShift: keysym = XK_Shift_R; break; - case Keyboard::LControl: keysym = XK_Control_L; break; - case Keyboard::RControl: keysym = XK_Control_R; break; - case Keyboard::LAlt: keysym = XK_Alt_L; break; - case Keyboard::RAlt: keysym = XK_Alt_R; break; - case Keyboard::LSystem: keysym = XK_Super_L; break; - case Keyboard::RSystem: keysym = XK_Super_R; break; - case Keyboard::Menu: keysym = XK_Menu; break; - case Keyboard::Escape: keysym = XK_Escape; break; - case Keyboard::SemiColon: keysym = XK_semicolon; break; - case Keyboard::Slash: keysym = XK_slash; break; - case Keyboard::Equal: keysym = XK_equal; break; - case Keyboard::Dash: keysym = XK_minus; break; - case Keyboard::LBracket: keysym = XK_bracketleft; break; - case Keyboard::RBracket: keysym = XK_bracketright; break; - case Keyboard::Comma: keysym = XK_comma; break; - case Keyboard::Period: keysym = XK_period; break; - case Keyboard::Quote: keysym = XK_apostrophe; break; - case Keyboard::BackSlash: keysym = XK_backslash; break; - case Keyboard::Tilde: keysym = XK_grave; break; - case Keyboard::Space: keysym = XK_space; break; - case Keyboard::Return: keysym = XK_Return; break; - case Keyboard::BackSpace: keysym = XK_BackSpace; break; - case Keyboard::Tab: keysym = XK_Tab; break; - case Keyboard::PageUp: keysym = XK_Prior; break; - case Keyboard::PageDown: keysym = XK_Next; break; - case Keyboard::End: keysym = XK_End; break; - case Keyboard::Home: keysym = XK_Home; break; - case Keyboard::Insert: keysym = XK_Insert; break; - case Keyboard::Delete: keysym = XK_Delete; break; - case Keyboard::Add: keysym = XK_KP_Add; break; - case Keyboard::Subtract: keysym = XK_KP_Subtract; break; - case Keyboard::Multiply: keysym = XK_KP_Multiply; break; - case Keyboard::Divide: keysym = XK_KP_Divide; break; - case Keyboard::Pause: keysym = XK_Pause; break; - case Keyboard::F1: keysym = XK_F1; break; - case Keyboard::F2: keysym = XK_F2; break; - case Keyboard::F3: keysym = XK_F3; break; - case Keyboard::F4: keysym = XK_F4; break; - case Keyboard::F5: keysym = XK_F5; break; - case Keyboard::F6: keysym = XK_F6; break; - case Keyboard::F7: keysym = XK_F7; break; - case Keyboard::F8: keysym = XK_F8; break; - case Keyboard::F9: keysym = XK_F9; break; - case Keyboard::F10: keysym = XK_F10; break; - case Keyboard::F11: keysym = XK_F11; break; - case Keyboard::F12: keysym = XK_F12; break; - case Keyboard::F13: keysym = XK_F13; break; - case Keyboard::F14: keysym = XK_F14; break; - case Keyboard::F15: keysym = XK_F15; break; - case Keyboard::Left: keysym = XK_Left; break; - case Keyboard::Right: keysym = XK_Right; break; - case Keyboard::Up: keysym = XK_Up; break; - case Keyboard::Down: keysym = XK_Down; break; - case Keyboard::Numpad0: keysym = XK_KP_Insert; break; - case Keyboard::Numpad1: keysym = XK_KP_End; break; - case Keyboard::Numpad2: keysym = XK_KP_Down; break; - case Keyboard::Numpad3: keysym = XK_KP_Page_Down; break; - case Keyboard::Numpad4: keysym = XK_KP_Left; break; - case Keyboard::Numpad5: keysym = XK_KP_Begin; break; - case Keyboard::Numpad6: keysym = XK_KP_Right; break; - case Keyboard::Numpad7: keysym = XK_KP_Home; break; - case Keyboard::Numpad8: keysym = XK_KP_Up; break; - case Keyboard::Numpad9: keysym = XK_KP_Page_Up; break; - case Keyboard::A: keysym = XK_a; break; - case Keyboard::B: keysym = XK_b; break; - case Keyboard::C: keysym = XK_c; break; - case Keyboard::D: keysym = XK_d; break; - case Keyboard::E: keysym = XK_e; break; - case Keyboard::F: keysym = XK_f; break; - case Keyboard::G: keysym = XK_g; break; - case Keyboard::H: keysym = XK_h; break; - case Keyboard::I: keysym = XK_i; break; - case Keyboard::J: keysym = XK_j; break; - case Keyboard::K: keysym = XK_k; break; - case Keyboard::L: keysym = XK_l; break; - case Keyboard::M: keysym = XK_m; break; - case Keyboard::N: keysym = XK_n; break; - case Keyboard::O: keysym = XK_o; break; - case Keyboard::P: keysym = XK_p; break; - case Keyboard::Q: keysym = XK_q; break; - case Keyboard::R: keysym = XK_r; break; - case Keyboard::S: keysym = XK_s; break; - case Keyboard::T: keysym = XK_t; break; - case Keyboard::U: keysym = XK_u; break; - case Keyboard::V: keysym = XK_v; break; - case Keyboard::W: keysym = XK_w; break; - case Keyboard::X: keysym = XK_x; break; - case Keyboard::Y: keysym = XK_y; break; - case Keyboard::Z: keysym = XK_z; break; - case Keyboard::Num0: keysym = XK_0; break; - case Keyboard::Num1: keysym = XK_1; break; - case Keyboard::Num2: keysym = XK_2; break; - case Keyboard::Num3: keysym = XK_3; break; - case Keyboard::Num4: keysym = XK_4; break; - case Keyboard::Num5: keysym = XK_5; break; - case Keyboard::Num6: keysym = XK_6; break; - case Keyboard::Num7: keysym = XK_7; break; - case Keyboard::Num8: keysym = XK_8; break; - case Keyboard::Num9: keysym = XK_9; break; - default: keysym = 0; break; + case Keyboard::Key::LShift: keysym = XK_Shift_L; break; + case Keyboard::Key::RShift: keysym = XK_Shift_R; break; + case Keyboard::Key::LControl: keysym = XK_Control_L; break; + case Keyboard::Key::RControl: keysym = XK_Control_R; break; + case Keyboard::Key::LAlt: keysym = XK_Alt_L; break; + case Keyboard::Key::RAlt: keysym = XK_Alt_R; break; + case Keyboard::Key::LSystem: keysym = XK_Super_L; break; + case Keyboard::Key::RSystem: keysym = XK_Super_R; break; + case Keyboard::Key::Menu: keysym = XK_Menu; break; + case Keyboard::Key::Escape: keysym = XK_Escape; break; + case Keyboard::Key::SemiColon: keysym = XK_semicolon; break; + case Keyboard::Key::Slash: keysym = XK_slash; break; + case Keyboard::Key::Equal: keysym = XK_equal; break; + case Keyboard::Key::Dash: keysym = XK_minus; break; + case Keyboard::Key::LBracket: keysym = XK_bracketleft; break; + case Keyboard::Key::RBracket: keysym = XK_bracketright; break; + case Keyboard::Key::Comma: keysym = XK_comma; break; + case Keyboard::Key::Period: keysym = XK_period; break; + case Keyboard::Key::Quote: keysym = XK_apostrophe; break; + case Keyboard::Key::BackSlash: keysym = XK_backslash; break; + case Keyboard::Key::Tilde: keysym = XK_grave; break; + case Keyboard::Key::Space: keysym = XK_space; break; + case Keyboard::Key::Return: keysym = XK_Return; break; + case Keyboard::Key::BackSpace: keysym = XK_BackSpace; break; + case Keyboard::Key::Tab: keysym = XK_Tab; break; + case Keyboard::Key::PageUp: keysym = XK_Prior; break; + case Keyboard::Key::PageDown: keysym = XK_Next; break; + case Keyboard::Key::End: keysym = XK_End; break; + case Keyboard::Key::Home: keysym = XK_Home; break; + case Keyboard::Key::Insert: keysym = XK_Insert; break; + case Keyboard::Key::Delete: keysym = XK_Delete; break; + case Keyboard::Key::Add: keysym = XK_KP_Add; break; + case Keyboard::Key::Subtract: keysym = XK_KP_Subtract; break; + case Keyboard::Key::Multiply: keysym = XK_KP_Multiply; break; + case Keyboard::Key::Divide: keysym = XK_KP_Divide; break; + case Keyboard::Key::Pause: keysym = XK_Pause; break; + case Keyboard::Key::F1: keysym = XK_F1; break; + case Keyboard::Key::F2: keysym = XK_F2; break; + case Keyboard::Key::F3: keysym = XK_F3; break; + case Keyboard::Key::F4: keysym = XK_F4; break; + case Keyboard::Key::F5: keysym = XK_F5; break; + case Keyboard::Key::F6: keysym = XK_F6; break; + case Keyboard::Key::F7: keysym = XK_F7; break; + case Keyboard::Key::F8: keysym = XK_F8; break; + case Keyboard::Key::F9: keysym = XK_F9; break; + case Keyboard::Key::F10: keysym = XK_F10; break; + case Keyboard::Key::F11: keysym = XK_F11; break; + case Keyboard::Key::F12: keysym = XK_F12; break; + case Keyboard::Key::F13: keysym = XK_F13; break; + case Keyboard::Key::F14: keysym = XK_F14; break; + case Keyboard::Key::F15: keysym = XK_F15; break; + case Keyboard::Key::Left: keysym = XK_Left; break; + case Keyboard::Key::Right: keysym = XK_Right; break; + case Keyboard::Key::Up: keysym = XK_Up; break; + case Keyboard::Key::Down: keysym = XK_Down; break; + case Keyboard::Key::Numpad0: keysym = XK_KP_Insert; break; + case Keyboard::Key::Numpad1: keysym = XK_KP_End; break; + case Keyboard::Key::Numpad2: keysym = XK_KP_Down; break; + case Keyboard::Key::Numpad3: keysym = XK_KP_Page_Down; break; + case Keyboard::Key::Numpad4: keysym = XK_KP_Left; break; + case Keyboard::Key::Numpad5: keysym = XK_KP_Begin; break; + case Keyboard::Key::Numpad6: keysym = XK_KP_Right; break; + case Keyboard::Key::Numpad7: keysym = XK_KP_Home; break; + case Keyboard::Key::Numpad8: keysym = XK_KP_Up; break; + case Keyboard::Key::Numpad9: keysym = XK_KP_Page_Up; break; + case Keyboard::Key::A: keysym = XK_a; break; + case Keyboard::Key::B: keysym = XK_b; break; + case Keyboard::Key::C: keysym = XK_c; break; + case Keyboard::Key::D: keysym = XK_d; break; + case Keyboard::Key::E: keysym = XK_e; break; + case Keyboard::Key::F: keysym = XK_f; break; + case Keyboard::Key::G: keysym = XK_g; break; + case Keyboard::Key::H: keysym = XK_h; break; + case Keyboard::Key::I: keysym = XK_i; break; + case Keyboard::Key::J: keysym = XK_j; break; + case Keyboard::Key::K: keysym = XK_k; break; + case Keyboard::Key::L: keysym = XK_l; break; + case Keyboard::Key::M: keysym = XK_m; break; + case Keyboard::Key::N: keysym = XK_n; break; + case Keyboard::Key::O: keysym = XK_o; break; + case Keyboard::Key::P: keysym = XK_p; break; + case Keyboard::Key::Q: keysym = XK_q; break; + case Keyboard::Key::R: keysym = XK_r; break; + case Keyboard::Key::S: keysym = XK_s; break; + case Keyboard::Key::T: keysym = XK_t; break; + case Keyboard::Key::U: keysym = XK_u; break; + case Keyboard::Key::V: keysym = XK_v; break; + case Keyboard::Key::W: keysym = XK_w; break; + case Keyboard::Key::X: keysym = XK_x; break; + case Keyboard::Key::Y: keysym = XK_y; break; + case Keyboard::Key::Z: keysym = XK_z; break; + case Keyboard::Key::Num0: keysym = XK_0; break; + case Keyboard::Key::Num1: keysym = XK_1; break; + case Keyboard::Key::Num2: keysym = XK_2; break; + case Keyboard::Key::Num3: keysym = XK_3; break; + case Keyboard::Key::Num4: keysym = XK_4; break; + case Keyboard::Key::Num5: keysym = XK_5; break; + case Keyboard::Key::Num6: keysym = XK_6; break; + case Keyboard::Key::Num7: keysym = XK_7; break; + case Keyboard::Key::Num8: keysym = XK_8; break; + case Keyboard::Key::Num9: keysym = XK_9; break; + default: keysym = 0; break; } - // Sanity checks - if (key < 0 || key >= sf::Keyboard::KeyCount) - return false; - // Open a connection with the X server Display* display = OpenDisplay(); @@ -205,12 +201,12 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) switch (button) { - case Mouse::Left: return buttons & Button1Mask; - case Mouse::Right: return buttons & Button3Mask; - case Mouse::Middle: return buttons & Button2Mask; - case Mouse::XButton1: return false; // not supported by X - case Mouse::XButton2: return false; // not supported by X - default: return false; + case Mouse::Button::Left: return buttons & Button1Mask; + case Mouse::Button::Right: return buttons & Button3Mask; + case Mouse::Button::Middle: return buttons & Button2Mask; + case Mouse::Button::XButton1: return false; // not supported by X + case Mouse::Button::XButton2: return false; // not supported by X + default: return false; } } diff --git a/src/SFML/Window/Unix/JoystickImpl.cpp b/src/SFML/Window/Unix/JoystickImpl.cpp index 7ca0de03..044412a7 100644 --- a/src/SFML/Window/Unix/JoystickImpl.cpp +++ b/src/SFML/Window/Unix/JoystickImpl.cpp @@ -613,16 +613,16 @@ JoystickCaps JoystickImpl::getCapabilities() const { switch (m_mapping[i]) { - case ABS_X: caps.axes[Joystick::X] = true; break; - case ABS_Y: caps.axes[Joystick::Y] = true; break; + case ABS_X: caps.axes[static_cast(Joystick::Axis::X)] = true; break; + case ABS_Y: caps.axes[static_cast(Joystick::Axis::Y)] = true; break; case ABS_Z: - case ABS_THROTTLE: caps.axes[Joystick::Z] = true; break; + case ABS_THROTTLE: caps.axes[static_cast(Joystick::Axis::Z)] = true; break; case ABS_RZ: - case ABS_RUDDER: caps.axes[Joystick::R] = true; break; - case ABS_RX: caps.axes[Joystick::U] = true; break; - case ABS_RY: caps.axes[Joystick::V] = true; break; - case ABS_HAT0X: caps.axes[Joystick::PovX] = true; break; - case ABS_HAT0Y: caps.axes[Joystick::PovY] = true; break; + case ABS_RUDDER: caps.axes[static_cast(Joystick::Axis::R)] = true; break; + case ABS_RX: caps.axes[static_cast(Joystick::Axis::U)] = true; break; + case ABS_RY: caps.axes[static_cast(Joystick::Axis::V)] = true; break; + case ABS_HAT0X: caps.axes[static_cast(Joystick::Axis::PovX)] = true; break; + case ABS_HAT0Y: caps.axes[static_cast(Joystick::Axis::PovY)] = true; break; default: break; } } @@ -663,16 +663,16 @@ JoystickState JoystickImpl::JoystickImpl::update() { switch (m_mapping[joyState.number]) { - case ABS_X: m_state.axes[Joystick::X] = value; break; - case ABS_Y: m_state.axes[Joystick::Y] = value; break; + case ABS_X: m_state.axes[static_cast(Joystick::Axis::X)] = value; break; + case ABS_Y: m_state.axes[static_cast(Joystick::Axis::Y)] = value; break; case ABS_Z: - case ABS_THROTTLE: m_state.axes[Joystick::Z] = value; break; + case ABS_THROTTLE: m_state.axes[static_cast(Joystick::Axis::Z)] = value; break; case ABS_RZ: - case ABS_RUDDER: m_state.axes[Joystick::R] = value; break; - case ABS_RX: m_state.axes[Joystick::U] = value; break; - case ABS_RY: m_state.axes[Joystick::V] = value; break; - case ABS_HAT0X: m_state.axes[Joystick::PovX] = value; break; - case ABS_HAT0Y: m_state.axes[Joystick::PovY] = value; break; + case ABS_RUDDER: m_state.axes[static_cast(Joystick::Axis::R)] = value; break; + case ABS_RX: m_state.axes[static_cast(Joystick::Axis::U)] = value; break; + case ABS_RY: m_state.axes[static_cast(Joystick::Axis::V)] = value; break; + case ABS_HAT0X: m_state.axes[static_cast(Joystick::Axis::PovX)] = value; break; + case ABS_HAT0Y: m_state.axes[static_cast(Joystick::Axis::PovY)] = value; break; default: break; } } diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 7553aa41..af9c9acf 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -264,111 +264,111 @@ namespace { switch (symbol) { - case XK_Shift_L: return sf::Keyboard::LShift; - case XK_Shift_R: return sf::Keyboard::RShift; - case XK_Control_L: return sf::Keyboard::LControl; - case XK_Control_R: return sf::Keyboard::RControl; - case XK_Alt_L: return sf::Keyboard::LAlt; - case XK_Alt_R: return sf::Keyboard::RAlt; - case XK_Super_L: return sf::Keyboard::LSystem; - case XK_Super_R: return sf::Keyboard::RSystem; - case XK_Menu: return sf::Keyboard::Menu; - case XK_Escape: return sf::Keyboard::Escape; - case XK_semicolon: return sf::Keyboard::SemiColon; - case XK_slash: return sf::Keyboard::Slash; - case XK_equal: return sf::Keyboard::Equal; - case XK_minus: return sf::Keyboard::Dash; - case XK_bracketleft: return sf::Keyboard::LBracket; - case XK_bracketright: return sf::Keyboard::RBracket; - case XK_comma: return sf::Keyboard::Comma; - case XK_period: return sf::Keyboard::Period; - case XK_apostrophe: return sf::Keyboard::Quote; - case XK_backslash: return sf::Keyboard::BackSlash; - case XK_grave: return sf::Keyboard::Tilde; - case XK_space: return sf::Keyboard::Space; - case XK_Return: return sf::Keyboard::Return; - case XK_KP_Enter: return sf::Keyboard::Return; - case XK_BackSpace: return sf::Keyboard::BackSpace; - case XK_Tab: return sf::Keyboard::Tab; - case XK_Prior: return sf::Keyboard::PageUp; - case XK_Next: return sf::Keyboard::PageDown; - case XK_End: return sf::Keyboard::End; - case XK_Home: return sf::Keyboard::Home; - case XK_Insert: return sf::Keyboard::Insert; - case XK_Delete: return sf::Keyboard::Delete; - case XK_KP_Add: return sf::Keyboard::Add; - case XK_KP_Subtract: return sf::Keyboard::Subtract; - case XK_KP_Multiply: return sf::Keyboard::Multiply; - case XK_KP_Divide: return sf::Keyboard::Divide; - case XK_Pause: return sf::Keyboard::Pause; - case XK_F1: return sf::Keyboard::F1; - case XK_F2: return sf::Keyboard::F2; - case XK_F3: return sf::Keyboard::F3; - case XK_F4: return sf::Keyboard::F4; - case XK_F5: return sf::Keyboard::F5; - case XK_F6: return sf::Keyboard::F6; - case XK_F7: return sf::Keyboard::F7; - case XK_F8: return sf::Keyboard::F8; - case XK_F9: return sf::Keyboard::F9; - case XK_F10: return sf::Keyboard::F10; - case XK_F11: return sf::Keyboard::F11; - case XK_F12: return sf::Keyboard::F12; - case XK_F13: return sf::Keyboard::F13; - case XK_F14: return sf::Keyboard::F14; - case XK_F15: return sf::Keyboard::F15; - case XK_Left: return sf::Keyboard::Left; - case XK_Right: return sf::Keyboard::Right; - case XK_Up: return sf::Keyboard::Up; - case XK_Down: return sf::Keyboard::Down; - case XK_KP_Insert: return sf::Keyboard::Numpad0; - case XK_KP_End: return sf::Keyboard::Numpad1; - case XK_KP_Down: return sf::Keyboard::Numpad2; - case XK_KP_Page_Down: return sf::Keyboard::Numpad3; - case XK_KP_Left: return sf::Keyboard::Numpad4; - case XK_KP_Begin: return sf::Keyboard::Numpad5; - case XK_KP_Right: return sf::Keyboard::Numpad6; - case XK_KP_Home: return sf::Keyboard::Numpad7; - case XK_KP_Up: return sf::Keyboard::Numpad8; - case XK_KP_Page_Up: return sf::Keyboard::Numpad9; - case XK_a: return sf::Keyboard::A; - case XK_b: return sf::Keyboard::B; - case XK_c: return sf::Keyboard::C; - case XK_d: return sf::Keyboard::D; - case XK_e: return sf::Keyboard::E; - case XK_f: return sf::Keyboard::F; - case XK_g: return sf::Keyboard::G; - case XK_h: return sf::Keyboard::H; - case XK_i: return sf::Keyboard::I; - case XK_j: return sf::Keyboard::J; - case XK_k: return sf::Keyboard::K; - case XK_l: return sf::Keyboard::L; - case XK_m: return sf::Keyboard::M; - case XK_n: return sf::Keyboard::N; - case XK_o: return sf::Keyboard::O; - case XK_p: return sf::Keyboard::P; - case XK_q: return sf::Keyboard::Q; - case XK_r: return sf::Keyboard::R; - case XK_s: return sf::Keyboard::S; - case XK_t: return sf::Keyboard::T; - case XK_u: return sf::Keyboard::U; - case XK_v: return sf::Keyboard::V; - case XK_w: return sf::Keyboard::W; - case XK_x: return sf::Keyboard::X; - case XK_y: return sf::Keyboard::Y; - case XK_z: return sf::Keyboard::Z; - case XK_0: return sf::Keyboard::Num0; - case XK_1: return sf::Keyboard::Num1; - case XK_2: return sf::Keyboard::Num2; - case XK_3: return sf::Keyboard::Num3; - case XK_4: return sf::Keyboard::Num4; - case XK_5: return sf::Keyboard::Num5; - case XK_6: return sf::Keyboard::Num6; - case XK_7: return sf::Keyboard::Num7; - case XK_8: return sf::Keyboard::Num8; - case XK_9: return sf::Keyboard::Num9; + case XK_Shift_L: return sf::Keyboard::Key::LShift; + case XK_Shift_R: return sf::Keyboard::Key::RShift; + case XK_Control_L: return sf::Keyboard::Key::LControl; + case XK_Control_R: return sf::Keyboard::Key::RControl; + case XK_Alt_L: return sf::Keyboard::Key::LAlt; + case XK_Alt_R: return sf::Keyboard::Key::RAlt; + case XK_Super_L: return sf::Keyboard::Key::LSystem; + case XK_Super_R: return sf::Keyboard::Key::RSystem; + case XK_Menu: return sf::Keyboard::Key::Menu; + case XK_Escape: return sf::Keyboard::Key::Escape; + case XK_semicolon: return sf::Keyboard::Key::SemiColon; + case XK_slash: return sf::Keyboard::Key::Slash; + case XK_equal: return sf::Keyboard::Key::Equal; + case XK_minus: return sf::Keyboard::Key::Dash; + case XK_bracketleft: return sf::Keyboard::Key::LBracket; + case XK_bracketright: return sf::Keyboard::Key::RBracket; + case XK_comma: return sf::Keyboard::Key::Comma; + case XK_period: return sf::Keyboard::Key::Period; + case XK_apostrophe: return sf::Keyboard::Key::Quote; + case XK_backslash: return sf::Keyboard::Key::BackSlash; + case XK_grave: return sf::Keyboard::Key::Tilde; + case XK_space: return sf::Keyboard::Key::Space; + case XK_Return: return sf::Keyboard::Key::Return; + case XK_KP_Enter: return sf::Keyboard::Key::Return; + case XK_BackSpace: return sf::Keyboard::Key::BackSpace; + case XK_Tab: return sf::Keyboard::Key::Tab; + case XK_Prior: return sf::Keyboard::Key::PageUp; + case XK_Next: return sf::Keyboard::Key::PageDown; + case XK_End: return sf::Keyboard::Key::End; + case XK_Home: return sf::Keyboard::Key::Home; + case XK_Insert: return sf::Keyboard::Key::Insert; + case XK_Delete: return sf::Keyboard::Key::Delete; + case XK_KP_Add: return sf::Keyboard::Key::Add; + case XK_KP_Subtract: return sf::Keyboard::Key::Subtract; + case XK_KP_Multiply: return sf::Keyboard::Key::Multiply; + case XK_KP_Divide: return sf::Keyboard::Key::Divide; + case XK_Pause: return sf::Keyboard::Key::Pause; + case XK_F1: return sf::Keyboard::Key::F1; + case XK_F2: return sf::Keyboard::Key::F2; + case XK_F3: return sf::Keyboard::Key::F3; + case XK_F4: return sf::Keyboard::Key::F4; + case XK_F5: return sf::Keyboard::Key::F5; + case XK_F6: return sf::Keyboard::Key::F6; + case XK_F7: return sf::Keyboard::Key::F7; + case XK_F8: return sf::Keyboard::Key::F8; + case XK_F9: return sf::Keyboard::Key::F9; + case XK_F10: return sf::Keyboard::Key::F10; + case XK_F11: return sf::Keyboard::Key::F11; + case XK_F12: return sf::Keyboard::Key::F12; + case XK_F13: return sf::Keyboard::Key::F13; + case XK_F14: return sf::Keyboard::Key::F14; + case XK_F15: return sf::Keyboard::Key::F15; + case XK_Left: return sf::Keyboard::Key::Left; + case XK_Right: return sf::Keyboard::Key::Right; + case XK_Up: return sf::Keyboard::Key::Up; + case XK_Down: return sf::Keyboard::Key::Down; + case XK_KP_Insert: return sf::Keyboard::Key::Numpad0; + case XK_KP_End: return sf::Keyboard::Key::Numpad1; + case XK_KP_Down: return sf::Keyboard::Key::Numpad2; + case XK_KP_Page_Down: return sf::Keyboard::Key::Numpad3; + case XK_KP_Left: return sf::Keyboard::Key::Numpad4; + case XK_KP_Begin: return sf::Keyboard::Key::Numpad5; + case XK_KP_Right: return sf::Keyboard::Key::Numpad6; + case XK_KP_Home: return sf::Keyboard::Key::Numpad7; + case XK_KP_Up: return sf::Keyboard::Key::Numpad8; + case XK_KP_Page_Up: return sf::Keyboard::Key::Numpad9; + case XK_a: return sf::Keyboard::Key::A; + case XK_b: return sf::Keyboard::Key::B; + case XK_c: return sf::Keyboard::Key::C; + case XK_d: return sf::Keyboard::Key::D; + case XK_e: return sf::Keyboard::Key::E; + case XK_f: return sf::Keyboard::Key::F; + case XK_g: return sf::Keyboard::Key::G; + case XK_h: return sf::Keyboard::Key::H; + case XK_i: return sf::Keyboard::Key::I; + case XK_j: return sf::Keyboard::Key::J; + case XK_k: return sf::Keyboard::Key::K; + case XK_l: return sf::Keyboard::Key::L; + case XK_m: return sf::Keyboard::Key::M; + case XK_n: return sf::Keyboard::Key::N; + case XK_o: return sf::Keyboard::Key::O; + case XK_p: return sf::Keyboard::Key::P; + case XK_q: return sf::Keyboard::Key::Q; + case XK_r: return sf::Keyboard::Key::R; + case XK_s: return sf::Keyboard::Key::S; + case XK_t: return sf::Keyboard::Key::T; + case XK_u: return sf::Keyboard::Key::U; + case XK_v: return sf::Keyboard::Key::V; + case XK_w: return sf::Keyboard::Key::W; + case XK_x: return sf::Keyboard::Key::X; + case XK_y: return sf::Keyboard::Key::Y; + case XK_z: return sf::Keyboard::Key::Z; + case XK_0: return sf::Keyboard::Key::Num0; + case XK_1: return sf::Keyboard::Key::Num1; + case XK_2: return sf::Keyboard::Key::Num2; + case XK_3: return sf::Keyboard::Key::Num3; + case XK_4: return sf::Keyboard::Key::Num4; + case XK_5: return sf::Keyboard::Key::Num5; + case XK_6: return sf::Keyboard::Key::Num6; + case XK_7: return sf::Keyboard::Key::Num7; + case XK_8: return sf::Keyboard::Key::Num8; + case XK_9: return sf::Keyboard::Key::Num9; } - return sf::Keyboard::Unknown; + return sf::Keyboard::Key::Unknown; } } @@ -1451,7 +1451,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) } Event event; - event.type = Event::GainedFocus; + event.type = Event::Type::GainedFocus; pushEvent(event); // If the window has been previously marked urgent (notification) as a result of a focus request, undo that @@ -1479,7 +1479,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) XUngrabPointer(m_display, CurrentTime); Event event; - event.type = Event::LostFocus; + event.type = Event::Type::LostFocus; pushEvent(event); break; } @@ -1491,7 +1491,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) if ((windowEvent.xconfigure.width != m_previousSize.x) || (windowEvent.xconfigure.height != m_previousSize.y)) { Event event; - event.type = Event::Resized; + event.type = Event::Type::Resized; event.size.width = windowEvent.xconfigure.width; event.size.height = windowEvent.xconfigure.height; pushEvent(event); @@ -1517,7 +1517,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) { // Handle the WM_DELETE_WINDOW message Event event; - event.type = Event::Closed; + event.type = Event::Type::Closed; pushEvent(event); } else if (netWmPing && (windowEvent.xclient.format == 32) && (windowEvent.xclient.data.l[0]) == static_cast(netWmPing)) @@ -1534,7 +1534,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // Key down event case KeyPress: { - Keyboard::Key key = Keyboard::Unknown; + Keyboard::Key key = Keyboard::Key::Unknown; // Try each KeySym index (modifier group) until we get a match for (int i = 0; i < 4; ++i) @@ -1542,14 +1542,14 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // Get the SFML keyboard code from the keysym of the key that has been pressed key = keysymToSF(XLookupKeysym(&windowEvent.xkey, i)); - if (key != Keyboard::Unknown) + if (key != Keyboard::Key::Unknown) break; } // Fill the event parameters // TODO: if modifiers are wrong, use XGetModifierMapping to retrieve the actual modifiers mapping Event event; - event.type = Event::KeyPressed; + event.type = Event::Type::KeyPressed; event.key.code = key; event.key.alt = windowEvent.xkey.state & Mod1Mask; event.key.control = windowEvent.xkey.state & ControlMask; @@ -1582,7 +1582,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) if (unicode != 0) { Event textEvent; - textEvent.type = Event::TextEntered; + textEvent.type = Event::Type::TextEntered; textEvent.text.unicode = unicode; pushEvent(textEvent); } @@ -1596,7 +1596,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) if (XLookupString(&windowEvent.xkey, keyBuffer, sizeof(keyBuffer), nullptr, &status)) { Event textEvent; - textEvent.type = Event::TextEntered; + textEvent.type = Event::Type::TextEntered; textEvent.text.unicode = static_cast(keyBuffer[0]); pushEvent(textEvent); } @@ -1611,7 +1611,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // Key up event case KeyRelease: { - Keyboard::Key key = Keyboard::Unknown; + Keyboard::Key key = Keyboard::Key::Unknown; // Try each KeySym index (modifier group) until we get a match for (int i = 0; i < 4; ++i) @@ -1619,13 +1619,13 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // Get the SFML keyboard code from the keysym of the key that has been released key = keysymToSF(XLookupKeysym(&windowEvent.xkey, i)); - if (key != Keyboard::Unknown) + if (key != Keyboard::Key::Unknown) break; } // Fill the event parameters Event event; - event.type = Event::KeyReleased; + event.type = Event::Type::KeyReleased; event.key.code = key; event.key.alt = windowEvent.xkey.state & Mod1Mask; event.key.control = windowEvent.xkey.state & ControlMask; @@ -1649,16 +1649,16 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) (button == 9)) { Event event; - event.type = Event::MouseButtonPressed; + event.type = Event::Type::MouseButtonPressed; event.mouseButton.x = windowEvent.xbutton.x; event.mouseButton.y = windowEvent.xbutton.y; switch(button) { - case Button1: event.mouseButton.button = Mouse::Left; break; - case Button2: event.mouseButton.button = Mouse::Middle; break; - case Button3: event.mouseButton.button = Mouse::Right; break; - case 8: event.mouseButton.button = Mouse::XButton1; break; - case 9: event.mouseButton.button = Mouse::XButton2; break; + case Button1: event.mouseButton.button = Mouse::Button::Left; break; + case Button2: event.mouseButton.button = Mouse::Button::Middle; break; + case Button3: event.mouseButton.button = Mouse::Button::Right; break; + case 8: event.mouseButton.button = Mouse::Button::XButton1; break; + case 9: event.mouseButton.button = Mouse::Button::XButton2; break; } pushEvent(event); } @@ -1679,16 +1679,16 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) (button == 9)) { Event event; - event.type = Event::MouseButtonReleased; + event.type = Event::Type::MouseButtonReleased; event.mouseButton.x = windowEvent.xbutton.x; event.mouseButton.y = windowEvent.xbutton.y; switch(button) { - case Button1: event.mouseButton.button = Mouse::Left; break; - case Button2: event.mouseButton.button = Mouse::Middle; break; - case Button3: event.mouseButton.button = Mouse::Right; break; - case 8: event.mouseButton.button = Mouse::XButton1; break; - case 9: event.mouseButton.button = Mouse::XButton2; break; + case Button1: event.mouseButton.button = Mouse::Button::Left; break; + case Button2: event.mouseButton.button = Mouse::Button::Middle; break; + case Button3: event.mouseButton.button = Mouse::Button::Right; break; + case 8: event.mouseButton.button = Mouse::Button::XButton1; break; + case 9: event.mouseButton.button = Mouse::Button::XButton2; break; } pushEvent(event); } @@ -1696,14 +1696,14 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) { Event event; - event.type = Event::MouseWheelMoved; + event.type = Event::Type::MouseWheelMoved; event.mouseWheel.delta = (button == Button4) ? 1 : -1; event.mouseWheel.x = windowEvent.xbutton.x; event.mouseWheel.y = windowEvent.xbutton.y; pushEvent(event); - event.type = Event::MouseWheelScrolled; - event.mouseWheelScroll.wheel = Mouse::VerticalWheel; + event.type = Event::Type::MouseWheelScrolled; + event.mouseWheelScroll.wheel = Mouse::Wheel::VerticalWheel; event.mouseWheelScroll.delta = (button == Button4) ? 1 : -1; event.mouseWheelScroll.x = windowEvent.xbutton.x; event.mouseWheelScroll.y = windowEvent.xbutton.y; @@ -1712,8 +1712,8 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) else if ((button == 6) || (button == 7)) { Event event; - event.type = Event::MouseWheelScrolled; - event.mouseWheelScroll.wheel = Mouse::HorizontalWheel; + event.type = Event::Type::MouseWheelScrolled; + event.mouseWheelScroll.wheel = Mouse::Wheel::HorizontalWheel; event.mouseWheelScroll.delta = (button == 6) ? 1 : -1; event.mouseWheelScroll.x = windowEvent.xbutton.x; event.mouseWheelScroll.y = windowEvent.xbutton.y; @@ -1726,7 +1726,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) case MotionNotify: { Event event; - event.type = Event::MouseMoved; + event.type = Event::Type::MouseMoved; event.mouseMove.x = windowEvent.xmotion.x; event.mouseMove.y = windowEvent.xmotion.y; pushEvent(event); @@ -1739,7 +1739,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) if (windowEvent.xcrossing.mode == NotifyNormal) { Event event; - event.type = Event::MouseEntered; + event.type = Event::Type::MouseEntered; pushEvent(event); } break; @@ -1751,7 +1751,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) if (windowEvent.xcrossing.mode == NotifyNormal) { Event event; - event.type = Event::MouseLeft; + event.type = Event::Type::MouseLeft; pushEvent(event); } break; diff --git a/src/SFML/Window/Win32/InputImpl.cpp b/src/SFML/Window/Win32/InputImpl.cpp index d5d3e566..cdd69f70 100644 --- a/src/SFML/Window/Win32/InputImpl.cpp +++ b/src/SFML/Window/Win32/InputImpl.cpp @@ -49,107 +49,107 @@ bool InputImpl::isKeyPressed(Keyboard::Key key) switch (key) { default: vkey = 0; break; - case Keyboard::A: vkey = 'A'; break; - case Keyboard::B: vkey = 'B'; break; - case Keyboard::C: vkey = 'C'; break; - case Keyboard::D: vkey = 'D'; break; - case Keyboard::E: vkey = 'E'; break; - case Keyboard::F: vkey = 'F'; break; - case Keyboard::G: vkey = 'G'; break; - case Keyboard::H: vkey = 'H'; break; - case Keyboard::I: vkey = 'I'; break; - case Keyboard::J: vkey = 'J'; break; - case Keyboard::K: vkey = 'K'; break; - case Keyboard::L: vkey = 'L'; break; - case Keyboard::M: vkey = 'M'; break; - case Keyboard::N: vkey = 'N'; break; - case Keyboard::O: vkey = 'O'; break; - case Keyboard::P: vkey = 'P'; break; - case Keyboard::Q: vkey = 'Q'; break; - case Keyboard::R: vkey = 'R'; break; - case Keyboard::S: vkey = 'S'; break; - case Keyboard::T: vkey = 'T'; break; - case Keyboard::U: vkey = 'U'; break; - case Keyboard::V: vkey = 'V'; break; - case Keyboard::W: vkey = 'W'; break; - case Keyboard::X: vkey = 'X'; break; - case Keyboard::Y: vkey = 'Y'; break; - case Keyboard::Z: vkey = 'Z'; break; - case Keyboard::Num0: vkey = '0'; break; - case Keyboard::Num1: vkey = '1'; break; - case Keyboard::Num2: vkey = '2'; break; - case Keyboard::Num3: vkey = '3'; break; - case Keyboard::Num4: vkey = '4'; break; - case Keyboard::Num5: vkey = '5'; break; - case Keyboard::Num6: vkey = '6'; break; - case Keyboard::Num7: vkey = '7'; break; - case Keyboard::Num8: vkey = '8'; break; - case Keyboard::Num9: vkey = '9'; break; - case Keyboard::Escape: vkey = VK_ESCAPE; break; - case Keyboard::LControl: vkey = VK_LCONTROL; break; - case Keyboard::LShift: vkey = VK_LSHIFT; break; - case Keyboard::LAlt: vkey = VK_LMENU; break; - case Keyboard::LSystem: vkey = VK_LWIN; break; - case Keyboard::RControl: vkey = VK_RCONTROL; break; - case Keyboard::RShift: vkey = VK_RSHIFT; break; - case Keyboard::RAlt: vkey = VK_RMENU; break; - case Keyboard::RSystem: vkey = VK_RWIN; break; - case Keyboard::Menu: vkey = VK_APPS; break; - case Keyboard::LBracket: vkey = VK_OEM_4; break; - case Keyboard::RBracket: vkey = VK_OEM_6; break; - case Keyboard::SemiColon: vkey = VK_OEM_1; break; - case Keyboard::Comma: vkey = VK_OEM_COMMA; break; - case Keyboard::Period: vkey = VK_OEM_PERIOD; break; - case Keyboard::Quote: vkey = VK_OEM_7; break; - case Keyboard::Slash: vkey = VK_OEM_2; break; - case Keyboard::BackSlash: vkey = VK_OEM_5; break; - case Keyboard::Tilde: vkey = VK_OEM_3; break; - case Keyboard::Equal: vkey = VK_OEM_PLUS; break; - case Keyboard::Dash: vkey = VK_OEM_MINUS; break; - case Keyboard::Space: vkey = VK_SPACE; break; - case Keyboard::Return: vkey = VK_RETURN; break; - case Keyboard::BackSpace: vkey = VK_BACK; break; - case Keyboard::Tab: vkey = VK_TAB; break; - case Keyboard::PageUp: vkey = VK_PRIOR; break; - case Keyboard::PageDown: vkey = VK_NEXT; break; - case Keyboard::End: vkey = VK_END; break; - case Keyboard::Home: vkey = VK_HOME; break; - case Keyboard::Insert: vkey = VK_INSERT; break; - case Keyboard::Delete: vkey = VK_DELETE; break; - case Keyboard::Add: vkey = VK_ADD; break; - case Keyboard::Subtract: vkey = VK_SUBTRACT; break; - case Keyboard::Multiply: vkey = VK_MULTIPLY; break; - case Keyboard::Divide: vkey = VK_DIVIDE; break; - case Keyboard::Left: vkey = VK_LEFT; break; - case Keyboard::Right: vkey = VK_RIGHT; break; - case Keyboard::Up: vkey = VK_UP; break; - case Keyboard::Down: vkey = VK_DOWN; break; - case Keyboard::Numpad0: vkey = VK_NUMPAD0; break; - case Keyboard::Numpad1: vkey = VK_NUMPAD1; break; - case Keyboard::Numpad2: vkey = VK_NUMPAD2; break; - case Keyboard::Numpad3: vkey = VK_NUMPAD3; break; - case Keyboard::Numpad4: vkey = VK_NUMPAD4; break; - case Keyboard::Numpad5: vkey = VK_NUMPAD5; break; - case Keyboard::Numpad6: vkey = VK_NUMPAD6; break; - case Keyboard::Numpad7: vkey = VK_NUMPAD7; break; - case Keyboard::Numpad8: vkey = VK_NUMPAD8; break; - case Keyboard::Numpad9: vkey = VK_NUMPAD9; break; - case Keyboard::F1: vkey = VK_F1; break; - case Keyboard::F2: vkey = VK_F2; break; - case Keyboard::F3: vkey = VK_F3; break; - case Keyboard::F4: vkey = VK_F4; break; - case Keyboard::F5: vkey = VK_F5; break; - case Keyboard::F6: vkey = VK_F6; break; - case Keyboard::F7: vkey = VK_F7; break; - case Keyboard::F8: vkey = VK_F8; break; - case Keyboard::F9: vkey = VK_F9; break; - case Keyboard::F10: vkey = VK_F10; break; - case Keyboard::F11: vkey = VK_F11; break; - case Keyboard::F12: vkey = VK_F12; break; - case Keyboard::F13: vkey = VK_F13; break; - case Keyboard::F14: vkey = VK_F14; break; - case Keyboard::F15: vkey = VK_F15; break; - case Keyboard::Pause: vkey = VK_PAUSE; break; + case Keyboard::Key::A: vkey = 'A'; break; + case Keyboard::Key::B: vkey = 'B'; break; + case Keyboard::Key::C: vkey = 'C'; break; + case Keyboard::Key::D: vkey = 'D'; break; + case Keyboard::Key::E: vkey = 'E'; break; + case Keyboard::Key::F: vkey = 'F'; break; + case Keyboard::Key::G: vkey = 'G'; break; + case Keyboard::Key::H: vkey = 'H'; break; + case Keyboard::Key::I: vkey = 'I'; break; + case Keyboard::Key::J: vkey = 'J'; break; + case Keyboard::Key::K: vkey = 'K'; break; + case Keyboard::Key::L: vkey = 'L'; break; + case Keyboard::Key::M: vkey = 'M'; break; + case Keyboard::Key::N: vkey = 'N'; break; + case Keyboard::Key::O: vkey = 'O'; break; + case Keyboard::Key::P: vkey = 'P'; break; + case Keyboard::Key::Q: vkey = 'Q'; break; + case Keyboard::Key::R: vkey = 'R'; break; + case Keyboard::Key::S: vkey = 'S'; break; + case Keyboard::Key::T: vkey = 'T'; break; + case Keyboard::Key::U: vkey = 'U'; break; + case Keyboard::Key::V: vkey = 'V'; break; + case Keyboard::Key::W: vkey = 'W'; break; + case Keyboard::Key::X: vkey = 'X'; break; + case Keyboard::Key::Y: vkey = 'Y'; break; + case Keyboard::Key::Z: vkey = 'Z'; break; + case Keyboard::Key::Num0: vkey = '0'; break; + case Keyboard::Key::Num1: vkey = '1'; break; + case Keyboard::Key::Num2: vkey = '2'; break; + case Keyboard::Key::Num3: vkey = '3'; break; + case Keyboard::Key::Num4: vkey = '4'; break; + case Keyboard::Key::Num5: vkey = '5'; break; + case Keyboard::Key::Num6: vkey = '6'; break; + case Keyboard::Key::Num7: vkey = '7'; break; + case Keyboard::Key::Num8: vkey = '8'; break; + case Keyboard::Key::Num9: vkey = '9'; break; + case Keyboard::Key::Escape: vkey = VK_ESCAPE; break; + case Keyboard::Key::LControl: vkey = VK_LCONTROL; break; + case Keyboard::Key::LShift: vkey = VK_LSHIFT; break; + case Keyboard::Key::LAlt: vkey = VK_LMENU; break; + case Keyboard::Key::LSystem: vkey = VK_LWIN; break; + case Keyboard::Key::RControl: vkey = VK_RCONTROL; break; + case Keyboard::Key::RShift: vkey = VK_RSHIFT; break; + case Keyboard::Key::RAlt: vkey = VK_RMENU; break; + case Keyboard::Key::RSystem: vkey = VK_RWIN; break; + case Keyboard::Key::Menu: vkey = VK_APPS; break; + case Keyboard::Key::LBracket: vkey = VK_OEM_4; break; + case Keyboard::Key::RBracket: vkey = VK_OEM_6; break; + case Keyboard::Key::SemiColon: vkey = VK_OEM_1; break; + case Keyboard::Key::Comma: vkey = VK_OEM_COMMA; break; + case Keyboard::Key::Period: vkey = VK_OEM_PERIOD; break; + case Keyboard::Key::Quote: vkey = VK_OEM_7; break; + case Keyboard::Key::Slash: vkey = VK_OEM_2; break; + case Keyboard::Key::BackSlash: vkey = VK_OEM_5; break; + case Keyboard::Key::Tilde: vkey = VK_OEM_3; break; + case Keyboard::Key::Equal: vkey = VK_OEM_PLUS; break; + case Keyboard::Key::Dash: vkey = VK_OEM_MINUS; break; + case Keyboard::Key::Space: vkey = VK_SPACE; break; + case Keyboard::Key::Return: vkey = VK_RETURN; break; + case Keyboard::Key::BackSpace: vkey = VK_BACK; break; + case Keyboard::Key::Tab: vkey = VK_TAB; break; + case Keyboard::Key::PageUp: vkey = VK_PRIOR; break; + case Keyboard::Key::PageDown: vkey = VK_NEXT; break; + case Keyboard::Key::End: vkey = VK_END; break; + case Keyboard::Key::Home: vkey = VK_HOME; break; + case Keyboard::Key::Insert: vkey = VK_INSERT; break; + case Keyboard::Key::Delete: vkey = VK_DELETE; break; + case Keyboard::Key::Add: vkey = VK_ADD; break; + case Keyboard::Key::Subtract: vkey = VK_SUBTRACT; break; + case Keyboard::Key::Multiply: vkey = VK_MULTIPLY; break; + case Keyboard::Key::Divide: vkey = VK_DIVIDE; break; + case Keyboard::Key::Left: vkey = VK_LEFT; break; + case Keyboard::Key::Right: vkey = VK_RIGHT; break; + case Keyboard::Key::Up: vkey = VK_UP; break; + case Keyboard::Key::Down: vkey = VK_DOWN; break; + case Keyboard::Key::Numpad0: vkey = VK_NUMPAD0; break; + case Keyboard::Key::Numpad1: vkey = VK_NUMPAD1; break; + case Keyboard::Key::Numpad2: vkey = VK_NUMPAD2; break; + case Keyboard::Key::Numpad3: vkey = VK_NUMPAD3; break; + case Keyboard::Key::Numpad4: vkey = VK_NUMPAD4; break; + case Keyboard::Key::Numpad5: vkey = VK_NUMPAD5; break; + case Keyboard::Key::Numpad6: vkey = VK_NUMPAD6; break; + case Keyboard::Key::Numpad7: vkey = VK_NUMPAD7; break; + case Keyboard::Key::Numpad8: vkey = VK_NUMPAD8; break; + case Keyboard::Key::Numpad9: vkey = VK_NUMPAD9; break; + case Keyboard::Key::F1: vkey = VK_F1; break; + case Keyboard::Key::F2: vkey = VK_F2; break; + case Keyboard::Key::F3: vkey = VK_F3; break; + case Keyboard::Key::F4: vkey = VK_F4; break; + case Keyboard::Key::F5: vkey = VK_F5; break; + case Keyboard::Key::F6: vkey = VK_F6; break; + case Keyboard::Key::F7: vkey = VK_F7; break; + case Keyboard::Key::F8: vkey = VK_F8; break; + case Keyboard::Key::F9: vkey = VK_F9; break; + case Keyboard::Key::F10: vkey = VK_F10; break; + case Keyboard::Key::F11: vkey = VK_F11; break; + case Keyboard::Key::F12: vkey = VK_F12; break; + case Keyboard::Key::F13: vkey = VK_F13; break; + case Keyboard::Key::F14: vkey = VK_F14; break; + case Keyboard::Key::F15: vkey = VK_F15; break; + case Keyboard::Key::Pause: vkey = VK_PAUSE; break; } return (GetAsyncKeyState(vkey) & 0x8000) != 0; @@ -169,12 +169,12 @@ bool InputImpl::isMouseButtonPressed(Mouse::Button button) int vkey = 0; switch (button) { - case Mouse::Left: vkey = GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON; break; - case Mouse::Right: vkey = GetSystemMetrics(SM_SWAPBUTTON) ? VK_LBUTTON : VK_RBUTTON; break; - case Mouse::Middle: vkey = VK_MBUTTON; break; - case Mouse::XButton1: vkey = VK_XBUTTON1; break; - case Mouse::XButton2: vkey = VK_XBUTTON2; break; - default: vkey = 0; break; + case Mouse::Button::Left: vkey = GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON; break; + case Mouse::Button::Right: vkey = GetSystemMetrics(SM_SWAPBUTTON) ? VK_LBUTTON : VK_RBUTTON; break; + case Mouse::Button::Middle: vkey = VK_MBUTTON; break; + case Mouse::Button::XButton1: vkey = VK_XBUTTON1; break; + case Mouse::Button::XButton2: vkey = VK_XBUTTON2; break; + default: vkey = 0; break; } return (GetAsyncKeyState(vkey) & 0x8000) != 0; diff --git a/src/SFML/Window/Win32/JoystickImpl.cpp b/src/SFML/Window/Win32/JoystickImpl.cpp index 820e1cee..a6159582 100644 --- a/src/SFML/Window/Win32/JoystickImpl.cpp +++ b/src/SFML/Window/Win32/JoystickImpl.cpp @@ -236,14 +236,14 @@ JoystickCaps JoystickImpl::getCapabilities() const if (caps.buttonCount > Joystick::ButtonCount) caps.buttonCount = Joystick::ButtonCount; - caps.axes[Joystick::X] = true; - caps.axes[Joystick::Y] = true; - caps.axes[Joystick::Z] = (m_caps.wCaps & JOYCAPS_HASZ) != 0; - caps.axes[Joystick::R] = (m_caps.wCaps & JOYCAPS_HASR) != 0; - caps.axes[Joystick::U] = (m_caps.wCaps & JOYCAPS_HASU) != 0; - caps.axes[Joystick::V] = (m_caps.wCaps & JOYCAPS_HASV) != 0; - caps.axes[Joystick::PovX] = (m_caps.wCaps & JOYCAPS_HASPOV) != 0; - caps.axes[Joystick::PovY] = (m_caps.wCaps & JOYCAPS_HASPOV) != 0; + caps.axes[static_cast(Joystick::Axis::X)] = true; + caps.axes[static_cast(Joystick::Axis::Y)] = true; + caps.axes[static_cast(Joystick::Axis::Z)] = (m_caps.wCaps & JOYCAPS_HASZ) != 0; + caps.axes[static_cast(Joystick::Axis::R)] = (m_caps.wCaps & JOYCAPS_HASR) != 0; + caps.axes[static_cast(Joystick::Axis::U)] = (m_caps.wCaps & JOYCAPS_HASU) != 0; + caps.axes[static_cast(Joystick::Axis::V)] = (m_caps.wCaps & JOYCAPS_HASV) != 0; + caps.axes[static_cast(Joystick::Axis::PovX)] = (m_caps.wCaps & JOYCAPS_HASPOV) != 0; + caps.axes[static_cast(Joystick::Axis::PovY)] = (m_caps.wCaps & JOYCAPS_HASPOV) != 0; return caps; } @@ -272,24 +272,24 @@ JoystickState JoystickImpl::update() state.connected = true; // Axes - state.axes[Joystick::X] = (pos.dwXpos - (m_caps.wXmax + m_caps.wXmin) / 2.f) * 200.f / (m_caps.wXmax - m_caps.wXmin); - state.axes[Joystick::Y] = (pos.dwYpos - (m_caps.wYmax + m_caps.wYmin) / 2.f) * 200.f / (m_caps.wYmax - m_caps.wYmin); - state.axes[Joystick::Z] = (pos.dwZpos - (m_caps.wZmax + m_caps.wZmin) / 2.f) * 200.f / (m_caps.wZmax - m_caps.wZmin); - state.axes[Joystick::R] = (pos.dwRpos - (m_caps.wRmax + m_caps.wRmin) / 2.f) * 200.f / (m_caps.wRmax - m_caps.wRmin); - state.axes[Joystick::U] = (pos.dwUpos - (m_caps.wUmax + m_caps.wUmin) / 2.f) * 200.f / (m_caps.wUmax - m_caps.wUmin); - state.axes[Joystick::V] = (pos.dwVpos - (m_caps.wVmax + m_caps.wVmin) / 2.f) * 200.f / (m_caps.wVmax - m_caps.wVmin); + state.axes[static_cast(Joystick::Axis::X)] = (pos.dwXpos - (m_caps.wXmax + m_caps.wXmin) / 2.f) * 200.f / (m_caps.wXmax - m_caps.wXmin); + state.axes[static_cast(Joystick::Axis::Y)] = (pos.dwYpos - (m_caps.wYmax + m_caps.wYmin) / 2.f) * 200.f / (m_caps.wYmax - m_caps.wYmin); + state.axes[static_cast(Joystick::Axis::Z)] = (pos.dwZpos - (m_caps.wZmax + m_caps.wZmin) / 2.f) * 200.f / (m_caps.wZmax - m_caps.wZmin); + state.axes[static_cast(Joystick::Axis::R)] = (pos.dwRpos - (m_caps.wRmax + m_caps.wRmin) / 2.f) * 200.f / (m_caps.wRmax - m_caps.wRmin); + state.axes[static_cast(Joystick::Axis::U)] = (pos.dwUpos - (m_caps.wUmax + m_caps.wUmin) / 2.f) * 200.f / (m_caps.wUmax - m_caps.wUmin); + state.axes[static_cast(Joystick::Axis::V)] = (pos.dwVpos - (m_caps.wVmax + m_caps.wVmin) / 2.f) * 200.f / (m_caps.wVmax - m_caps.wVmin); // Special case for POV, it is given as an angle if (pos.dwPOV != 0xFFFF) { float angle = pos.dwPOV / 18000.f * 3.141592654f; - state.axes[Joystick::PovX] = std::sin(angle) * 100; - state.axes[Joystick::PovY] = std::cos(angle) * 100; + state.axes[static_cast(Joystick::Axis::PovX)] = std::sin(angle) * 100; + state.axes[static_cast(Joystick::Axis::PovY)] = std::cos(angle) * 100; } else { - state.axes[Joystick::PovX] = 0; - state.axes[Joystick::PovY] = 0; + state.axes[static_cast(Joystick::Axis::PovX)] = 0; + state.axes[static_cast(Joystick::Axis::PovY)] = 0; } // Buttons diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index e9fc32db..22a2a9f8 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -576,7 +576,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_CLOSE: { Event event; - event.type = Event::Closed; + event.type = Event::Type::Closed; pushEvent(event); break; } @@ -592,7 +592,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Push a resize event Event event; - event.type = Event::Resized; + event.type = Event::Type::Resized; event.size.width = m_lastSize.x; event.size.height = m_lastSize.y; pushEvent(event); @@ -624,7 +624,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Push a resize event Event event; - event.type = Event::Resized; + event.type = Event::Type::Resized; event.size.width = m_lastSize.x; event.size.height = m_lastSize.y; pushEvent(event); @@ -653,7 +653,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) grabCursor(m_cursorGrabbed); Event event; - event.type = Event::GainedFocus; + event.type = Event::Type::GainedFocus; pushEvent(event); break; } @@ -665,7 +665,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) grabCursor(false); Event event; - event.type = Event::LostFocus; + event.type = Event::Type::LostFocus; pushEvent(event); break; } @@ -697,7 +697,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Send a TextEntered event Event event; - event.type = Event::TextEntered; + event.type = Event::Type::TextEntered; event.text.unicode = character; pushEvent(event); } @@ -712,7 +712,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) if (m_keyRepeatEnabled || ((HIWORD(lParam) & KF_REPEAT) == 0)) { Event event; - event.type = Event::KeyPressed; + event.type = Event::Type::KeyPressed; event.key.alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0; event.key.control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0; event.key.shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0; @@ -728,7 +728,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_SYSKEYUP: { Event event; - event.type = Event::KeyReleased; + event.type = Event::Type::KeyReleased; event.key.alt = HIWORD(GetAsyncKeyState(VK_MENU)) != 0; event.key.control = HIWORD(GetAsyncKeyState(VK_CONTROL)) != 0; event.key.shift = HIWORD(GetAsyncKeyState(VK_SHIFT)) != 0; @@ -751,14 +751,14 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) Event event; - event.type = Event::MouseWheelMoved; + event.type = Event::Type::MouseWheelMoved; event.mouseWheel.delta = delta / 120; event.mouseWheel.x = position.x; event.mouseWheel.y = position.y; pushEvent(event); - event.type = Event::MouseWheelScrolled; - event.mouseWheelScroll.wheel = Mouse::VerticalWheel; + event.type = Event::Type::MouseWheelScrolled; + event.mouseWheelScroll.wheel = Mouse::Wheel::VerticalWheel; event.mouseWheelScroll.delta = static_cast(delta) / 120.f; event.mouseWheelScroll.x = position.x; event.mouseWheelScroll.y = position.y; @@ -778,8 +778,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) Int16 delta = static_cast(HIWORD(wParam)); Event event; - event.type = Event::MouseWheelScrolled; - event.mouseWheelScroll.wheel = Mouse::HorizontalWheel; + event.type = Event::Type::MouseWheelScrolled; + event.mouseWheelScroll.wheel = Mouse::Wheel::HorizontalWheel; event.mouseWheelScroll.delta = -static_cast(delta) / 120.f; event.mouseWheelScroll.x = position.x; event.mouseWheelScroll.y = position.y; @@ -791,8 +791,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_LBUTTONDOWN: { Event event; - event.type = Event::MouseButtonPressed; - event.mouseButton.button = Mouse::Left; + event.type = Event::Type::MouseButtonPressed; + event.mouseButton.button = Mouse::Button::Left; event.mouseButton.x = static_cast(LOWORD(lParam)); event.mouseButton.y = static_cast(HIWORD(lParam)); pushEvent(event); @@ -803,8 +803,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_LBUTTONUP: { Event event; - event.type = Event::MouseButtonReleased; - event.mouseButton.button = Mouse::Left; + event.type = Event::Type::MouseButtonReleased; + event.mouseButton.button = Mouse::Button::Left; event.mouseButton.x = static_cast(LOWORD(lParam)); event.mouseButton.y = static_cast(HIWORD(lParam)); pushEvent(event); @@ -815,8 +815,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_RBUTTONDOWN: { Event event; - event.type = Event::MouseButtonPressed; - event.mouseButton.button = Mouse::Right; + event.type = Event::Type::MouseButtonPressed; + event.mouseButton.button = Mouse::Button::Right; event.mouseButton.x = static_cast(LOWORD(lParam)); event.mouseButton.y = static_cast(HIWORD(lParam)); pushEvent(event); @@ -827,8 +827,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_RBUTTONUP: { Event event; - event.type = Event::MouseButtonReleased; - event.mouseButton.button = Mouse::Right; + event.type = Event::Type::MouseButtonReleased; + event.mouseButton.button = Mouse::Button::Right; event.mouseButton.x = static_cast(LOWORD(lParam)); event.mouseButton.y = static_cast(HIWORD(lParam)); pushEvent(event); @@ -839,8 +839,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_MBUTTONDOWN: { Event event; - event.type = Event::MouseButtonPressed; - event.mouseButton.button = Mouse::Middle; + event.type = Event::Type::MouseButtonPressed; + event.mouseButton.button = Mouse::Button::Middle; event.mouseButton.x = static_cast(LOWORD(lParam)); event.mouseButton.y = static_cast(HIWORD(lParam)); pushEvent(event); @@ -851,8 +851,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_MBUTTONUP: { Event event; - event.type = Event::MouseButtonReleased; - event.mouseButton.button = Mouse::Middle; + event.type = Event::Type::MouseButtonReleased; + event.mouseButton.button = Mouse::Button::Middle; event.mouseButton.x = static_cast(LOWORD(lParam)); event.mouseButton.y = static_cast(HIWORD(lParam)); pushEvent(event); @@ -863,8 +863,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_XBUTTONDOWN: { Event event; - event.type = Event::MouseButtonPressed; - event.mouseButton.button = HIWORD(wParam) == XBUTTON1 ? Mouse::XButton1 : Mouse::XButton2; + event.type = Event::Type::MouseButtonPressed; + event.mouseButton.button = HIWORD(wParam) == XBUTTON1 ? Mouse::Button::XButton1 : Mouse::Button::XButton2; event.mouseButton.x = static_cast(LOWORD(lParam)); event.mouseButton.y = static_cast(HIWORD(lParam)); pushEvent(event); @@ -875,8 +875,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) case WM_XBUTTONUP: { Event event; - event.type = Event::MouseButtonReleased; - event.mouseButton.button = HIWORD(wParam) == XBUTTON1 ? Mouse::XButton1 : Mouse::XButton2; + event.type = Event::Type::MouseButtonReleased; + event.mouseButton.button = HIWORD(wParam) == XBUTTON1 ? Mouse::Button::XButton1 : Mouse::Button::XButton2; event.mouseButton.x = static_cast(LOWORD(lParam)); event.mouseButton.y = static_cast(HIWORD(lParam)); pushEvent(event); @@ -893,7 +893,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Generate a MouseLeft event Event event; - event.type = Event::MouseLeft; + event.type = Event::Type::MouseLeft; pushEvent(event); } break; @@ -936,7 +936,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Generate a MouseLeft event Event event; - event.type = Event::MouseLeft; + event.type = Event::Type::MouseLeft; pushEvent(event); } } @@ -952,14 +952,14 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) // Generate a MouseEntered event Event event; - event.type = Event::MouseEntered; + event.type = Event::Type::MouseEntered; pushEvent(event); } } // Generate a MouseMove event Event event; - event.type = Event::MouseMoved; + event.type = Event::Type::MouseMoved; event.mouseMove.x = x; event.mouseMove.y = y; pushEvent(event); @@ -986,114 +986,114 @@ Keyboard::Key WindowImplWin32::virtualKeyCodeToSF(WPARAM key, LPARAM flags) { static const auto lShift = MapVirtualKeyW(VK_LSHIFT, MAPVK_VK_TO_VSC); UINT scancode = static_cast((flags & (0xFF << 16)) >> 16); - return scancode == lShift ? Keyboard::LShift : Keyboard::RShift; + return scancode == lShift ? Keyboard::Key::LShift : Keyboard::Key::RShift; } // Check the "extended" flag to distinguish between left and right alt - case VK_MENU : return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RAlt : Keyboard::LAlt; + case VK_MENU : return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::Key::RAlt : Keyboard::Key::LAlt; // Check the "extended" flag to distinguish between left and right control - case VK_CONTROL : return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RControl : Keyboard::LControl; + case VK_CONTROL : return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::Key::RControl : Keyboard::Key::LControl; // Other keys are reported properly - case VK_LWIN: return Keyboard::LSystem; - case VK_RWIN: return Keyboard::RSystem; - case VK_APPS: return Keyboard::Menu; - case VK_OEM_1: return Keyboard::SemiColon; - case VK_OEM_2: return Keyboard::Slash; - case VK_OEM_PLUS: return Keyboard::Equal; - case VK_OEM_MINUS: return Keyboard::Dash; - case VK_OEM_4: return Keyboard::LBracket; - case VK_OEM_6: return Keyboard::RBracket; - case VK_OEM_COMMA: return Keyboard::Comma; - case VK_OEM_PERIOD: return Keyboard::Period; - case VK_OEM_7: return Keyboard::Quote; - case VK_OEM_5: return Keyboard::BackSlash; - case VK_OEM_3: return Keyboard::Tilde; - case VK_ESCAPE: return Keyboard::Escape; - case VK_SPACE: return Keyboard::Space; - case VK_RETURN: return Keyboard::Return; - case VK_BACK: return Keyboard::BackSpace; - case VK_TAB: return Keyboard::Tab; - case VK_PRIOR: return Keyboard::PageUp; - case VK_NEXT: return Keyboard::PageDown; - case VK_END: return Keyboard::End; - case VK_HOME: return Keyboard::Home; - case VK_INSERT: return Keyboard::Insert; - case VK_DELETE: return Keyboard::Delete; - case VK_ADD: return Keyboard::Add; - case VK_SUBTRACT: return Keyboard::Subtract; - case VK_MULTIPLY: return Keyboard::Multiply; - case VK_DIVIDE: return Keyboard::Divide; - case VK_PAUSE: return Keyboard::Pause; - case VK_F1: return Keyboard::F1; - case VK_F2: return Keyboard::F2; - case VK_F3: return Keyboard::F3; - case VK_F4: return Keyboard::F4; - case VK_F5: return Keyboard::F5; - case VK_F6: return Keyboard::F6; - case VK_F7: return Keyboard::F7; - case VK_F8: return Keyboard::F8; - case VK_F9: return Keyboard::F9; - case VK_F10: return Keyboard::F10; - case VK_F11: return Keyboard::F11; - case VK_F12: return Keyboard::F12; - case VK_F13: return Keyboard::F13; - case VK_F14: return Keyboard::F14; - case VK_F15: return Keyboard::F15; - case VK_LEFT: return Keyboard::Left; - case VK_RIGHT: return Keyboard::Right; - case VK_UP: return Keyboard::Up; - case VK_DOWN: return Keyboard::Down; - case VK_NUMPAD0: return Keyboard::Numpad0; - case VK_NUMPAD1: return Keyboard::Numpad1; - case VK_NUMPAD2: return Keyboard::Numpad2; - case VK_NUMPAD3: return Keyboard::Numpad3; - case VK_NUMPAD4: return Keyboard::Numpad4; - case VK_NUMPAD5: return Keyboard::Numpad5; - case VK_NUMPAD6: return Keyboard::Numpad6; - case VK_NUMPAD7: return Keyboard::Numpad7; - case VK_NUMPAD8: return Keyboard::Numpad8; - case VK_NUMPAD9: return Keyboard::Numpad9; - case 'A': return Keyboard::A; - case 'Z': return Keyboard::Z; - case 'E': return Keyboard::E; - case 'R': return Keyboard::R; - case 'T': return Keyboard::T; - case 'Y': return Keyboard::Y; - case 'U': return Keyboard::U; - case 'I': return Keyboard::I; - case 'O': return Keyboard::O; - case 'P': return Keyboard::P; - case 'Q': return Keyboard::Q; - case 'S': return Keyboard::S; - case 'D': return Keyboard::D; - case 'F': return Keyboard::F; - case 'G': return Keyboard::G; - case 'H': return Keyboard::H; - case 'J': return Keyboard::J; - case 'K': return Keyboard::K; - case 'L': return Keyboard::L; - case 'M': return Keyboard::M; - case 'W': return Keyboard::W; - case 'X': return Keyboard::X; - case 'C': return Keyboard::C; - case 'V': return Keyboard::V; - case 'B': return Keyboard::B; - case 'N': return Keyboard::N; - case '0': return Keyboard::Num0; - case '1': return Keyboard::Num1; - case '2': return Keyboard::Num2; - case '3': return Keyboard::Num3; - case '4': return Keyboard::Num4; - case '5': return Keyboard::Num5; - case '6': return Keyboard::Num6; - case '7': return Keyboard::Num7; - case '8': return Keyboard::Num8; - case '9': return Keyboard::Num9; + case VK_LWIN: return Keyboard::Key::LSystem; + case VK_RWIN: return Keyboard::Key::RSystem; + case VK_APPS: return Keyboard::Key::Menu; + case VK_OEM_1: return Keyboard::Key::SemiColon; + case VK_OEM_2: return Keyboard::Key::Slash; + case VK_OEM_PLUS: return Keyboard::Key::Equal; + case VK_OEM_MINUS: return Keyboard::Key::Dash; + case VK_OEM_4: return Keyboard::Key::LBracket; + case VK_OEM_6: return Keyboard::Key::RBracket; + case VK_OEM_COMMA: return Keyboard::Key::Comma; + case VK_OEM_PERIOD: return Keyboard::Key::Period; + case VK_OEM_7: return Keyboard::Key::Quote; + case VK_OEM_5: return Keyboard::Key::BackSlash; + case VK_OEM_3: return Keyboard::Key::Tilde; + case VK_ESCAPE: return Keyboard::Key::Escape; + case VK_SPACE: return Keyboard::Key::Space; + case VK_RETURN: return Keyboard::Key::Return; + case VK_BACK: return Keyboard::Key::BackSpace; + case VK_TAB: return Keyboard::Key::Tab; + case VK_PRIOR: return Keyboard::Key::PageUp; + case VK_NEXT: return Keyboard::Key::PageDown; + case VK_END: return Keyboard::Key::End; + case VK_HOME: return Keyboard::Key::Home; + case VK_INSERT: return Keyboard::Key::Insert; + case VK_DELETE: return Keyboard::Key::Delete; + case VK_ADD: return Keyboard::Key::Add; + case VK_SUBTRACT: return Keyboard::Key::Subtract; + case VK_MULTIPLY: return Keyboard::Key::Multiply; + case VK_DIVIDE: return Keyboard::Key::Divide; + case VK_PAUSE: return Keyboard::Key::Pause; + case VK_F1: return Keyboard::Key::F1; + case VK_F2: return Keyboard::Key::F2; + case VK_F3: return Keyboard::Key::F3; + case VK_F4: return Keyboard::Key::F4; + case VK_F5: return Keyboard::Key::F5; + case VK_F6: return Keyboard::Key::F6; + case VK_F7: return Keyboard::Key::F7; + case VK_F8: return Keyboard::Key::F8; + case VK_F9: return Keyboard::Key::F9; + case VK_F10: return Keyboard::Key::F10; + case VK_F11: return Keyboard::Key::F11; + case VK_F12: return Keyboard::Key::F12; + case VK_F13: return Keyboard::Key::F13; + case VK_F14: return Keyboard::Key::F14; + case VK_F15: return Keyboard::Key::F15; + case VK_LEFT: return Keyboard::Key::Left; + case VK_RIGHT: return Keyboard::Key::Right; + case VK_UP: return Keyboard::Key::Up; + case VK_DOWN: return Keyboard::Key::Down; + case VK_NUMPAD0: return Keyboard::Key::Numpad0; + case VK_NUMPAD1: return Keyboard::Key::Numpad1; + case VK_NUMPAD2: return Keyboard::Key::Numpad2; + case VK_NUMPAD3: return Keyboard::Key::Numpad3; + case VK_NUMPAD4: return Keyboard::Key::Numpad4; + case VK_NUMPAD5: return Keyboard::Key::Numpad5; + case VK_NUMPAD6: return Keyboard::Key::Numpad6; + case VK_NUMPAD7: return Keyboard::Key::Numpad7; + case VK_NUMPAD8: return Keyboard::Key::Numpad8; + case VK_NUMPAD9: return Keyboard::Key::Numpad9; + case 'A': return Keyboard::Key::A; + case 'Z': return Keyboard::Key::Z; + case 'E': return Keyboard::Key::E; + case 'R': return Keyboard::Key::R; + case 'T': return Keyboard::Key::T; + case 'Y': return Keyboard::Key::Y; + case 'U': return Keyboard::Key::U; + case 'I': return Keyboard::Key::I; + case 'O': return Keyboard::Key::O; + case 'P': return Keyboard::Key::P; + case 'Q': return Keyboard::Key::Q; + case 'S': return Keyboard::Key::S; + case 'D': return Keyboard::Key::D; + case 'F': return Keyboard::Key::F; + case 'G': return Keyboard::Key::G; + case 'H': return Keyboard::Key::H; + case 'J': return Keyboard::Key::J; + case 'K': return Keyboard::Key::K; + case 'L': return Keyboard::Key::L; + case 'M': return Keyboard::Key::M; + case 'W': return Keyboard::Key::W; + case 'X': return Keyboard::Key::X; + case 'C': return Keyboard::Key::C; + case 'V': return Keyboard::Key::V; + case 'B': return Keyboard::Key::B; + case 'N': return Keyboard::Key::N; + case '0': return Keyboard::Key::Num0; + case '1': return Keyboard::Key::Num1; + case '2': return Keyboard::Key::Num2; + case '3': return Keyboard::Key::Num3; + case '4': return Keyboard::Key::Num4; + case '5': return Keyboard::Key::Num5; + case '6': return Keyboard::Key::Num6; + case '7': return Keyboard::Key::Num7; + case '8': return Keyboard::Key::Num8; + case '9': return Keyboard::Key::Num9; } - return Keyboard::Unknown; + return Keyboard::Key::Unknown; } diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 2e1481b0..7f6f1fba 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -393,7 +393,7 @@ void Window::onResize() bool Window::filterEvent(const Event& event) { // Notify resize events to the derived class - if (event.type == Event::Resized) + if (event.type == Event::Type::Resized) { // Cache the new size m_size.x = event.size.width; diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 4df62b69..f8c75acf 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -89,8 +89,8 @@ m_joystickThreshold(0.1f) m_joystickStates[i] = JoystickManager::getInstance().getState(i); // Get the initial sensor states - for (unsigned int i = 0; i < Sensor::Count; ++i) - m_sensorValue[i] = Vector3f(0, 0, 0); + for (auto& sensorValue : m_sensorValue) + sensorValue = Vector3f(0, 0, 0); } @@ -173,7 +173,7 @@ void WindowImpl::processJoystickEvents() if (previousState.connected ^ connected) { Event event; - event.type = connected ? Event::JoystickConnected : Event::JoystickDisconnected; + event.type = connected ? Event::Type::JoystickConnected : Event::Type::JoystickDisconnected; event.joystickButton.joystickId = i; pushEvent(event); } @@ -181,19 +181,18 @@ void WindowImpl::processJoystickEvents() if (connected) { // Axes - for (unsigned int j = 0; j < Joystick::AxisCount; ++j) + for (auto j = 0u; j < static_cast(Joystick::Axis::Count); ++j) { if (caps.axes[j]) { - Joystick::Axis axis = static_cast(j); - float prevPos = previousState.axes[axis]; - float currPos = m_joystickStates[i].axes[axis]; + float prevPos = previousState.axes[j]; + float currPos = m_joystickStates[i].axes[j]; if (fabs(currPos - prevPos) >= m_joystickThreshold) { Event event; - event.type = Event::JoystickMoved; + event.type = Event::Type::JoystickMoved; event.joystickMove.joystickId = i; - event.joystickMove.axis = axis; + event.joystickMove.axis = static_cast(j); event.joystickMove.position = currPos; pushEvent(event); } @@ -209,7 +208,7 @@ void WindowImpl::processJoystickEvents() if (prevPressed ^ currPressed) { Event event; - event.type = currPressed ? Event::JoystickButtonPressed : Event::JoystickButtonReleased; + event.type = currPressed ? Event::Type::JoystickButtonPressed : Event::Type::JoystickButtonReleased; event.joystickButton.joystickId = i; event.joystickButton.button = j; pushEvent(event); @@ -226,7 +225,7 @@ void WindowImpl::processSensorEvents() // First update the sensor states SensorManager::getInstance().update(); - for (unsigned int i = 0; i < Sensor::Count; ++i) + for (auto i = 0u; i < static_cast(Sensor::Type::Count); ++i) { Sensor::Type sensor = static_cast(i); @@ -241,7 +240,7 @@ void WindowImpl::processSensorEvents() if (m_sensorValue[i] != previousValue) // @todo use a threshold? { Event event; - event.type = Event::SensorChanged; + event.type = Event::Type::SensorChanged; event.sensor.type = sensor; event.sensor.x = m_sensorValue[i].x; event.sensor.y = m_sensorValue[i].y; diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 919e78d3..a0d5967e 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -262,10 +262,10 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - std::queue m_events; ///< Queue of available events - JoystickState m_joystickStates[Joystick::Count]; ///< Previous state of the joysticks - Vector3f m_sensorValue[Sensor::Count]; ///< Previous value of the sensors - float m_joystickThreshold; ///< Joystick threshold (minimum motion for "move" event to be generated) + std::queue m_events; ///< Queue of available events + JoystickState m_joystickStates[Joystick::Count]; ///< Previous state of the joysticks + Vector3f m_sensorValue[static_cast(Sensor::Type::Count)]; ///< Previous value of the sensors + float m_joystickThreshold; ///< Joystick threshold (minimum motion for "move" event to be generated) }; } // namespace priv diff --git a/src/SFML/Window/iOS/SensorImpl.mm b/src/SFML/Window/iOS/SensorImpl.mm index 02f8e1ff..4f0d518b 100644 --- a/src/SFML/Window/iOS/SensorImpl.mm +++ b/src/SFML/Window/iOS/SensorImpl.mm @@ -63,18 +63,18 @@ bool SensorImpl::isAvailable(Sensor::Type sensor) { switch (sensor) { - case Sensor::Accelerometer: + case Sensor::Type::Accelerometer: return [SFAppDelegate getInstance].motionManager.accelerometerAvailable; - case Sensor::Gyroscope: + case Sensor::Type::Gyroscope: return [SFAppDelegate getInstance].motionManager.gyroAvailable; - case Sensor::Magnetometer: + case Sensor::Type::Magnetometer: return [SFAppDelegate getInstance].motionManager.magnetometerAvailable; - case Sensor::Gravity: - case Sensor::UserAcceleration: - case Sensor::Orientation: + case Sensor::Type::Gravity: + case Sensor::Type::UserAcceleration: + case Sensor::Type::Orientation: return [SFAppDelegate getInstance].motionManager.deviceMotionAvailable; default: @@ -96,21 +96,21 @@ bool SensorImpl::open(Sensor::Type sensor) static const NSTimeInterval updateInterval = 1. / 60.; switch (sensor) { - case Sensor::Accelerometer: + case Sensor::Type::Accelerometer: [SFAppDelegate getInstance].motionManager.accelerometerUpdateInterval = updateInterval; break; - case Sensor::Gyroscope: + case Sensor::Type::Gyroscope: [SFAppDelegate getInstance].motionManager.gyroUpdateInterval = updateInterval; break; - case Sensor::Magnetometer: + case Sensor::Type::Magnetometer: [SFAppDelegate getInstance].motionManager.magnetometerUpdateInterval = updateInterval; break; - case Sensor::Gravity: - case Sensor::UserAcceleration: - case Sensor::Orientation: + case Sensor::Type::Gravity: + case Sensor::Type::UserAcceleration: + case Sensor::Type::Orientation: [SFAppDelegate getInstance].motionManager.deviceMotionUpdateInterval = updateInterval; break; @@ -137,35 +137,35 @@ Vector3f SensorImpl::update() switch (m_sensor) { - case Sensor::Accelerometer: + case Sensor::Type::Accelerometer: // Acceleration is given in G, convert to m/s^2 value.x = manager.accelerometerData.acceleration.x * 9.81f; value.y = manager.accelerometerData.acceleration.y * 9.81f; value.z = manager.accelerometerData.acceleration.z * 9.81f; break; - case Sensor::Gyroscope: + case Sensor::Type::Gyroscope: // Rotation rates are given in rad/s, convert to deg/s value.x = toDegrees(manager.gyroData.rotationRate.x); value.y = toDegrees(manager.gyroData.rotationRate.y); value.z = toDegrees(manager.gyroData.rotationRate.z); break; - case Sensor::Magnetometer: + case Sensor::Type::Magnetometer: // Magnetic field is given in microteslas value.x = manager.magnetometerData.magneticField.x; value.y = manager.magnetometerData.magneticField.y; value.z = manager.magnetometerData.magneticField.z; break; - case Sensor::UserAcceleration: + case Sensor::Type::UserAcceleration: // User acceleration is given in G, convert to m/s^2 value.x = manager.deviceMotion.userAcceleration.x * 9.81f; value.y = manager.deviceMotion.userAcceleration.y * 9.81f; value.z = manager.deviceMotion.userAcceleration.z * 9.81f; break; - case Sensor::Orientation: + case Sensor::Type::Orientation: // Absolute rotation (Euler) angles are given in radians, convert to degrees value.x = toDegrees(manager.deviceMotion.attitude.yaw); value.y = toDegrees(manager.deviceMotion.attitude.pitch); @@ -189,30 +189,30 @@ void SensorImpl::setEnabled(bool enabled) switch (m_sensor) { - case Sensor::Accelerometer: + case Sensor::Type::Accelerometer: if (enabled) [[SFAppDelegate getInstance].motionManager startAccelerometerUpdates]; else [[SFAppDelegate getInstance].motionManager stopAccelerometerUpdates]; break; - case Sensor::Gyroscope: + case Sensor::Type::Gyroscope: if (enabled) [[SFAppDelegate getInstance].motionManager startGyroUpdates]; else [[SFAppDelegate getInstance].motionManager stopGyroUpdates]; break; - case Sensor::Magnetometer: + case Sensor::Type::Magnetometer: if (enabled) [[SFAppDelegate getInstance].motionManager startMagnetometerUpdates]; else [[SFAppDelegate getInstance].motionManager stopMagnetometerUpdates]; break; - case Sensor::Gravity: - case Sensor::UserAcceleration: - case Sensor::Orientation: + case Sensor::Type::Gravity: + case Sensor::Type::UserAcceleration: + case Sensor::Type::Orientation: // these 3 sensors all share the same implementation, so we must disable // it only if the three sensors are disabled if (enabled) diff --git a/src/SFML/Window/iOS/WindowImplUIKit.mm b/src/SFML/Window/iOS/WindowImplUIKit.mm index 49791ce3..6808c1cf 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.mm +++ b/src/SFML/Window/iOS/WindowImplUIKit.mm @@ -214,9 +214,9 @@ bool WindowImplUIKit::hasFocus() const //////////////////////////////////////////////////////////// void WindowImplUIKit::forwardEvent(Event event) { - if (event.type == Event::GainedFocus) + if (event.type == Event::Type::GainedFocus) m_hasFocus = true; - else if (event.type == Event::LostFocus) + else if (event.type == Event::Type::LostFocus) m_hasFocus = false; pushEvent(event); From 7800cbb9f66eb8e1f4d35c8099325243cc76633c Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Wed, 5 Apr 2017 21:56:06 +0200 Subject: [PATCH 15/18] Add requirement for macOS: 10.9+ --- CMakeLists.txt | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ce5bf50..c7432b34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,25 @@ if(SFML_OS_MACOSX) # add an option to automatically install Xcode templates sfml_set_option(SFML_INSTALL_XCODE_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode templates, FALSE to do nothing about it. The templates are compatible with Xcode 4 and 5.") + + # add some default value for some additional macOS variable + if(NOT CMAKE_OSX_ARCHITECTURES) + set(CMAKE_OSX_ARCHITECTURES "x86_64") + endif() + if(NOT CMAKE_OSX_DEPLOYMENT_TARGET) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9") + endif() + if(NOT CMAKE_OSX_SYSROOT) + # query the path to the default SDK + execute_process(COMMAND xcodebuild -sdk macosx -version Path | head -n 1 + RESULT_VARIABLE STATUS_QUERY + OUTPUT_VARIABLE CMAKE_OSX_SYSROOT + ERROR_QUIET) + + if(NOT STATUS_QUERY EQUAL 0) + message(FATAL_ERROR "Querying the default SDK failed with status ${STATUS_QUERY}.") + endif() + endif() endif() # Android options @@ -232,11 +251,17 @@ if(SFML_OS_MACOSX) endif() # only the default architecture (i.e. 64-bit) is supported - if(CMAKE_OSX_ARCHITECTURES AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64") + if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64") message(FATAL_ERROR "Only 64-bit architecture is supported") return() endif() - + + # Ensure macOS 10.9+ is used + if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "10.9") + message(FATAL_ERROR "macOS 10.9 or greater is required for the deployment target.") + return() + endif() + # configure Xcode templates set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)") endif() From 41348bc18003dffaf61e0d265b8973a4e7eb6295 Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Wed, 5 Apr 2017 23:01:06 +0200 Subject: [PATCH 16/18] Fix macOS build setup The CMAKE_OSX_* variables need to be defined before the project or the CMAKE_CXX_STANDARD gets ignored. They also need to be set with FORCE. --- CMakeLists.txt | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7432b34..98072c82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.1.0) # set the minimum required C++ standard to C++14 set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) # define a macro that helps defining an option macro(sfml_set_option var default type docstring) @@ -22,6 +23,23 @@ set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Suppress Mac OS X RPATH warnings and adopt new related behaviors cmake_policy(SET CMP0042 NEW) +# add some default value for some additional macOS variable +# note that those variables are ignored on other systems +if(NOT CMAKE_OSX_ARCHITECTURES) + set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "macOS architecture to build; 64-bit is expected" FORCE) +endif() +if(NOT CMAKE_OSX_DEPLOYMENT_TARGET) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "macOS deployement target; 10.9+ is expected" FORCE) +endif() +if(NOT CMAKE_OSX_SYSROOT) + # query the path to the default SDK, will fail on non-macOS, but it's okay. + execute_process(COMMAND xcodebuild -sdk macosx -version Path + COMMAND head -n 1 + COMMAND tr -d '\n' + OUTPUT_VARIABLE CMAKE_OSX_SYSROOT + ERROR_QUIET) +endif() + # set Android specific options # define the minimum API level to be used @@ -90,25 +108,6 @@ if(SFML_OS_MACOSX) # add an option to automatically install Xcode templates sfml_set_option(SFML_INSTALL_XCODE_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode templates, FALSE to do nothing about it. The templates are compatible with Xcode 4 and 5.") - - # add some default value for some additional macOS variable - if(NOT CMAKE_OSX_ARCHITECTURES) - set(CMAKE_OSX_ARCHITECTURES "x86_64") - endif() - if(NOT CMAKE_OSX_DEPLOYMENT_TARGET) - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9") - endif() - if(NOT CMAKE_OSX_SYSROOT) - # query the path to the default SDK - execute_process(COMMAND xcodebuild -sdk macosx -version Path | head -n 1 - RESULT_VARIABLE STATUS_QUERY - OUTPUT_VARIABLE CMAKE_OSX_SYSROOT - ERROR_QUIET) - - if(NOT STATUS_QUERY EQUAL 0) - message(FATAL_ERROR "Querying the default SDK failed with status ${STATUS_QUERY}.") - endif() - endif() endif() # Android options @@ -253,13 +252,11 @@ if(SFML_OS_MACOSX) # only the default architecture (i.e. 64-bit) is supported if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64") message(FATAL_ERROR "Only 64-bit architecture is supported") - return() endif() # Ensure macOS 10.9+ is used if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "10.9") message(FATAL_ERROR "macOS 10.9 or greater is required for the deployment target.") - return() endif() # configure Xcode templates From f591f0bf5c8f3a23e217cb8caf716fb1318174a5 Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Wed, 5 Apr 2017 23:30:01 +0200 Subject: [PATCH 17/18] Update Xcode templates Fixes for: - C++14 settings - Strongly typed enum --- .../SFML/SFML App.xctemplate/main.cpp | 4 +- .../SFML/SFML CLT.xctemplate/main.cpp | 4 +- .../TemplateInfo.plist.in | 80 +++---------------- 3 files changed, 15 insertions(+), 73 deletions(-) diff --git a/tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp b/tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp index 58ac6660..ca464a8d 100644 --- a/tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp +++ b/tools/xcode/templates/SFML/SFML App.xctemplate/main.cpp @@ -64,12 +64,12 @@ int main(int, char const**) while (window.pollEvent(event)) { // Close window: exit - if (event.type == sf::Event::Closed) { + if (event.type == sf::Event::Type::Closed) { window.close(); } // Escape pressed: exit - if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { + if (event.type == sf::Event::Type::KeyPressed && event.key.code == sf::Keyboard::Key::Escape) { window.close(); } } diff --git a/tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp b/tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp index 106f6e2b..e10f2aa0 100644 --- a/tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp +++ b/tools/xcode/templates/SFML/SFML CLT.xctemplate/main.cpp @@ -62,12 +62,12 @@ int main(int argc, char const** argv) while (window.pollEvent(event)) { // Close window: exit - if (event.type == sf::Event::Closed) { + if (event.type == sf::Event::Type::Closed) { window.close(); } // Escape pressed: exit - if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { + if (event.type == sf::Event::Type::KeyPressed && event.key.code == sf::Keyboard::Key::Escape) { window.close(); } } diff --git a/tools/xcode/templates/SFML/SFML Compiler.xctemplate/TemplateInfo.plist.in b/tools/xcode/templates/SFML/SFML Compiler.xctemplate/TemplateInfo.plist.in index 11551bdf..d390dab6 100644 --- a/tools/xcode/templates/SFML/SFML Compiler.xctemplate/TemplateInfo.plist.in +++ b/tools/xcode/templates/SFML/SFML Compiler.xctemplate/TemplateInfo.plist.in @@ -25,7 +25,7 @@ subject to the following restrictions: --> - Options - - - Identifier - compilerSettingsType - - Name - [ADVANCED] C++ Compiler and Standard Library - - Description - If you don't know what is it about, use the default value. Note that you'll need a version of SFML compiled with Clang and libc++ to use C++11! - - Default - C++11 with Clang and libc++ - - NotPersisted - - - Type - popup - - Units - - - C++98 with Clang and libstdc++ - - Project - - SharedSettings - - GCC_VERSION - com.apple.compilers.llvm.clang.1_0 - - CLANG_CXX_LANGUAGE_STANDARD - c++98 - - CLANG_CXX_LIBRARY - libstdc++ - - - - - - C++11 with Clang and libc++ - - Project - - SharedSettings - - GCC_VERSION - com.apple.compilers.llvm.clang.1_0 - - CLANG_CXX_LANGUAGE_STANDARD - c++0x - - CLANG_CXX_LIBRARY - libc++ - - - - - - - - @@ -140,6 +72,16 @@ subject to the following restrictions: LIBRARY_SEARCH_PATHS /usr/local/lib/ $(inherited) + + + GCC_VERSION + com.apple.compilers.llvm.clang.1_0 + + CLANG_CXX_LANGUAGE_STANDARD + gnu++14 + + CLANG_CXX_LIBRARY + libc++ Configurations From 842f9be3858fa20ce3c70c719eac7a6d332a4666 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sat, 8 Apr 2017 13:17:02 +0200 Subject: [PATCH 18/18] Adjust sf::NonCopyable to make use of = default and = delete thus also making it move-enabled. --- include/SFML/System/NonCopyable.hpp | 78 ++++++++++++++++++----------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/include/SFML/System/NonCopyable.hpp b/include/SFML/System/NonCopyable.hpp index 71476388..d7eba33a 100644 --- a/include/SFML/System/NonCopyable.hpp +++ b/include/SFML/System/NonCopyable.hpp @@ -47,10 +47,10 @@ protected: /// /// Because this class has a copy constructor, the compiler /// will not automatically generate the default constructor. - /// That's why we must define it explicitly. + /// That's why we must mark it as defaulted explicitly. /// //////////////////////////////////////////////////////////// - NonCopyable() {} + NonCopyable() = default; //////////////////////////////////////////////////////////// /// \brief Default destructor @@ -60,33 +60,49 @@ protected: /// preventing possible resource leaks. /// //////////////////////////////////////////////////////////// - ~NonCopyable() {} - -private: + ~NonCopyable() = default; //////////////////////////////////////////////////////////// /// \brief Disabled copy constructor /// - /// By making the copy constructor private, the compiler will - /// trigger an error if anyone outside tries to use it. - /// To prevent NonCopyable or friend classes from using it, - /// we also give no definition, so that the linker will - /// produce an error if the first protection was inefficient. + /// By marking the copy constructor as deleted, the compiler + /// will trigger an error if anyone outside tries to use it. /// //////////////////////////////////////////////////////////// - NonCopyable(const NonCopyable&); + NonCopyable(const NonCopyable&) = delete; //////////////////////////////////////////////////////////// - /// \brief Disabled assignment operator + /// \brief Disabled copy assignment operator /// - /// By making the assignment operator private, the compiler will - /// trigger an error if anyone outside tries to use it. - /// To prevent NonCopyable or friend classes from using it, - /// we also give no definition, so that the linker will - /// produce an error if the first protection was inefficient. + /// By marking the copy assignment operator as deleted, the + /// compiler will trigger an error if anyone outside tries + /// to use it. /// //////////////////////////////////////////////////////////// - NonCopyable& operator =(const NonCopyable&); + NonCopyable& operator =(const NonCopyable&) = delete; + + //////////////////////////////////////////////////////////// + /// \brief Default move constructor + /// + /// Because this class has all other special member + /// functions user-defined, the compiler will not + /// automatically generate the default move constructor. + /// That's why we must mark it as defaulted explicitly. + /// + //////////////////////////////////////////////////////////// + NonCopyable(NonCopyable&&) = default; + + //////////////////////////////////////////////////////////// + /// \brief Default move assignment operator + /// + /// Because this class has all other special member + /// functions user-defined, the compiler will not + /// automatically generate the default move assignment + /// operator. That's why we must mark it as defaulted + /// explicitly. + /// + //////////////////////////////////////////////////////////// + NonCopyable& operator =(NonCopyable&&) = default; }; } // namespace sf @@ -99,17 +115,18 @@ private: /// \class sf::NonCopyable /// \ingroup system /// -/// This class makes its instances non-copyable, by explicitly -/// disabling its copy constructor and its assignment operator. +/// This class makes its instances non-copyable, by +/// explicitly deleting its copy constructor and its +/// assignment operator. /// /// To create a non-copyable class, simply inherit from /// sf::NonCopyable. /// -/// The type of inheritance (public or private) doesn't matter, -/// the copy constructor and assignment operator are declared private -/// in sf::NonCopyable so they will end up being inaccessible in both -/// cases. Thus you can use a shorter syntax for inheriting from it -/// (see below). +/// The type of inheritance (public or private) doesn't +/// matter, the copy constructor and assignment operator +/// are deleted in sf::NonCopyable so they will end up being +/// inaccessible in both cases. Thus you can use a shorter +/// syntax for inheriting from it (see below). /// /// Usage example: /// \code @@ -120,10 +137,11 @@ private: /// \endcode /// /// Deciding whether the instances of a class can be copied -/// or not is a very important design choice. You are strongly -/// encouraged to think about it before writing a class, -/// and to use sf::NonCopyable when necessary to prevent -/// many potential future errors when using it. This is also -/// a very important indication to users of your class. +/// or not is a very important design choice. You are +/// strongly encouraged to think about it before writing a +/// class, and to use sf::NonCopyable when necessary to +/// prevent many potential future errors when using it. This +/// is alsoa very important indication to users of your +/// class. /// ////////////////////////////////////////////////////////////