mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Improve const correctness
This commit is contained in:
parent
aef34af556
commit
fa28722ff7
@ -24,14 +24,15 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// Width and height of the application window
|
// Width and height of the application window
|
||||||
const sf::Vector2u windowSize(800, 600);
|
constexpr sf::Vector2u windowSize(800, 600);
|
||||||
|
|
||||||
// Resolution of the generated terrain
|
// Resolution of the generated terrain
|
||||||
const sf::Vector2u resolution(800, 600);
|
constexpr sf::Vector2u resolution(800, 600);
|
||||||
|
|
||||||
// Thread pool parameters
|
// Thread pool parameters
|
||||||
const unsigned int threadCount = 4;
|
constexpr unsigned int threadCount = 4;
|
||||||
const unsigned int blockCount = 32;
|
constexpr unsigned int blockCount = 32;
|
||||||
|
constexpr unsigned int rowBlockSize = (resolution.y / blockCount) + 1;
|
||||||
|
|
||||||
struct WorkItem
|
struct WorkItem
|
||||||
{
|
{
|
||||||
@ -53,7 +54,7 @@ struct Setting
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Terrain noise parameters
|
// Terrain noise parameters
|
||||||
const int perlinOctaves = 3;
|
constexpr int perlinOctaves = 3;
|
||||||
|
|
||||||
float perlinFrequency = 7.0f;
|
float perlinFrequency = 7.0f;
|
||||||
float perlinFrequencyBase = 4.0f;
|
float perlinFrequencyBase = 4.0f;
|
||||||
@ -242,7 +243,7 @@ sf::Vector2f computeNormal(float left, float right, float bottom, float top)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sf::Vertex computeVertex(sf::Vector2u position)
|
sf::Vertex computeVertex(sf::Vector2u position)
|
||||||
{
|
{
|
||||||
static const auto scalingFactors = sf::Vector2f(windowSize).componentWiseDiv(sf::Vector2f(resolution));
|
static constexpr auto scalingFactors = sf::Vector2f(windowSize).componentWiseDiv(sf::Vector2f(resolution));
|
||||||
sf::Vertex vertex;
|
sf::Vertex vertex;
|
||||||
vertex.position = sf::Vector2f(position).componentWiseMul(scalingFactors);
|
vertex.position = sf::Vector2f(position).componentWiseMul(scalingFactors);
|
||||||
vertex.color = getTerrainColor(getElevation(position), getMoisture(position));
|
vertex.color = getTerrainColor(getElevation(position), getMoisture(position));
|
||||||
@ -262,7 +263,6 @@ sf::Vertex computeVertex(sf::Vector2u position)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem)
|
void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem)
|
||||||
{
|
{
|
||||||
const unsigned int rowBlockSize = (resolution.y / blockCount) + 1;
|
|
||||||
const unsigned int rowStart = rowBlockSize * workItem.index;
|
const unsigned int rowStart = rowBlockSize * workItem.index;
|
||||||
|
|
||||||
if (rowStart >= resolution.y)
|
if (rowStart >= resolution.y)
|
||||||
@ -337,8 +337,6 @@ void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void threadFunction()
|
void threadFunction()
|
||||||
{
|
{
|
||||||
const unsigned int rowBlockSize = (resolution.y / blockCount) + 1;
|
|
||||||
|
|
||||||
std::vector<sf::Vertex> vertices(resolution.x * rowBlockSize * 6);
|
std::vector<sf::Vertex> vertices(resolution.x * rowBlockSize * 6);
|
||||||
|
|
||||||
WorkItem workItem = {nullptr, 0};
|
WorkItem workItem = {nullptr, 0};
|
||||||
|
@ -102,7 +102,7 @@ int main()
|
|||||||
|
|
||||||
// Set up our joystick identification sf::Text objects
|
// Set up our joystick identification sf::Text objects
|
||||||
{
|
{
|
||||||
auto [it, success] = texts.try_emplace("ID", JoystickObject{{font, "<Not Connected>"}, {font}});
|
const auto [it, success] = texts.try_emplace("ID", JoystickObject{{font, "<Not Connected>"}, {font}});
|
||||||
auto& [label, value] = it->second;
|
auto& [label, value] = it->second;
|
||||||
label.setPosition({5.f, 5.f});
|
label.setPosition({5.f, 5.f});
|
||||||
value.setPosition({80.f, 5.f});
|
value.setPosition({80.f, 5.f});
|
||||||
@ -112,7 +112,7 @@ int main()
|
|||||||
sstr.str("");
|
sstr.str("");
|
||||||
sstr << threshold << " (Change with up/down arrow keys)";
|
sstr << threshold << " (Change with up/down arrow keys)";
|
||||||
{
|
{
|
||||||
auto [it, success] = texts.try_emplace("Threshold", JoystickObject{{font, "Threshold:"}, {font, sstr.str()}});
|
const auto [it, success] = texts.emplace("Threshold", JoystickObject{{font, "Threshold:"}, {font, sstr.str()}});
|
||||||
auto& [label, value] = it->second;
|
auto& [label, value] = it->second;
|
||||||
label.setPosition({5.f, 5.f + 2 * font.getLineSpacing(14)});
|
label.setPosition({5.f, 5.f + 2 * font.getLineSpacing(14)});
|
||||||
value.setPosition({80.f, 5.f + 2 * font.getLineSpacing(14)});
|
value.setPosition({80.f, 5.f + 2 * font.getLineSpacing(14)});
|
||||||
@ -121,8 +121,8 @@ int main()
|
|||||||
// Set up our label-value sf::Text objects
|
// Set up our label-value sf::Text objects
|
||||||
for (unsigned int i = 0; i < sf::Joystick::AxisCount; ++i)
|
for (unsigned int i = 0; i < sf::Joystick::AxisCount; ++i)
|
||||||
{
|
{
|
||||||
auto [it,
|
const auto [it, success] = texts.try_emplace(axislabels[i],
|
||||||
success] = texts.try_emplace(axislabels[i], JoystickObject{{font, axislabels[i] + ":"}, {font, "N/A"}});
|
JoystickObject{{font, axislabels[i] + ":"}, {font, "N/A"}});
|
||||||
auto& [label, value] = it->second;
|
auto& [label, value] = it->second;
|
||||||
label.setPosition({5.f, 5.f + (static_cast<float>(i + 4) * font.getLineSpacing(14))});
|
label.setPosition({5.f, 5.f + (static_cast<float>(i + 4) * font.getLineSpacing(14))});
|
||||||
value.setPosition({80.f, 5.f + (static_cast<float>(i + 4) * font.getLineSpacing(14))});
|
value.setPosition({80.f, 5.f + (static_cast<float>(i + 4) * font.getLineSpacing(14))});
|
||||||
@ -132,7 +132,8 @@ int main()
|
|||||||
{
|
{
|
||||||
sstr.str("");
|
sstr.str("");
|
||||||
sstr << "Button " << i;
|
sstr << "Button " << i;
|
||||||
auto [it, success] = texts.try_emplace(sstr.str(), JoystickObject{{font, sstr.str() + ":"}, {font, "N/A"}});
|
const auto [it,
|
||||||
|
success] = texts.try_emplace(sstr.str(), JoystickObject{{font, sstr.str() + ":"}, {font, "N/A"}});
|
||||||
auto& [label, value] = it->second;
|
auto& [label, value] = it->second;
|
||||||
label.setPosition({5.f, 5.f + (static_cast<float>(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))});
|
label.setPosition({5.f, 5.f + (static_cast<float>(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))});
|
||||||
value.setPosition({80.f, 5.f + (static_cast<float>(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))});
|
value.setPosition({80.f, 5.f + (static_cast<float>(sf::Joystick::AxisCount + i + 4) * font.getLineSpacing(14))});
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
const std::uint8_t clientAudioData = 1;
|
constexpr std::uint8_t clientAudioData = 1;
|
||||||
const std::uint8_t clientEndOfStream = 2;
|
constexpr std::uint8_t clientEndOfStream = 2;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
const std::uint8_t serverAudioData = 1;
|
constexpr std::uint8_t serverAudioData = 1;
|
||||||
const std::uint8_t serverEndOfStream = 2;
|
constexpr std::uint8_t serverEndOfStream = 2;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -395,7 +395,7 @@ Packet& Packet::operator<<(std::uint8_t data)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet& Packet::operator<<(std::int16_t data)
|
Packet& Packet::operator<<(std::int16_t data)
|
||||||
{
|
{
|
||||||
auto toWrite = static_cast<std::int16_t>(htons(static_cast<std::uint16_t>(data)));
|
const auto toWrite = static_cast<std::int16_t>(htons(static_cast<std::uint16_t>(data)));
|
||||||
append(&toWrite, sizeof(toWrite));
|
append(&toWrite, sizeof(toWrite));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -404,7 +404,7 @@ Packet& Packet::operator<<(std::int16_t data)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet& Packet::operator<<(std::uint16_t data)
|
Packet& Packet::operator<<(std::uint16_t data)
|
||||||
{
|
{
|
||||||
std::uint16_t toWrite = htons(data);
|
const std::uint16_t toWrite = htons(data);
|
||||||
append(&toWrite, sizeof(toWrite));
|
append(&toWrite, sizeof(toWrite));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -413,7 +413,7 @@ Packet& Packet::operator<<(std::uint16_t data)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet& Packet::operator<<(std::int32_t data)
|
Packet& Packet::operator<<(std::int32_t data)
|
||||||
{
|
{
|
||||||
auto toWrite = static_cast<std::int32_t>(htonl(static_cast<std::uint32_t>(data)));
|
const auto toWrite = static_cast<std::int32_t>(htonl(static_cast<std::uint32_t>(data)));
|
||||||
append(&toWrite, sizeof(toWrite));
|
append(&toWrite, sizeof(toWrite));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -422,7 +422,7 @@ Packet& Packet::operator<<(std::int32_t data)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Packet& Packet::operator<<(std::uint32_t data)
|
Packet& Packet::operator<<(std::uint32_t data)
|
||||||
{
|
{
|
||||||
std::uint32_t toWrite = htonl(data);
|
const std::uint32_t toWrite = htonl(data);
|
||||||
append(&toWrite, sizeof(toWrite));
|
append(&toWrite, sizeof(toWrite));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,9 @@ namespace
|
|||||||
{
|
{
|
||||||
// Low-level send/receive flags (OS-dependent)
|
// Low-level send/receive flags (OS-dependent)
|
||||||
#ifdef SFML_SYSTEM_LINUX
|
#ifdef SFML_SYSTEM_LINUX
|
||||||
const int flags = MSG_NOSIGNAL;
|
constexpr int flags = MSG_NOSIGNAL;
|
||||||
#else
|
#else
|
||||||
const int flags = 0;
|
constexpr int flags = 0;
|
||||||
#endif
|
#endif
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ void SensorImpl::setEnabled(bool enabled)
|
|||||||
const ASensor* SensorImpl::getDefaultSensor(Sensor::Type sensor)
|
const ASensor* SensorImpl::getDefaultSensor(Sensor::Type sensor)
|
||||||
{
|
{
|
||||||
// Find the Android sensor type
|
// Find the Android sensor type
|
||||||
static EnumArray<Sensor::Type, int, Sensor::Count> types =
|
static constexpr EnumArray<Sensor::Type, int, Sensor::Count> types =
|
||||||
{ASENSOR_TYPE_ACCELEROMETER,
|
{ASENSOR_TYPE_ACCELEROMETER,
|
||||||
ASENSOR_TYPE_GYROSCOPE,
|
ASENSOR_TYPE_GYROSCOPE,
|
||||||
ASENSOR_TYPE_MAGNETIC_FIELD,
|
ASENSOR_TYPE_MAGNETIC_FIELD,
|
||||||
|
@ -174,12 +174,7 @@ DrmFb* drmFbGetFromBo(gbm_bo& bo)
|
|||||||
modifiers[static_cast<std::size_t>(i)] = modifiers[0];
|
modifiers[static_cast<std::size_t>(i)] = modifiers[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t flags = 0;
|
const std::uint32_t flags = modifiers[0] ? DRM_MODE_FB_MODIFIERS : 0;
|
||||||
if (modifiers[0])
|
|
||||||
{
|
|
||||||
flags = DRM_MODE_FB_MODIFIERS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int result = drmModeAddFB2WithModifiers(drmFd,
|
int result = drmModeAddFB2WithModifiers(drmFd,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
@ -695,13 +690,7 @@ void DRMContext::createContext(DRMContext* shared)
|
|||||||
{
|
{
|
||||||
static constexpr std::array contextVersion = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
|
static constexpr std::array contextVersion = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
|
||||||
|
|
||||||
EGLContext toShared = nullptr;
|
const EGLContext toShared = shared ? shared->m_context : EGL_NO_CONTEXT;
|
||||||
|
|
||||||
if (shared)
|
|
||||||
toShared = shared->m_context;
|
|
||||||
else
|
|
||||||
toShared = EGL_NO_CONTEXT;
|
|
||||||
|
|
||||||
if (toShared != EGL_NO_CONTEXT)
|
if (toShared != EGL_NO_CONTEXT)
|
||||||
eglCheck(eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
|
eglCheck(eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ std::vector<TouchSlot> touchSlots; // track the state of each touch "slot"
|
|||||||
int currentSlot = 0; // which slot are we currently updating?
|
int currentSlot = 0; // which slot are we currently updating?
|
||||||
|
|
||||||
std::queue<sf::Event> eventQueue; // events received and waiting to be consumed
|
std::queue<sf::Event> eventQueue; // events received and waiting to be consumed
|
||||||
const int maxQueue = 64; // The maximum size we let eventQueue grow to
|
constexpr int maxQueue = 64; // The maximum size we let eventQueue grow to
|
||||||
|
|
||||||
termios newTerminalConfig, oldTerminalConfig; // Terminal configurations
|
termios newTerminalConfig, oldTerminalConfig; // Terminal configurations
|
||||||
|
|
||||||
|
@ -254,13 +254,7 @@ void EglContext::createContext(EglContext* shared)
|
|||||||
{
|
{
|
||||||
static constexpr std::array contextVersion = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
|
static constexpr std::array contextVersion = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
|
||||||
|
|
||||||
EGLContext toShared = nullptr;
|
const EGLContext toShared = shared ? shared->m_context : EGL_NO_CONTEXT;
|
||||||
|
|
||||||
if (shared)
|
|
||||||
toShared = shared->m_context;
|
|
||||||
else
|
|
||||||
toShared = EGL_NO_CONTEXT;
|
|
||||||
|
|
||||||
if (toShared != EGL_NO_CONTEXT)
|
if (toShared != EGL_NO_CONTEXT)
|
||||||
eglCheck(eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
|
eglCheck(eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
const KeyCode nullKeyCode = 0;
|
constexpr KeyCode nullKeyCode = 0;
|
||||||
const int maxKeyCode = 256;
|
constexpr int maxKeyCode = 256;
|
||||||
sf::priv::EnumArray<sf::Keyboard::Scancode, KeyCode, sf::Keyboard::ScancodeCount> scancodeToKeycode; ///< Mapping of SFML scancode to X11 KeyCode
|
sf::priv::EnumArray<sf::Keyboard::Scancode, KeyCode, sf::Keyboard::ScancodeCount> scancodeToKeycode; ///< Mapping of SFML scancode to X11 KeyCode
|
||||||
std::array<sf::Keyboard::Scancode, maxKeyCode> keycodeToScancode; ///< Mapping of X11 KeyCode to SFML scancode
|
std::array<sf::Keyboard::Scancode, maxKeyCode> keycodeToScancode; ///< Mapping of X11 KeyCode to SFML scancode
|
||||||
|
|
||||||
|
@ -61,18 +61,18 @@ namespace
|
|||||||
namespace guids
|
namespace guids
|
||||||
{
|
{
|
||||||
// NOLINTBEGIN(readability-identifier-naming)
|
// NOLINTBEGIN(readability-identifier-naming)
|
||||||
const GUID IID_IDirectInput8W = {0xbf798031, 0x483a, 0x4da2, {0xaa, 0x99, 0x5d, 0x64, 0xed, 0x36, 0x97, 0x00}};
|
constexpr GUID IID_IDirectInput8W = {0xbf798031, 0x483a, 0x4da2, {0xaa, 0x99, 0x5d, 0x64, 0xed, 0x36, 0x97, 0x00}};
|
||||||
|
|
||||||
const GUID GUID_XAxis = {0xa36d02e0, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
constexpr GUID GUID_XAxis = {0xa36d02e0, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
||||||
const GUID GUID_YAxis = {0xa36d02e1, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
constexpr GUID GUID_YAxis = {0xa36d02e1, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
||||||
const GUID GUID_ZAxis = {0xa36d02e2, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
constexpr GUID GUID_ZAxis = {0xa36d02e2, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
||||||
const GUID GUID_RzAxis = {0xa36d02e3, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
constexpr GUID GUID_RzAxis = {0xa36d02e3, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
||||||
const GUID GUID_Slider = {0xa36d02e4, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
constexpr GUID GUID_Slider = {0xa36d02e4, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
||||||
|
|
||||||
const GUID GUID_POV = {0xa36d02f2, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
constexpr GUID GUID_POV = {0xa36d02f2, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
||||||
|
|
||||||
const GUID GUID_RxAxis = {0xa36d02f4, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
constexpr GUID GUID_RxAxis = {0xa36d02f4, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
||||||
const GUID GUID_RyAxis = {0xa36d02f5, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
constexpr GUID GUID_RyAxis = {0xa36d02f5, 0xc9f3, 0x11cf, {0xbf, 0xc7, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
|
||||||
// NOLINTEND(readability-identifier-naming)
|
// NOLINTEND(readability-identifier-naming)
|
||||||
} // namespace guids
|
} // namespace guids
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ unsigned int handleCount = 0; // All window handles
|
|||||||
const wchar_t* className = L"SFML_Window";
|
const wchar_t* className = L"SFML_Window";
|
||||||
sf::priv::WindowImplWin32* fullscreenWindow = nullptr;
|
sf::priv::WindowImplWin32* fullscreenWindow = nullptr;
|
||||||
|
|
||||||
const GUID guidDevinterfaceHid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30}};
|
constexpr GUID guidDevinterfaceHid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30}};
|
||||||
|
|
||||||
void setProcessDpiAware()
|
void setProcessDpiAware()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user