mirror of https://github.com/blawar/ooot.git
Compare commits
3 Commits
1d3aabe643
...
75e9f69086
Author | SHA1 | Date |
---|---|---|
Fred Hallock | 75e9f69086 | |
Fred Hallock | 4e3b367ec1 | |
Fred Hallock | 4709c04d77 |
|
@ -523,6 +523,16 @@ namespace oot::hid
|
|||
|
||||
init_ok = true;
|
||||
|
||||
if(m_controllers.size() > 0)
|
||||
{
|
||||
for(auto it = m_controllers.begin(); it != m_controllers.end(); it++)
|
||||
{
|
||||
players().detach(*it, 0);
|
||||
}
|
||||
|
||||
m_controllers.resize(0);
|
||||
}
|
||||
|
||||
for(int i = 0; i < SDL_NumJoysticks(); i++)
|
||||
{
|
||||
if(SDL_IsGameController(i))
|
||||
|
|
|
@ -16,6 +16,18 @@ namespace oot
|
|||
m_controllers.push_back(controller);
|
||||
}
|
||||
|
||||
void Player::detach(const std::shared_ptr<hid::Controller>& controller)
|
||||
{
|
||||
for(auto it = m_controllers.begin(); it != m_controllers.end(); it++)
|
||||
{
|
||||
if(*it == controller)
|
||||
{
|
||||
m_controllers.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::detachControllers()
|
||||
{
|
||||
m_controllers.resize(0);
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace oot
|
|||
}
|
||||
void resetBindings();
|
||||
void attach(const std::shared_ptr<hid::Controller>& controller);
|
||||
void detach(const std::shared_ptr<hid::Controller>& controller);
|
||||
void detachControllers();
|
||||
void update();
|
||||
hid::Controller& controller()
|
||||
|
|
|
@ -62,4 +62,9 @@ namespace oot
|
|||
m_size = std::max((u64)playerId + 1, m_size);
|
||||
}
|
||||
}
|
||||
|
||||
void Players::detach(const std::shared_ptr<hid::Controller>& controller, const u8 playerId)
|
||||
{
|
||||
m_players[playerId].detach(controller);
|
||||
}
|
||||
} // namespace oot
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace oot
|
|||
return m_players[i];
|
||||
}
|
||||
void attach(const std::shared_ptr<hid::Controller>& controller, const u8 playerId = MAX_PLAYERS);
|
||||
void detach(const std::shared_ptr<hid::Controller>& controller, const u8 playerId = MAX_PLAYERS);
|
||||
|
||||
protected:
|
||||
Player m_players[MAX_PLAYERS];
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include "z64message.h"
|
||||
#include "port/options.h"
|
||||
#include "port/debug.h"
|
||||
#include "port/controller/controllers.h"
|
||||
#include "port/controller/sdl.h"
|
||||
|
||||
void quit();
|
||||
void Set_Language(u8 language_id);
|
||||
|
@ -391,6 +393,11 @@ namespace platform::window
|
|||
resize(event.window.data1, event.window.data2);
|
||||
}
|
||||
break;
|
||||
// Whenever a device is added or removed, call this function to ensure that they are detected
|
||||
case SDL_JOYDEVICEADDED:
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
oot::hid::controllers().scan();
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
quit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue