do all multiplayer input translation in StepMania.cpp

This commit is contained in:
Chris Danford
2006-01-10 18:23:20 +00:00
parent a9020229ee
commit d534772422
3 changed files with 68 additions and 93 deletions
+4 -20
View File
@@ -2172,27 +2172,11 @@ void ScreenGameplay::Input( const InputEventPlus &input )
if( GAMESTATE->m_bMultiplayer ) if( GAMESTATE->m_bMultiplayer )
{ {
MultiPlayer mp = MultiPlayer_INVALID; if( input.mp != MultiPlayer_INVALID &&
input.StyleI.IsValid() &&
// Translate input and sent to the appropriate player. Assume that all GAMESTATE->IsMultiPlayerEnabled(input.mp) )
// joystick devices are mapped the same as the master player.
if( input.DeviceI.IsJoystick() )
{ {
DeviceInput _DeviceI = input.DeviceI; m_vPlayerInfo[input.mp].m_pPlayer->Step( input.StyleI.col, input.DeviceI.ts );
_DeviceI.device = DEVICE_JOY1;
GameInput _GameI;
INPUTMAPPER->DeviceToGame( _DeviceI, _GameI );
if( input.GameI.IsValid() )
{
StyleInput _StyleI;
INPUTMAPPER->GameToStyle( _GameI, _StyleI );
mp = InputMapper::InputDeviceToMultiPlayer( input.DeviceI.device );
if( mp>=0 && mp<NUM_MultiPlayer )
m_vPlayerInfo[mp].m_pPlayer->Step( _StyleI.col, input.DeviceI.ts );
}
} }
} }
else else
+34 -48
View File
@@ -45,7 +45,6 @@ void ScreenJoinMultiplayer::Init()
GAMEMAN->GetStylesForGame( GAMESTATE->m_pCurGame, v, false ); GAMEMAN->GetStylesForGame( GAMESTATE->m_pCurGame, v, false );
GAMESTATE->m_pCurStyle.Set( v[0] ); GAMESTATE->m_pCurStyle.Set( v[0] );
GAMESTATE->m_PlayMode.Set( PLAY_MODE_REGULAR );
GAMESTATE->m_bTemporaryEventMode = true; GAMESTATE->m_bTemporaryEventMode = true;
GAMESTATE->m_MasterPlayerNumber = PLAYER_1; GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
@@ -106,57 +105,35 @@ void ScreenJoinMultiplayer::Input( const InputEventPlus &input )
// joystick devices are mapped the same as the master player. // joystick devices are mapped the same as the master player.
if( input.type == IET_FIRST_PRESS && if( input.type == IET_FIRST_PRESS &&
input.DeviceI.device >= DEVICE_JOY1 && input.DeviceI.device >= DEVICE_JOY1 &&
input.DeviceI.device < DEVICE_JOY1 + NUM_MultiPlayer ) input.DeviceI.device < DEVICE_JOY1 + NUM_MultiPlayer &&
input.MenuI.IsValid() )
{ {
DeviceInput di = input.DeviceI; MultiPlayerStatus old = m_MultiPlayerStatus[input.mp];
di.device = DEVICE_JOY1;
GameInput gi;
INPUTMAPPER->DeviceToGame( di, gi );
if( gi.IsValid() ) switch( input.MenuI.button )
{ {
MenuInput mi; case MENU_BUTTON_UP:
INPUTMAPPER->GameToMenu( gi, mi ); if( old == MultiPlayerStatus_NotJoined )
MultiPlayer p = InputMapper::InputDeviceToMultiPlayer( input.DeviceI.device );
// testing hack
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LSHIFT) ) )
p = (MultiPlayer)(p + 1);
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LCTRL) ) )
p = (MultiPlayer)(p + 2);
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LALT) ) )
p = (MultiPlayer)(p + 4);
ASSERT( p>=0 && p<NUM_MultiPlayer );
MultiPlayerStatus old = m_MultiPlayerStatus[p];
switch( mi.button )
{ {
case MENU_BUTTON_UP: m_soundJoin.Play();
if( old == MultiPlayerStatus_NotJoined ) m_MultiPlayerStatus[input.mp] = MultiPlayerStatus_Joined;
{ m_sprPlayer[input.mp]->PlayCommand( MultiPlayerStatusToString(m_MultiPlayerStatus[input.mp]) );
m_soundJoin.Play();
m_MultiPlayerStatus[p] = MultiPlayerStatus_Joined;
m_sprPlayer[p]->PlayCommand( MultiPlayerStatusToString(m_MultiPlayerStatus[p]) );
}
return; // input handled
case MENU_BUTTON_DOWN:
if( old == MultiPlayerStatus_Joined )
{
m_soundUnjoin.Play();
m_MultiPlayerStatus[p] = MultiPlayerStatus_NotJoined;
m_sprPlayer[p]->PlayCommand( MultiPlayerStatusToString(m_MultiPlayerStatus[p]) );
}
return; // input handled
case MENU_BUTTON_BACK:
MenuBack( GAMESTATE->m_MasterPlayerNumber );
return; // input handled
case MENU_BUTTON_START:
MenuStart( GAMESTATE->m_MasterPlayerNumber );
return; // input handled
} }
return; // input handled
case MENU_BUTTON_DOWN:
if( old == MultiPlayerStatus_Joined )
{
m_soundUnjoin.Play();
m_MultiPlayerStatus[input.mp] = MultiPlayerStatus_NotJoined;
m_sprPlayer[input.mp]->PlayCommand( MultiPlayerStatusToString(m_MultiPlayerStatus[input.mp]) );
}
return; // input handled
case MENU_BUTTON_BACK:
//MenuBack( GAMESTATE->m_MasterPlayerNumber );
return; // input handled
case MENU_BUTTON_START:
MenuStart( GAMESTATE->m_MasterPlayerNumber );
return; // input handled
} }
} }
@@ -184,7 +161,9 @@ void ScreenJoinMultiplayer::UpdatePlayerStatus( bool bFirstUpdate )
InputDeviceState idsOld = m_InputDeviceState[p]; InputDeviceState idsOld = m_InputDeviceState[p];
bool bWasConnected = idsOld == InputDeviceState_Connected; bool bWasConnected = idsOld == InputDeviceState_Connected;
InputDeviceState idsNew = INPUTMAN->GetInputDeviceState(id); // DEBUG
//InputDeviceState idsNew = INPUTMAN->GetInputDeviceState(id);
InputDeviceState idsNew = InputDeviceState_Connected;
if( INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD,KEY_RSHIFT)) ) if( INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD,KEY_RSHIFT)) )
idsNew = InputDeviceState_Disconnected; idsNew = InputDeviceState_Disconnected;
bool bIsConnected = idsNew == InputDeviceState_Connected; bool bIsConnected = idsNew == InputDeviceState_Connected;
@@ -235,8 +214,15 @@ void ScreenJoinMultiplayer::MenuBack( PlayerNumber pn )
} }
static LocalizedString JOIN_2_OR_MORE_PLAYERS ("ScreenJoinMultiplayer", "You must join 2 or more players before continuing."); static LocalizedString JOIN_2_OR_MORE_PLAYERS ("ScreenJoinMultiplayer", "You must join 2 or more players before continuing.");
static LocalizedString ONLY_PLAYER_1_CAN_START ("ScreenJoinMultiplayer", "Only Player 1 can start the game.");
void ScreenJoinMultiplayer::MenuStart( PlayerNumber pn ) void ScreenJoinMultiplayer::MenuStart( PlayerNumber pn )
{ {
if( pn != PLAYER_1 )
{
ScreenPrompt::Prompt( SM_None, ONLY_PLAYER_1_CAN_START );
return;
}
int iNumJoinedPlayers = 0; int iNumJoinedPlayers = 0;
FOREACH_MultiPlayer( p ) FOREACH_MultiPlayer( p )
{ {
+28 -23
View File
@@ -1332,6 +1332,17 @@ void HandleInputEvents(float fDeltaTime)
input.DeviceI = (DeviceInput)ieArray[i]; input.DeviceI = (DeviceInput)ieArray[i];
input.type = ieArray[i].type; input.type = ieArray[i].type;
// hack for testing with only one joytick
if( input.DeviceI.IsJoystick() )
{
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LSHIFT) ) )
input.DeviceI.device = (InputDevice)(input.DeviceI.device + 1);
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LCTRL) ) )
input.DeviceI.device = (InputDevice)(input.DeviceI.device + 2);
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LALT) ) )
input.DeviceI.device = (InputDevice)(input.DeviceI.device + 4);
}
INPUTMAPPER->DeviceToGame( input.DeviceI, input.GameI ); INPUTMAPPER->DeviceToGame( input.DeviceI, input.GameI );
if( input.GameI.IsValid() && input.type == IET_FIRST_PRESS ) if( input.GameI.IsValid() && input.type == IET_FIRST_PRESS )
@@ -1342,37 +1353,31 @@ void HandleInputEvents(float fDeltaTime)
INPUTMAPPER->GameToStyle( input.GameI, input.StyleI ); INPUTMAPPER->GameToStyle( input.GameI, input.StyleI );
} }
if( !GAMESTATE->m_bMultiplayer ) input.mp = MultiPlayer_INVALID;
{
input.mp = MultiPlayer_INVALID; if( GAMESTATE->m_bMultiplayer )
}
else
{ {
// Translate input and sent to the appropriate player. Assume that all // Translate input and sent to the appropriate player. Assume that all
// joystick devices are mapped the same as the master player. // joystick devices are mapped the same as the master player.
if( input.DeviceI.IsJoystick() ) if( input.DeviceI.IsJoystick() )
{ {
DeviceInput _DeviceI = input.DeviceI; DeviceInput diTemp = input.DeviceI;
_DeviceI.device = DEVICE_JOY1; diTemp.device = DEVICE_JOY1;
GameInput _GameI;
INPUTMAPPER->DeviceToGame( _DeviceI, _GameI );
if( input.GameI.IsValid() ) //LOG->Trace( "device %d, %d", diTemp.device, diTemp.button );
if( INPUTMAPPER->DeviceToGame(diTemp, input.GameI) )
{ {
StyleInput _StyleI; //LOG->Trace( "game %d %d", input.GameI.controller, input.GameI.button );
INPUTMAPPER->GameToStyle( _GameI, _StyleI ); INPUTMAPPER->GameToStyle( input.GameI, input.StyleI );
input.mp = InputMapper::InputDeviceToMultiPlayer( input.DeviceI.device ); INPUTMAPPER->GameToMenu( input.GameI, input.MenuI );
}
/* //LOG->Trace( "style %d %d", input.StyleI.player, input.StyleI.col );
// hack for testing with only one joytick //LOG->Trace( "menu %d %d", input.MenuI.player, input.MenuI.button );
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LSHIFT) ) )
p = (MultiPlayer)(p + 1); input.mp = InputMapper::InputDeviceToMultiPlayer( input.DeviceI.device );
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LCTRL) ) ) //LOG->Trace( "multiplayer %d", input.mp );
p = (MultiPlayer)(p + 2); ASSERT( input.mp >= 0 && input.mp < NUM_MultiPlayer );
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD,KEY_LALT) ) ) }
p = (MultiPlayer)(p + 4);
*/
} }
} }