Reduce the scope of variables

This commit is contained in:
Chris Thrasher 2024-05-28 05:16:44 +00:00
parent 2c443d143b
commit 24dc6b5ea9
3 changed files with 6 additions and 9 deletions

View File

@ -473,7 +473,6 @@ void ensureMapping()
XkbGetNames(display.get(), XkbKeyNamesMask, descriptor);
std::unordered_map<std::string, sf::Keyboard::Scancode> nameScancodeMap = getNameScancodeMap();
sf::Keyboard::Scancode scancode = sf::Keyboard::Scan::Unknown;
for (int keycode = descriptor->min_key_code; keycode <= descriptor->max_key_code; ++keycode)
{
@ -486,7 +485,7 @@ void ensureMapping()
name[XkbKeyNameLength] = '\0';
const auto mappedScancode = nameScancodeMap.find(std::string(name));
scancode = sf::Keyboard::Scan::Unknown;
auto scancode = sf::Keyboard::Scan::Unknown;
if (mappedScancode != nameScancodeMap.end())
scancode = mappedScancode->second;
@ -505,7 +504,7 @@ void ensureMapping()
{
if (keycodeToScancode[static_cast<KeyCode>(keycode)] == sf::Keyboard::Scan::Unknown)
{
scancode = translateKeyCode(display.get(), static_cast<KeyCode>(keycode));
const auto scancode = translateKeyCode(display.get(), static_cast<KeyCode>(keycode));
if (scancode != sf::Keyboard::Scan::Unknown && scancodeToKeycode[scancode] == nullKeyCode)
scancodeToKeycode[scancode] = static_cast<KeyCode>(keycode);

View File

@ -57,8 +57,7 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
std::vector<VideoMode> modes;
// Open a connection with the X server
const auto display = openDisplay();
if (display)
if (const auto display = openDisplay())
{
// Retrieve the default screen number
const int screen = DefaultScreen(display.get());
@ -135,8 +134,7 @@ VideoMode VideoModeImpl::getDesktopMode()
VideoMode desktopMode;
// Open a connection with the X server
const auto display = openDisplay();
if (display)
if (const auto display = openDisplay())
{
// Retrieve the default screen number
const int screen = DefaultScreen(display.get());

View File

@ -110,7 +110,6 @@ struct ConnectionCache
bool connected{};
sf::Clock timer;
};
const sf::Time connectionRefreshDelay = sf::milliseconds(500);
ConnectionCache connectionCache[sf::Joystick::Count];
@ -252,6 +251,7 @@ bool JoystickImpl::isConnected(unsigned int index)
return isConnectedDInput(index);
ConnectionCache& cache = connectionCache[index];
constexpr sf::Time connectionRefreshDelay = sf::milliseconds(500);
if (!lazyUpdates && cache.timer.getElapsedTime() > connectionRefreshDelay)
{
JOYINFOEX joyInfo;