Replaced function-local static variables with C++11 constructs.
This commit is contained in:
parent
2ef0d36569
commit
d6dcafbc90
|
@ -35,6 +35,7 @@
|
|||
#include <SFML/System/FileInputStream.hpp>
|
||||
#include <SFML/System/MemoryInputStream.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
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::priv::SoundFileReaderFlac>();
|
||||
sf::SoundFileFactory::registerWriter<sf::priv::SoundFileWriterFlac>();
|
||||
|
@ -51,8 +52,7 @@ namespace
|
|||
sf::SoundFileFactory::registerWriter<sf::priv::SoundFileWriterOgg>();
|
||||
sf::SoundFileFactory::registerReader<sf::priv::SoundFileReaderWav>();
|
||||
sf::SoundFileFactory::registerWriter<sf::priv::SoundFileWriterWav>();
|
||||
registered = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<int>(count / m_channelCount);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <SFML/Graphics/GLExtensions.hpp>
|
||||
#include <SFML/Window/Context.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <mutex>
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <SFML/System/Err.hpp>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <SFML/System/Err.hpp>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -30,25 +30,6 @@
|
|||
#include <SFML/System/Lock.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
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<DWORD>(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<DWORD>(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);
|
||||
|
||||
|
|
|
@ -64,14 +64,13 @@ VideoMode VideoMode::getDesktopMode()
|
|||
////////////////////////////////////////////////////////////
|
||||
const std::vector<VideoMode>& VideoMode::getFullscreenModes()
|
||||
{
|
||||
static std::vector<VideoMode> 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<VideoMode>());
|
||||
}
|
||||
return modes;
|
||||
}();
|
||||
|
||||
return modes;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <SFML/System/Err.hpp>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
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<GlFunctionPointer>(GetProcAddress(module, reinterpret_cast<LPCSTR>(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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<UINT>((flags & (0xFF << 16)) >> 16);
|
||||
return scancode == lShift ? Keyboard::LShift : Keyboard::RShift;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue