mirror of
https://github.com/SFML/SFML.git
synced 2024-11-29 06:41:05 +08:00
Joystick check on Linux is now a lot faster (globally improves the performances of pollEvent)
This commit is contained in:
parent
d716b3657c
commit
18f1b6263a
@ -29,7 +29,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sstream>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
@ -39,21 +39,21 @@ namespace priv
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool JoystickImpl::isConnected(unsigned int index)
|
bool JoystickImpl::isConnected(unsigned int index)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
char name[32];
|
||||||
oss << "/dev/input/js" << index;
|
std::sprintf(name, "/dev/input/js%u", index);
|
||||||
|
|
||||||
struct stat info;
|
struct stat info;
|
||||||
return stat(oss.str().c_str(), &info) == 0;
|
return stat(name, &info) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool JoystickImpl::open(unsigned int index)
|
bool JoystickImpl::open(unsigned int index)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
char name[32];
|
||||||
oss << "/dev/input/js" << index;
|
std::sprintf(name, "/dev/input/js%u", index);
|
||||||
|
|
||||||
m_file = ::open(oss.str().c_str(), O_RDONLY);
|
m_file = ::open(name, O_RDONLY);
|
||||||
if (m_file > 0)
|
if (m_file > 0)
|
||||||
{
|
{
|
||||||
// Use non-blocking mode
|
// Use non-blocking mode
|
||||||
|
Loading…
Reference in New Issue
Block a user