Compare commits

...

3 Commits

6 changed files with 36 additions and 0 deletions

View File

@ -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))

View File

@ -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);

View File

@ -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()

View File

@ -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

View File

@ -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];

View File

@ -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();
}