mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 14:21:04 +08:00
Reduce the scope of variables
This commit is contained in:
parent
2c443d143b
commit
24dc6b5ea9
@ -473,7 +473,6 @@ void ensureMapping()
|
|||||||
XkbGetNames(display.get(), XkbKeyNamesMask, descriptor);
|
XkbGetNames(display.get(), XkbKeyNamesMask, descriptor);
|
||||||
|
|
||||||
std::unordered_map<std::string, sf::Keyboard::Scancode> nameScancodeMap = getNameScancodeMap();
|
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)
|
for (int keycode = descriptor->min_key_code; keycode <= descriptor->max_key_code; ++keycode)
|
||||||
{
|
{
|
||||||
@ -486,7 +485,7 @@ void ensureMapping()
|
|||||||
name[XkbKeyNameLength] = '\0';
|
name[XkbKeyNameLength] = '\0';
|
||||||
|
|
||||||
const auto mappedScancode = nameScancodeMap.find(std::string(name));
|
const auto mappedScancode = nameScancodeMap.find(std::string(name));
|
||||||
scancode = sf::Keyboard::Scan::Unknown;
|
auto scancode = sf::Keyboard::Scan::Unknown;
|
||||||
|
|
||||||
if (mappedScancode != nameScancodeMap.end())
|
if (mappedScancode != nameScancodeMap.end())
|
||||||
scancode = mappedScancode->second;
|
scancode = mappedScancode->second;
|
||||||
@ -505,7 +504,7 @@ void ensureMapping()
|
|||||||
{
|
{
|
||||||
if (keycodeToScancode[static_cast<KeyCode>(keycode)] == sf::Keyboard::Scan::Unknown)
|
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)
|
if (scancode != sf::Keyboard::Scan::Unknown && scancodeToKeycode[scancode] == nullKeyCode)
|
||||||
scancodeToKeycode[scancode] = static_cast<KeyCode>(keycode);
|
scancodeToKeycode[scancode] = static_cast<KeyCode>(keycode);
|
||||||
|
@ -57,8 +57,7 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
|
|||||||
std::vector<VideoMode> modes;
|
std::vector<VideoMode> modes;
|
||||||
|
|
||||||
// Open a connection with the X server
|
// Open a connection with the X server
|
||||||
const auto display = openDisplay();
|
if (const auto display = openDisplay())
|
||||||
if (display)
|
|
||||||
{
|
{
|
||||||
// Retrieve the default screen number
|
// Retrieve the default screen number
|
||||||
const int screen = DefaultScreen(display.get());
|
const int screen = DefaultScreen(display.get());
|
||||||
@ -135,8 +134,7 @@ VideoMode VideoModeImpl::getDesktopMode()
|
|||||||
VideoMode desktopMode;
|
VideoMode desktopMode;
|
||||||
|
|
||||||
// Open a connection with the X server
|
// Open a connection with the X server
|
||||||
const auto display = openDisplay();
|
if (const auto display = openDisplay())
|
||||||
if (display)
|
|
||||||
{
|
{
|
||||||
// Retrieve the default screen number
|
// Retrieve the default screen number
|
||||||
const int screen = DefaultScreen(display.get());
|
const int screen = DefaultScreen(display.get());
|
||||||
|
@ -110,7 +110,6 @@ struct ConnectionCache
|
|||||||
bool connected{};
|
bool connected{};
|
||||||
sf::Clock timer;
|
sf::Clock timer;
|
||||||
};
|
};
|
||||||
const sf::Time connectionRefreshDelay = sf::milliseconds(500);
|
|
||||||
|
|
||||||
ConnectionCache connectionCache[sf::Joystick::Count];
|
ConnectionCache connectionCache[sf::Joystick::Count];
|
||||||
|
|
||||||
@ -251,7 +250,8 @@ bool JoystickImpl::isConnected(unsigned int index)
|
|||||||
if (directInput)
|
if (directInput)
|
||||||
return isConnectedDInput(index);
|
return isConnectedDInput(index);
|
||||||
|
|
||||||
ConnectionCache& cache = connectionCache[index];
|
ConnectionCache& cache = connectionCache[index];
|
||||||
|
constexpr sf::Time connectionRefreshDelay = sf::milliseconds(500);
|
||||||
if (!lazyUpdates && cache.timer.getElapsedTime() > connectionRefreshDelay)
|
if (!lazyUpdates && cache.timer.getElapsedTime() > connectionRefreshDelay)
|
||||||
{
|
{
|
||||||
JOYINFOEX joyInfo;
|
JOYINFOEX joyInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user