Added functions to clean-up input after a game (though they're not called yet)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3702 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-07-04 20:09:49 +00:00
parent a7abbf4c82
commit 18dc556fe6
8 changed files with 47 additions and 7 deletions

View File

@ -74,7 +74,7 @@ Robert Howie
- Skyline Track (with modifications by conso)
Elisee
Checker background
- Checker background
Marianne Gagnon (Auria)
- 'SnowTux peak' (Based on older 'Geeko peak')

View File

@ -57,7 +57,9 @@ public:
void setDevice(InputDevice* device)
{
m_device = device;
device->setPlayer(this);
if(device != NULL)
device->setPlayer(this);
}
void setName(const std::string &name_){m_name = name_;}

View File

@ -169,13 +169,15 @@ void setPlayer0Device(InputDevice* device)
std::cout << "Player 0 is using a gamepad\n";
}
// TODO : support moer than 1 player
// TODO : support more than 1 player
StateManager::addActivePlayer( UserConfigParams::m_player.get(0) );
UserConfigParams::m_player[0].setDevice(device);
// TODO : fall back in no-assign mode when aborting a game and going back to the menu
input_manager->getDeviceList()->setNoAssignMode(false);
// TODO : fall back in no-assign mode when aborting a game and going back to the menu
// how to revert assign mode :
// StateManager::resetActivePlayers();
// input_manager->getDeviceList()->setNoAssignMode(true);
}
/**

View File

@ -66,6 +66,16 @@ namespace StateManager
g_active_players.push_back(p);
}
void resetActivePlayers()
{
const int amount = g_active_players.size();
for(int i=0; i<amount; i++)
{
g_active_players[i].setDevice(NULL);
}
g_active_players.clearWithoutDeleting();
}
#if 0
#pragma mark Callbacks
#endif

View File

@ -39,6 +39,7 @@ namespace StateManager
const ptr_vector<Player, REF>& getActivePlayers();
void addActivePlayer(Player* p);
void resetActivePlayers();
void escapePressed();
}

View File

@ -44,9 +44,23 @@ bool DeviceManager::initGamePadSupport()
return something_new_to_write;
}
// -----------------------------------------------------------------------------
void DeviceManager::setNoAssignMode(const bool noAssignMode)
{
m_no_assign_mode = noAssignMode;
// when going back to no-assign mode, do some cleanup
if(noAssignMode)
{
for(unsigned int i=0; i<m_gamepad_amount; i++)
{
m_gamepads[i].setPlayer(NULL);
}
for(unsigned int n=0; n<m_keyboard_amount; n++)
{
m_keyboards[n].setPlayer(NULL);
}
}
}
// -----------------------------------------------------------------------------
GamePadDevice* DeviceManager::getGamePadFromIrrID(const int id)

View File

@ -32,6 +32,8 @@ public:
/**
* The device manager starts in "no-assign" mode, which means no input configuration is associated
* to any player. So all devices will react. This is used in menus before player set-up is done.
* Switching back to no-assign mode will also clear anything in devices that was associated with
* players in assign mode.
*/
bool noAssignMode() const { return m_no_assign_mode; }
void setNoAssignMode(const bool noAssignMode);

View File

@ -16,19 +16,28 @@ InputDevice::InputDevice()
m_player_id = -1;
}
// -----------------------------------------------------------------------------
/**
* Sets which players uses this device; or pass NULL to say no player uses it.
*/
void InputDevice::setPlayer(Player* owner)
{
if(owner == NULL)
{
m_player_id = -1;
return;
}
const ptr_vector<Player, REF>& players = StateManager::getActivePlayers();
const int playerAmount = players.size();
for(int n=0; n<playerAmount; n++)
{
if(players.getConst(n) == owner)
{
m_player_id = n; // TODO : reset m_player_id when ending a game
m_player_id = n;
return;
}
}
std::cerr << "Error, trying to assign that doesn't exist to a device\n";
std::cerr << "\n\nError, trying to assign that doesn't exist to a device!!!\n\n";
}
// -----------------------------------------------------------------------------
void InputDevice::serialize(std::ofstream& stream)