Reduce the scope of variables

This commit is contained in:
Chris Thrasher 2024-10-12 10:39:19 -06:00 committed by Vittorio Romeo
parent 56f9ee2b40
commit cabc36b8a4
21 changed files with 64 additions and 125 deletions

View File

@ -240,10 +240,9 @@ sf::Vector2f computeNormal(float left, float right, float bottom, float top)
/// coordinates. /// coordinates.
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const auto scalingFactors = sf::Vector2f(windowSize).componentWiseDiv(sf::Vector2f(resolution));
sf::Vertex computeVertex(sf::Vector2u position) sf::Vertex computeVertex(sf::Vector2u position)
{ {
static const 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));

View File

@ -398,7 +398,7 @@ int main()
std::optional edgeEffect = tryLoadEdge(); std::optional edgeEffect = tryLoadEdge();
std::optional geometryEffect = tryLoadGeometry(); std::optional geometryEffect = tryLoadGeometry();
const auto optionalToPtr = [&](auto& effect) -> Effect* { return effect.has_value() ? &*effect : nullptr; }; const auto optionalToPtr = [](auto& effect) -> Effect* { return effect.has_value() ? &*effect : nullptr; };
const std::array<Effect*, 5> effects{optionalToPtr(pixelateEffect), const std::array<Effect*, 5> effects{optionalToPtr(pixelateEffect),
optionalToPtr(waveBlurEffect), optionalToPtr(waveBlurEffect),

View File

@ -462,9 +462,9 @@ std::optional<ma_device_id> AudioDevice::getSelectedDeviceId() const
if (!deviceName) if (!deviceName)
deviceName = PlaybackDevice::getDefaultDevice(); deviceName = PlaybackDevice::getDefaultDevice();
auto iter = std::find_if(devices.begin(), const auto iter = std::find_if(devices.begin(),
devices.end(), devices.end(),
[&](const auto& device) { return device.name == deviceName; }); [&deviceName](const auto& device) { return device.name == deviceName; });
if (iter != devices.end()) if (iter != devices.end())
return iter->id; return iter->id;

View File

@ -66,8 +66,8 @@ bool setDevice(const std::string& name)
{ {
// Perform a sanity check to make sure the user isn't passing us a non-existent device name // Perform a sanity check to make sure the user isn't passing us a non-existent device name
const auto devices = priv::AudioDevice::getAvailableDevices(); const auto devices = priv::AudioDevice::getAvailableDevices();
if (auto iter = std::find_if(devices.begin(), devices.end(), [&](const auto& device) { return device.name == name; }); if (std::find_if(devices.begin(), devices.end(), [&name](const auto& device) { return device.name == name; }) ==
iter == devices.end()) devices.end())
return false; return false;
return priv::AudioDevice::setDevice(name); return priv::AudioDevice::setDevice(name);

View File

@ -216,9 +216,7 @@ bool Image::loadFromFile(const std::filesystem::path& filename)
int width = 0; int width = 0;
int height = 0; int height = 0;
int channels = 0; int channels = 0;
const auto ptr = StbPtr(stbi_load(filename.string().c_str(), &width, &height, &channels, STBI_rgb_alpha)); if (const auto ptr = StbPtr(stbi_load(filename.string().c_str(), &width, &height, &channels, STBI_rgb_alpha)))
if (ptr)
{ {
// Assign the image properties // Assign the image properties
m_size = Vector2u(Vector2i(width, height)); m_size = Vector2u(Vector2i(width, height));
@ -251,10 +249,8 @@ bool Image::loadFromMemory(const void* data, std::size_t size)
int height = 0; int height = 0;
int channels = 0; int channels = 0;
const auto* buffer = static_cast<const unsigned char*>(data); const auto* buffer = static_cast<const unsigned char*>(data);
const auto ptr = StbPtr( if (const auto ptr = StbPtr(
stbi_load_from_memory(buffer, static_cast<int>(size), &width, &height, &channels, STBI_rgb_alpha)); stbi_load_from_memory(buffer, static_cast<int>(size), &width, &height, &channels, STBI_rgb_alpha)))
if (ptr)
{ {
// Assign the image properties // Assign the image properties
m_size = Vector2u(Vector2i(width, height)); m_size = Vector2u(Vector2i(width, height));
@ -299,9 +295,7 @@ bool Image::loadFromStream(InputStream& stream)
int width = 0; int width = 0;
int height = 0; int height = 0;
int channels = 0; int channels = 0;
const auto ptr = StbPtr(stbi_load_from_callbacks(&callbacks, &stream, &width, &height, &channels, STBI_rgb_alpha)); if (const auto ptr = StbPtr(stbi_load_from_callbacks(&callbacks, &stream, &width, &height, &channels, STBI_rgb_alpha)))
if (ptr)
{ {
// Assign the image properties // Assign the image properties
m_size = Vector2u(Vector2i(width, height)); m_size = Vector2u(Vector2i(width, height));

View File

@ -82,8 +82,7 @@ std::size_t getMaxTextureUnits()
// Read the contents of a file into an array of char // Read the contents of a file into an array of char
bool getFileContents(const std::filesystem::path& filename, std::vector<char>& buffer) bool getFileContents(const std::filesystem::path& filename, std::vector<char>& buffer)
{ {
std::ifstream file(filename, std::ios_base::binary); if (auto file = std::ifstream(filename, std::ios_base::binary))
if (file)
{ {
file.seekg(0, std::ios_base::end); file.seekg(0, std::ios_base::end);
const std::ifstream::pos_type size = file.tellg(); const std::ifstream::pos_type size = file.tellg();

View File

@ -226,9 +226,7 @@ std::uint32_t findCrtcForConnector(const sf::priv::Drm& drm, const drmModeRes& r
for (int i = 0; i < connector.count_encoders; ++i) for (int i = 0; i < connector.count_encoders; ++i)
{ {
const std::uint32_t encoderId = connector.encoders[i]; const std::uint32_t encoderId = connector.encoders[i];
const drmModeEncoderPtr encoder = drmModeGetEncoder(drm.fileDescriptor, encoderId); if (auto* encoder = drmModeGetEncoder(drm.fileDescriptor, encoderId))
if (encoder)
{ {
const std::uint32_t crtcId = findCrtcForEncoder(resources, *encoder); const std::uint32_t crtcId = findCrtcForEncoder(resources, *encoder);
@ -451,10 +449,8 @@ void checkInit()
// Use in combination with mode to request specific refresh rate for the mode // Use in combination with mode to request specific refresh rate for the mode
// if multiple refresh rates for same mode might be supported // if multiple refresh rates for same mode might be supported
unsigned int refreshRate = 0; unsigned int refreshRate = 0;
char* refreshString = std::getenv("SFML_DRM_REFRESH"); if (const char* refreshString = std::getenv("SFML_DRM_REFRESH"))
refreshRate = static_cast<unsigned int>(std::atoi(refreshString));
if (refreshString)
refreshRate = static_cast<unsigned int>(atoi(refreshString));
if (initDrm(drmNode, if (initDrm(drmNode,
deviceString, // device deviceString, // device

View File

@ -38,10 +38,7 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
{ {
std::vector<VideoMode> modes; std::vector<VideoMode> modes;
const Drm& drm = DRMContext::getDRM(); if (const auto* conn = DRMContext::getDRM().savedConnector)
drmModeConnectorPtr conn = drm.savedConnector;
if (conn)
{ {
for (int i = 0; i < conn->count_modes; i++) for (int i = 0; i < conn->count_modes; i++)
modes.push_back(VideoMode({conn->modes[i].hdisplay, conn->modes[i].vdisplay})); modes.push_back(VideoMode({conn->modes[i].hdisplay, conn->modes[i].vdisplay}));
@ -56,9 +53,7 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
VideoMode VideoModeImpl::getDesktopMode() VideoMode VideoModeImpl::getDesktopMode()
{ {
const Drm& drm = DRMContext::getDRM(); if (const auto* ptr = DRMContext::getDRM().mode)
drmModeModeInfoPtr ptr = drm.mode;
if (ptr)
return VideoMode({ptr->hdisplay, ptr->vdisplay}); return VideoMode({ptr->hdisplay, ptr->vdisplay});
return VideoMode({0, 0}); return VideoMode({0, 0});

View File

@ -111,9 +111,7 @@ void updatePluggedList()
* and check if they are joysticks. The index of JoystickImpl::open * and check if they are joysticks. The index of JoystickImpl::open
* does not match the /dev/uhid<index> device! * does not match the /dev/uhid<index> device!
*/ */
DIR* directory = opendir("/dev"); if (DIR* directory = opendir("/dev"))
if (directory)
{ {
unsigned int joystickCount = 0; unsigned int joystickCount = 0;
struct dirent* directoryEntry = readdir(directory); struct dirent* directoryEntry = readdir(directory);

View File

@ -269,9 +269,7 @@ struct GlContext::SharedContext
if (glGetErrorFunc() == GL_INVALID_ENUM || !majorVersion || !glGetStringiFunc) if (glGetErrorFunc() == GL_INVALID_ENUM || !majorVersion || !glGetStringiFunc)
{ {
// Try to load the < 3.0 way // Try to load the < 3.0 way
const char* extensionString = reinterpret_cast<const char*>(glGetStringFunc(GL_EXTENSIONS)); if (const char* extensionString = reinterpret_cast<const char*>(glGetStringFunc(GL_EXTENSIONS)))
if (extensionString)
{ {
extensions.clear(); extensions.clear();
@ -297,15 +295,11 @@ struct GlContext::SharedContext
extensions.clear(); extensions.clear();
for (unsigned int i = 0; i < static_cast<unsigned int>(numExtensions); ++i) for (unsigned int i = 0; i < static_cast<unsigned int>(numExtensions); ++i)
{ if (const char* extensionString = reinterpret_cast<const char*>(glGetStringiFunc(GL_EXTENSIONS, i)))
const char* extensionString = reinterpret_cast<const char*>(glGetStringiFunc(GL_EXTENSIONS, i));
if (extensionString)
extensions.emplace_back(extensionString); extensions.emplace_back(extensionString);
} }
} }
} }
}
// AMD drivers have issues with internal synchronization // AMD drivers have issues with internal synchronization
// We need to make sure that no operating system context // We need to make sure that no operating system context
@ -496,7 +490,7 @@ void GlContext::unregisterUnsharedGlObject(std::shared_ptr<void> object)
// in unshared objects should be the only one existing // in unshared objects should be the only one existing
const auto iter = std::find_if(unsharedGlObjects->begin(), const auto iter = std::find_if(unsharedGlObjects->begin(),
unsharedGlObjects->end(), unsharedGlObjects->end(),
[&](const Impl::UnsharedGlObject& obj) { [&object](const Impl::UnsharedGlObject& obj) {
return (obj.object == object) && return (obj.object == object) &&
(obj.contextId == GlContextImpl::CurrentContext::get().id); (obj.contextId == GlContextImpl::CurrentContext::get().id);
}); });
@ -917,8 +911,7 @@ void GlContext::initialize(const ContextSettings& requestedSettings)
m_settings.majorVersion = 1; m_settings.majorVersion = 1;
m_settings.minorVersion = 1; m_settings.minorVersion = 1;
const char* version = reinterpret_cast<const char*>(glGetStringFunc(GL_VERSION)); if (const char* version = reinterpret_cast<const char*>(glGetStringFunc(GL_VERSION)))
if (version)
{ {
// OpenGL ES Common Lite profile: The beginning of the returned string is "OpenGL ES-CL major.minor" // OpenGL ES Common Lite profile: The beginning of the returned string is "OpenGL ES-CL major.minor"
// OpenGL ES Common profile: The beginning of the returned string is "OpenGL ES-CM major.minor" // OpenGL ES Common profile: The beginning of the returned string is "OpenGL ES-CM major.minor"

View File

@ -112,9 +112,7 @@ void updatePluggedList()
* and check if they are joysticks. The index of JoystickImpl::open * and check if they are joysticks. The index of JoystickImpl::open
* does not match the /dev/uhid<index> device! * does not match the /dev/uhid<index> device!
*/ */
DIR* directory = opendir("/dev"); if (DIR* directory = opendir("/dev"))
if (directory)
{ {
unsigned int joystickCount = 0; unsigned int joystickCount = 0;
struct dirent* directoryEntry = readdir(directory); struct dirent* directoryEntry = readdir(directory);

View File

@ -300,8 +300,7 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe
// Retrieve all the visuals // Retrieve all the visuals
int count = 0; int count = 0;
const auto visuals = X11Ptr<XVisualInfo[]>(XGetVisualInfo(display, 0, nullptr, &count)); if (const auto visuals = X11Ptr<XVisualInfo[]>(XGetVisualInfo(display, 0, nullptr, &count)))
if (visuals)
{ {
// Evaluate all the returned visuals, and pick the best one // Evaluate all the returned visuals, and pick the best one
int bestScore = 0x7FFFFFFF; int bestScore = 0x7FFFFFFF;

View File

@ -139,8 +139,7 @@ Vector2i getMousePosition()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2i getMousePosition(const WindowBase& relativeTo) Vector2i getMousePosition(const WindowBase& relativeTo)
{ {
const WindowHandle handle = relativeTo.getNativeHandle(); if (const WindowHandle handle = relativeTo.getNativeHandle())
if (handle)
{ {
// Open a connection with the X server // Open a connection with the X server
const auto display = openDisplay(); const auto display = openDisplay();
@ -180,8 +179,7 @@ void setMousePosition(Vector2i position, const WindowBase& relativeTo)
// Open a connection with the X server // Open a connection with the X server
const auto display = openDisplay(); const auto display = openDisplay();
const WindowHandle handle = relativeTo.getNativeHandle(); if (const WindowHandle handle = relativeTo.getNativeHandle())
if (handle)
{ {
XWarpPointer(display.get(), None, handle, 0, 0, 0, 0, position.x, position.y); XWarpPointer(display.get(), None, handle, 0, 0, 0, 0, position.x, position.y);
XFlush(display.get()); XFlush(display.get());

View File

@ -120,9 +120,7 @@ bool isJoystick(udev_device* udevDevice)
// On some platforms (older udev), ID_INPUT_ properties are not present, instead // On some platforms (older udev), ID_INPUT_ properties are not present, instead
// the system makes use of the ID_CLASS property to identify the device class // the system makes use of the ID_CLASS property to identify the device class
const char* idClass = udev_device_get_property_value(udevDevice, "ID_CLASS"); if (const char* idClass = udev_device_get_property_value(udevDevice, "ID_CLASS"))
if (idClass)
{ {
// Check if the device class matches joystick // Check if the device class matches joystick
if (std::strstr(idClass, "joystick")) if (std::strstr(idClass, "joystick"))
@ -144,9 +142,7 @@ void updatePluggedList(udev_device* udevDevice = nullptr)
{ {
if (udevDevice) if (udevDevice)
{ {
const char* action = udev_device_get_action(udevDevice); if (const char* action = udev_device_get_action(udevDevice))
if (action)
{ {
if (isJoystick(udevDevice)) if (isJoystick(udevDevice))
{ {
@ -300,13 +296,10 @@ unsigned int getUsbAttributeUint(udev_device* udevDevice, const std::string& att
if (!udevDevice) if (!udevDevice)
return 0; return 0;
const char* attribute = getUsbAttribute(udevDevice, attributeName); if (const char* attribute = getUsbAttribute(udevDevice, attributeName))
unsigned int value = 0; return static_cast<unsigned int>(std::strtoul(attribute, nullptr, 16));
if (attribute) return 0;
value = static_cast<unsigned int>(std::strtoul(attribute, nullptr, 16));
return value;
} }
// Get a udev property value for a joystick as an unsigned int // Get a udev property value for a joystick as an unsigned int
@ -315,13 +308,10 @@ unsigned int getUdevAttributeUint(udev_device* udevDevice, const std::string& at
if (!udevDevice) if (!udevDevice)
return 0; return 0;
const char* attribute = getUdevAttribute(udevDevice, attributeName); if (const char* attribute = getUdevAttribute(udevDevice, attributeName))
unsigned int value = 0; return static_cast<unsigned int>(std::strtoul(attribute, nullptr, 16));
if (attribute) return 0;
value = static_cast<unsigned int>(std::strtoul(attribute, nullptr, 16));
return value;
} }
// Get the joystick vendor id // Get the joystick vendor id
@ -408,14 +398,10 @@ std::string getJoystickName(unsigned int index)
// Fall back to manual USB chain walk via udev // Fall back to manual USB chain walk via udev
if (udevContext) if (udevContext)
{ if (const auto udevDevice = UdevPtr<udev_device>(
const auto udevDevice = UdevPtr<udev_device>( udev_device_new_from_syspath(udevContext.get(), joystickList[index].systemPath.c_str())))
udev_device_new_from_syspath(udevContext.get(), joystickList[index].systemPath.c_str()));
if (udevDevice)
if (const char* product = getUsbAttribute(udevDevice.get(), "product")) if (const char* product = getUsbAttribute(udevDevice.get(), "product"))
return {product}; return {product};
}
sf::err() << "Unable to get name for joystick " << devnode << std::endl; sf::err() << "Unable to get name for joystick " << devnode << std::endl;

View File

@ -67,9 +67,8 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
if (XQueryExtension(display.get(), "RANDR", &version, &version, &version)) if (XQueryExtension(display.get(), "RANDR", &version, &version, &version))
{ {
// Get the current configuration // Get the current configuration
const auto config = X11Ptr<XRRScreenConfiguration>( if (const auto config = X11Ptr<XRRScreenConfiguration>(
XRRGetScreenInfo(display.get(), RootWindow(display.get(), screen))); XRRGetScreenInfo(display.get(), RootWindow(display.get(), screen))))
if (config)
{ {
// Get the available screen sizes // Get the available screen sizes
int nbSizes = 0; int nbSizes = 0;
@ -144,9 +143,8 @@ VideoMode VideoModeImpl::getDesktopMode()
if (XQueryExtension(display.get(), "RANDR", &version, &version, &version)) if (XQueryExtension(display.get(), "RANDR", &version, &version, &version))
{ {
// Get the current configuration // Get the current configuration
const auto config = X11Ptr<XRRScreenConfiguration>( if (const auto config = X11Ptr<XRRScreenConfiguration>(
XRRGetScreenInfo(display.get(), RootWindow(display.get(), screen))); XRRGetScreenInfo(display.get(), RootWindow(display.get(), screen))))
if (config)
{ {
// Get the current video mode // Get the current video mode
Rotation currentRotation = 0; Rotation currentRotation = 0;

View File

@ -88,8 +88,6 @@ std::bitset<256> isKeyFiltered;
std::recursive_mutex allWindowsMutex; std::recursive_mutex allWindowsMutex;
sf::String windowManagerName; sf::String windowManagerName;
sf::String wmAbsPosGood[] = {"Enlightenment", "FVWM", "i3"};
constexpr unsigned long eventMask = FocusChangeMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | constexpr unsigned long eventMask = FocusChangeMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask | PointerMotionMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask |
EnterWindowMask | LeaveWindowMask | VisibilityChangeMask | PropertyChangeMask; EnterWindowMask | LeaveWindowMask | VisibilityChangeMask | PropertyChangeMask;
@ -365,9 +363,10 @@ bool isWMAbsolutePositionGood()
if (!ewmhSupported()) if (!ewmhSupported())
return false; return false;
return std::any_of(std::begin(wmAbsPosGood), static const std::array<sf::String, 3> wmAbsPosGood = {"Enlightenment", "FVWM", "i3"};
std::end(wmAbsPosGood), return std::any_of(wmAbsPosGood.begin(),
[&](const sf::String& name) { return name == windowManagerName; }); wmAbsPosGood.end(),
[](const sf::String& name) { return name == windowManagerName; });
} }
// Initialize raw mouse input // Initialize raw mouse input
@ -569,8 +568,7 @@ m_cursorGrabbed(m_fullscreen)
// change our window's decorations and functions according to the requested style) // change our window's decorations and functions according to the requested style)
if (!m_fullscreen) if (!m_fullscreen)
{ {
const Atom wmHintsAtom = getAtom("_MOTIF_WM_HINTS", false); if (const Atom wmHintsAtom = getAtom("_MOTIF_WM_HINTS", false))
if (wmHintsAtom)
{ {
// NOLINTBEGIN(readability-identifier-naming) // NOLINTBEGIN(readability-identifier-naming)
// Disable naming check so these better match the contents of the Motif library // Disable naming check so these better match the contents of the Motif library
@ -1430,9 +1428,7 @@ void WindowImplX11::switchToFullscreen()
if (ewmhSupported()) if (ewmhSupported())
{ {
const Atom netWmBypassCompositor = getAtom("_NET_WM_BYPASS_COMPOSITOR"); if (const Atom netWmBypassCompositor = getAtom("_NET_WM_BYPASS_COMPOSITOR"))
if (netWmBypassCompositor)
{ {
constexpr unsigned long bypassCompositor = 1; constexpr unsigned long bypassCompositor = 1;

View File

@ -91,9 +91,7 @@ void ClipboardImpl::setString(const String& text)
// Create a Win32-compatible string // Create a Win32-compatible string
const std::size_t stringSize = (text.getSize() + 1) * sizeof(WCHAR); const std::size_t stringSize = (text.getSize() + 1) * sizeof(WCHAR);
HANDLE stringHandle = GlobalAlloc(GMEM_MOVEABLE, stringSize); if (const HANDLE stringHandle = GlobalAlloc(GMEM_MOVEABLE, stringSize))
if (stringHandle)
{ {
std::memcpy(GlobalLock(stringHandle), text.toWideString().data(), stringSize); std::memcpy(GlobalLock(stringHandle), text.toWideString().data(), stringSize);
GlobalUnlock(stringHandle); GlobalUnlock(stringHandle);

View File

@ -703,8 +703,7 @@ Vector2i getMousePosition()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Vector2i getMousePosition(const WindowBase& relativeTo) Vector2i getMousePosition(const WindowBase& relativeTo)
{ {
WindowHandle handle = relativeTo.getNativeHandle(); if (const WindowHandle handle = relativeTo.getNativeHandle())
if (handle)
{ {
POINT point; POINT point;
GetCursorPos(&point); GetCursorPos(&point);
@ -726,8 +725,7 @@ void setMousePosition(Vector2i position)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void setMousePosition(Vector2i position, const WindowBase& relativeTo) void setMousePosition(Vector2i position, const WindowBase& relativeTo)
{ {
WindowHandle handle = relativeTo.getNativeHandle(); if (const WindowHandle handle = relativeTo.getNativeHandle())
if (handle)
{ {
POINT point = {position.x, position.y}; POINT point = {position.x, position.y};
ClientToScreen(handle, &point); ClientToScreen(handle, &point);

View File

@ -69,9 +69,7 @@ const GUID guidDevinterfaceHid = {0x4d1e55b2, 0xf16f, 0x11cf, {0x88, 0xcb, 0x00,
void setProcessDpiAware() void setProcessDpiAware()
{ {
// Try SetProcessDpiAwareness first // Try SetProcessDpiAwareness first
HINSTANCE shCoreDll = LoadLibrary(L"Shcore.dll"); if (const HINSTANCE shCoreDll = LoadLibrary(L"Shcore.dll"))
if (shCoreDll)
{ {
enum ProcessDpiAwareness enum ProcessDpiAwareness
{ {
@ -109,9 +107,7 @@ void setProcessDpiAware()
// Fall back to SetProcessDPIAware if SetProcessDpiAwareness // Fall back to SetProcessDPIAware if SetProcessDpiAwareness
// is not available on this system // is not available on this system
HINSTANCE user32Dll = LoadLibrary(L"user32.dll"); if (const HINSTANCE user32Dll = LoadLibrary(L"user32.dll"))
if (user32Dll)
{ {
using SetProcessDPIAwareFuncType = BOOL(WINAPI*)(); using SetProcessDPIAwareFuncType = BOOL(WINAPI*)();
auto setProcessDPIAwareFunc = reinterpret_cast<SetProcessDPIAwareFuncType>( auto setProcessDPIAwareFunc = reinterpret_cast<SetProcessDPIAwareFuncType>(

View File

@ -228,7 +228,7 @@ void WindowImpl::setMaximumSize(const std::optional<Vector2u>& maximumSize)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::optional<Event> WindowImpl::waitEvent(Time timeout) std::optional<Event> WindowImpl::waitEvent(Time timeout)
{ {
const auto timedOut = [&, startTime = std::chrono::steady_clock::now()] const auto timedOut = [timeout, startTime = std::chrono::steady_clock::now()]
{ {
const bool infiniteTimeout = timeout == Time::Zero; const bool infiniteTimeout = timeout == Time::Zero;
return !infiniteTimeout && (std::chrono::steady_clock::now() - startTime) >= timeout.toDuration(); return !infiniteTimeout && (std::chrono::steady_clock::now() - startTime) >= timeout.toDuration();

View File

@ -215,9 +215,7 @@ void SFContext::createContext(SFContext* shared, unsigned int bitsPerPixel, cons
// 1.x/2.x are mapped to 2.1 since Apple only support that legacy version. // 1.x/2.x are mapped to 2.1 since Apple only support that legacy version.
// >=3.0 are mapped to a 3.2 core profile. // >=3.0 are mapped to a 3.2 core profile.
const bool legacy = m_settings.majorVersion < 3; if (m_settings.majorVersion < 3)
if (legacy)
{ {
m_settings.attributeFlags &= ~static_cast<unsigned int>(ContextSettings::Core); m_settings.attributeFlags &= ~static_cast<unsigned int>(ContextSettings::Core);
m_settings.majorVersion = 2; m_settings.majorVersion = 2;