Turn more compile-time constants into 'constexpr' variables
This commit is contained in:
parent
9d51a6bd50
commit
5b500ad2c2
@ -155,7 +155,6 @@ constexpr Color& operator *=(Color& left, const Color& right)
|
||||
|
||||
// Note: the 'inline' keyword here is technically not required, but VS2019 fails
|
||||
// to compile with a bogus "multiple definition" error if not explicitly used.
|
||||
|
||||
inline constexpr Color Color::Black(0, 0, 0);
|
||||
inline constexpr Color Color::White(255, 255, 255);
|
||||
inline constexpr Color Color::Red(255, 0, 0);
|
||||
|
@ -218,5 +218,4 @@ constexpr bool operator !=(const Transform& left, const Transform& right)
|
||||
|
||||
// Note: the 'inline' keyword here is technically not required, but VS2019 fails
|
||||
// to compile with a bogus "multiple definition" error if not explicitly used.
|
||||
|
||||
inline constexpr Transform Transform::Identity;
|
||||
|
@ -139,7 +139,7 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API static const Angle Zero; //!< Predefined 0 degree angle value
|
||||
static const Angle Zero; //!< Predefined 0 degree angle value
|
||||
|
||||
private:
|
||||
|
||||
|
@ -257,3 +257,12 @@ constexpr Angle operator "" _rad(unsigned long long angle)
|
||||
}
|
||||
|
||||
} // namespace Literals
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// Note: the 'inline' keyword here is technically not required, but VS2019 fails
|
||||
// to compile with a bogus "multiple definition" error if not explicitly used.
|
||||
inline constexpr Angle Angle::Zero;
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API static const Time Zero; //!< Predefined "zero" time value
|
||||
static const Time Zero; //!< Predefined "zero" time value
|
||||
|
||||
private:
|
||||
|
||||
|
@ -245,3 +245,12 @@ constexpr Time& operator %=(Time& left, Time right)
|
||||
{
|
||||
return left = left % right;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// Note: the 'inline' keyword here is technically not required, but VS2019 fails
|
||||
// to compile with a bogus "multiple definition" error if not explicitly used.
|
||||
inline constexpr Time Time::Zero;
|
||||
|
@ -48,7 +48,7 @@ template <typename In>
|
||||
In Utf<8>::decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||
{
|
||||
// Some useful precomputed data
|
||||
static const int trailing[256] =
|
||||
static constexpr int trailing[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@ -59,7 +59,7 @@ In Utf<8>::decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
|
||||
};
|
||||
static const Uint32 offsets[6] =
|
||||
static constexpr Uint32 offsets[6] =
|
||||
{
|
||||
0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080
|
||||
};
|
||||
@ -96,7 +96,7 @@ template <typename Out>
|
||||
Out Utf<8>::encode(Uint32 input, Out output, Uint8 replacement)
|
||||
{
|
||||
// Some useful precomputed data
|
||||
static const Uint8 firstBytes[7] =
|
||||
static constexpr Uint8 firstBytes[7] =
|
||||
{
|
||||
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
|
||||
};
|
||||
|
@ -59,7 +59,7 @@ struct ContextSettings
|
||||
/// \param sRgb sRGB capable framebuffer
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit ContextSettings(unsigned int depth = 0, unsigned int stencil = 0, unsigned int antialiasing = 0, unsigned int major = 1, unsigned int minor = 1, unsigned int attributes = Default, bool sRgb = false) :
|
||||
constexpr explicit ContextSettings(unsigned int depth = 0, unsigned int stencil = 0, unsigned int antialiasing = 0, unsigned int major = 1, unsigned int minor = 1, unsigned int attributes = Default, bool sRgb = false) :
|
||||
depthBits (depth),
|
||||
stencilBits (stencil),
|
||||
antialiasingLevel(antialiasing),
|
||||
|
@ -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 int bufferSize = 65536;
|
||||
|
||||
// A frame contains a sample from each channel
|
||||
int frameCount = static_cast<int>(count / m_channelCount);
|
||||
|
@ -733,7 +733,7 @@ void RenderTarget::setupDraw(bool useVertexCache, const RenderStates& states)
|
||||
void RenderTarget::drawPrimitives(PrimitiveType type, std::size_t firstVertex, std::size_t vertexCount)
|
||||
{
|
||||
// Find the OpenGL primitive type
|
||||
static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES,
|
||||
static constexpr GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES,
|
||||
GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN};
|
||||
GLenum mode = modes[type];
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2022 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 <SFML/System/Angle.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
const Angle Angle::Zero;
|
||||
|
||||
} // namespace sf
|
@ -4,8 +4,8 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/src/SFML/System)
|
||||
|
||||
# all source files
|
||||
set(SRC
|
||||
${SRCROOT}/Angle.cpp
|
||||
${INCROOT}/Angle.hpp
|
||||
${INCROOT}/Angle.inl
|
||||
${SRCROOT}/Clock.cpp
|
||||
${INCROOT}/Clock.hpp
|
||||
${SRCROOT}/Err.cpp
|
||||
@ -18,7 +18,6 @@ set(SRC
|
||||
${SRCROOT}/String.cpp
|
||||
${INCROOT}/String.hpp
|
||||
${INCROOT}/String.inl
|
||||
${SRCROOT}/Time.cpp
|
||||
${INCROOT}/Time.hpp
|
||||
${INCROOT}/Time.inl
|
||||
${INCROOT}/Utf.hpp
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
DefaultErrStreamBuf()
|
||||
{
|
||||
// Allocate the write buffer
|
||||
static const int size = 64;
|
||||
constexpr int size = 64;
|
||||
char* buffer = new char[size];
|
||||
setp(buffer, buffer + size);
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2022 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 <SFML/System/Time.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
const Time Time::Zero;
|
||||
|
||||
} // namespace sf
|
@ -384,7 +384,7 @@ Joystick::Identification JoystickImpl::getIdentification() const
|
||||
JoystickState JoystickImpl::update()
|
||||
{
|
||||
AutoreleasePool pool;
|
||||
static const JoystickState disconnectedState; // return this if joystick was disconnected
|
||||
static constexpr JoystickState disconnectedState; // return this if joystick was disconnected
|
||||
JoystickState state; // otherwise return that
|
||||
state.connected = true;
|
||||
|
||||
|
@ -78,14 +78,14 @@ namespace
|
||||
|
||||
sf::String wmAbsPosGood[] = { "Enlightenment", "FVWM", "i3" };
|
||||
|
||||
static const unsigned long eventMask = FocusChangeMask | ButtonPressMask |
|
||||
constexpr unsigned long eventMask = FocusChangeMask | ButtonPressMask |
|
||||
ButtonReleaseMask | ButtonMotionMask |
|
||||
PointerMotionMask | KeyPressMask |
|
||||
KeyReleaseMask | StructureNotifyMask |
|
||||
EnterWindowMask | LeaveWindowMask |
|
||||
VisibilityChangeMask | PropertyChangeMask;
|
||||
|
||||
static const unsigned int maxTrialsCount = 5;
|
||||
constexpr unsigned int maxTrialsCount = 5;
|
||||
|
||||
// Predicate we use to find key repeat events in processEvent
|
||||
struct KeyRepeatFinder
|
||||
@ -656,23 +656,23 @@ m_lastInputTime (0)
|
||||
Atom WMHintsAtom = getAtom("_MOTIF_WM_HINTS", false);
|
||||
if (WMHintsAtom)
|
||||
{
|
||||
static const unsigned long MWM_HINTS_FUNCTIONS = 1 << 0;
|
||||
static const unsigned long MWM_HINTS_DECORATIONS = 1 << 1;
|
||||
constexpr unsigned long MWM_HINTS_FUNCTIONS = 1 << 0;
|
||||
constexpr unsigned long MWM_HINTS_DECORATIONS = 1 << 1;
|
||||
|
||||
//static const unsigned long MWM_DECOR_ALL = 1 << 0;
|
||||
static const unsigned long MWM_DECOR_BORDER = 1 << 1;
|
||||
static const unsigned long MWM_DECOR_RESIZEH = 1 << 2;
|
||||
static const unsigned long MWM_DECOR_TITLE = 1 << 3;
|
||||
static const unsigned long MWM_DECOR_MENU = 1 << 4;
|
||||
static const unsigned long MWM_DECOR_MINIMIZE = 1 << 5;
|
||||
static const unsigned long MWM_DECOR_MAXIMIZE = 1 << 6;
|
||||
//constexpr unsigned long MWM_DECOR_ALL = 1 << 0;
|
||||
constexpr unsigned long MWM_DECOR_BORDER = 1 << 1;
|
||||
constexpr unsigned long MWM_DECOR_RESIZEH = 1 << 2;
|
||||
constexpr unsigned long MWM_DECOR_TITLE = 1 << 3;
|
||||
constexpr unsigned long MWM_DECOR_MENU = 1 << 4;
|
||||
constexpr unsigned long MWM_DECOR_MINIMIZE = 1 << 5;
|
||||
constexpr unsigned long MWM_DECOR_MAXIMIZE = 1 << 6;
|
||||
|
||||
//static const unsigned long MWM_FUNC_ALL = 1 << 0;
|
||||
static const unsigned long MWM_FUNC_RESIZE = 1 << 1;
|
||||
static const unsigned long MWM_FUNC_MOVE = 1 << 2;
|
||||
static const unsigned long MWM_FUNC_MINIMIZE = 1 << 3;
|
||||
static const unsigned long MWM_FUNC_MAXIMIZE = 1 << 4;
|
||||
static const unsigned long MWM_FUNC_CLOSE = 1 << 5;
|
||||
//constexpr unsigned long MWM_FUNC_ALL = 1 << 0;
|
||||
constexpr unsigned long MWM_FUNC_RESIZE = 1 << 1;
|
||||
constexpr unsigned long MWM_FUNC_MOVE = 1 << 2;
|
||||
constexpr unsigned long MWM_FUNC_MINIMIZE = 1 << 3;
|
||||
constexpr unsigned long MWM_FUNC_MAXIMIZE = 1 << 4;
|
||||
constexpr unsigned long MWM_FUNC_CLOSE = 1 << 5;
|
||||
|
||||
struct WMHints
|
||||
{
|
||||
@ -1495,7 +1495,7 @@ void WindowImplX11::switchToFullscreen()
|
||||
|
||||
if (netWmBypassCompositor)
|
||||
{
|
||||
static const unsigned long bypassCompositor = 1;
|
||||
constexpr unsigned long bypassCompositor = 1;
|
||||
|
||||
XChangeProperty(m_display,
|
||||
m_window,
|
||||
|
@ -164,7 +164,7 @@ void Window::close()
|
||||
////////////////////////////////////////////////////////////
|
||||
const ContextSettings& Window::getSettings() const
|
||||
{
|
||||
static const ContextSettings empty(0, 0, 0);
|
||||
static constexpr ContextSettings empty(0, 0, 0);
|
||||
|
||||
return m_context ? m_context->getSettings() : empty;
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ void EaglContext::display()
|
||||
// therefore we fake it with a manual framerate limit
|
||||
if (m_vsyncEnabled)
|
||||
{
|
||||
static const Time frameDuration = seconds(1.f / 60.f);
|
||||
constexpr Time frameDuration = seconds(1.f / 60.f);
|
||||
sleep(frameDuration - m_clock.getElapsedTime());
|
||||
m_clock.restart();
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ bool SensorImpl::open(Sensor::Type sensor)
|
||||
m_enabled = false;
|
||||
|
||||
// Set the refresh rate (use the maximum allowed)
|
||||
static const NSTimeInterval updateInterval = 1. / 60.;
|
||||
constexpr NSTimeInterval updateInterval = 1. / 60.;
|
||||
switch (sensor)
|
||||
{
|
||||
case Sensor::Accelerometer:
|
||||
|
Loading…
Reference in New Issue
Block a user