mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
control for battery, pantographs, line breaker, converter and compressor
This commit is contained in:
@@ -31,6 +31,7 @@ keyboard_input::key( int const Key, int const Action ) {
|
||||
false :
|
||||
true );
|
||||
modifier = true;
|
||||
// whenever shift key is used it may affect currently pressed movement keys, so check and update these
|
||||
}
|
||||
if( ( Key == GLFW_KEY_LEFT_CONTROL ) || ( Key == GLFW_KEY_RIGHT_CONTROL ) ) {
|
||||
// update internal state, but don't bother passing these
|
||||
@@ -45,6 +46,16 @@ keyboard_input::key( int const Key, int const Action ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( true == update_movement( Key, Action ) ) {
|
||||
// if the received key was one of movement keys, it's been handled and we don't need to bother further
|
||||
return true;
|
||||
}
|
||||
|
||||
// store key state
|
||||
if( Key != -1 ) {
|
||||
m_keys[ Key ] = Action;
|
||||
}
|
||||
|
||||
// include active modifiers for currently pressed key, except if the key is a modifier itself
|
||||
auto const key =
|
||||
Key
|
||||
@@ -106,14 +117,16 @@ keyboard_input::default_bindings() {
|
||||
/*
|
||||
const int k_AntiSlipping = 21;
|
||||
const int k_Sand = 22;
|
||||
const int k_Main = 23;
|
||||
*/
|
||||
{ "linebreakertoggle", command_target::vehicle, GLFW_KEY_M },
|
||||
{ "reverserincrease", command_target::vehicle, GLFW_KEY_D },
|
||||
{ "reverserdecrease", command_target::vehicle, GLFW_KEY_R },
|
||||
/*
|
||||
const int k_Fuse = 26;
|
||||
const int k_Compressor = 27;
|
||||
const int k_Converter = 28;
|
||||
*/
|
||||
{ "compressortoggle", command_target::vehicle, GLFW_KEY_C },
|
||||
{ "convertertoggle", command_target::vehicle, GLFW_KEY_X },
|
||||
/*
|
||||
const int k_MaxCurrent = 29;
|
||||
const int k_CurrentAutoRelay = 30;
|
||||
const int k_BrakeProfile = 31;
|
||||
@@ -130,20 +143,12 @@ const int k_FailedEngineCutOff = 35;
|
||||
{ "moveback", command_target::entity, GLFW_KEY_DOWN },
|
||||
{ "moveup", command_target::entity, GLFW_KEY_PAGE_UP },
|
||||
{ "movedown", command_target::entity, GLFW_KEY_PAGE_DOWN },
|
||||
{ "moveleftfast", command_target::entity, GLFW_KEY_LEFT | keymodifier::shift },
|
||||
{ "moverightfast", command_target::entity, GLFW_KEY_RIGHT | keymodifier::shift },
|
||||
{ "moveforwardfast", command_target::entity, GLFW_KEY_UP | keymodifier::shift },
|
||||
{ "movebackfast", command_target::entity, GLFW_KEY_DOWN | keymodifier::shift },
|
||||
{ "moveupfast", command_target::entity, GLFW_KEY_PAGE_UP | keymodifier::shift },
|
||||
{ "movedownfast", command_target::entity, GLFW_KEY_PAGE_DOWN | keymodifier::shift }
|
||||
/*
|
||||
{ "moveleftfastest", command_target::entity, GLFW_KEY_LEFT | keymodifier::control },
|
||||
{ "moverightfastest", command_target::entity, GLFW_KEY_RIGHT | keymodifier::control },
|
||||
{ "moveforwardfastest", command_target::entity, GLFW_KEY_UP | keymodifier::control },
|
||||
{ "movebackfastest", command_target::entity, GLFW_KEY_DOWN | keymodifier::control },
|
||||
{ "moveupfastest", command_target::entity, GLFW_KEY_PAGE_UP | keymodifier::control },
|
||||
{ "movedownfastest", command_target::entity, GLFW_KEY_PAGE_DOWN | keymodifier::control }
|
||||
*/
|
||||
{ "moveleftfast", command_target::entity, -1 },
|
||||
{ "moverightfast", command_target::entity, -1 },
|
||||
{ "moveforwardfast", command_target::entity, -1 },
|
||||
{ "movebackfast", command_target::entity, -1 },
|
||||
{ "moveupfast", command_target::entity, -1 },
|
||||
{ "movedownfast", command_target::entity, -1 },
|
||||
/*
|
||||
const int k_CabForward = 42;
|
||||
const int k_CabBackward = 43;
|
||||
@@ -157,10 +162,10 @@ const int k_OpenRight = 50;
|
||||
const int k_CloseLeft = 51;
|
||||
const int k_CloseRight = 52;
|
||||
const int k_DepartureSignal = 53;
|
||||
const int k_PantFrontUp = 54;
|
||||
const int k_PantRearUp = 55;
|
||||
const int k_PantFrontDown = 56;
|
||||
const int k_PantRearDown = 57;
|
||||
*/
|
||||
{ "pantographtogglefront", command_target::vehicle, GLFW_KEY_P },
|
||||
{ "pantographtogglerear", command_target::vehicle, GLFW_KEY_O },
|
||||
/*
|
||||
const int k_Heating = 58;
|
||||
// const int k_FreeFlyMode= 59;
|
||||
const int k_LeftSign = 60;
|
||||
@@ -175,7 +180,9 @@ const int k_Univ3 = 68;
|
||||
const int k_Univ4 = 69;
|
||||
const int k_EndSign = 70;
|
||||
const int k_Active = 71;
|
||||
const int k_Battery = 72;
|
||||
*/
|
||||
{ "batterytoggle", command_target::vehicle, GLFW_KEY_J }
|
||||
/*
|
||||
const int k_WalkMode = 73;
|
||||
int const k_DimHeadlights = 74;
|
||||
*/
|
||||
@@ -199,6 +206,117 @@ keyboard_input::bind() {
|
||||
}
|
||||
++commandcode;
|
||||
}
|
||||
// cache movement key bindings, so we can test them faster in the input loop
|
||||
m_bindingscache.forward = m_commands[ static_cast<std::size_t>( user_command::moveforward ) ].binding;
|
||||
m_bindingscache.back = m_commands[ static_cast<std::size_t>( user_command::moveback ) ].binding;
|
||||
m_bindingscache.left = m_commands[ static_cast<std::size_t>( user_command::moveleft ) ].binding;
|
||||
m_bindingscache.right = m_commands[ static_cast<std::size_t>( user_command::moveright ) ].binding;
|
||||
m_bindingscache.up = m_commands[ static_cast<std::size_t>( user_command::moveup ) ].binding;
|
||||
m_bindingscache.down = m_commands[ static_cast<std::size_t>( user_command::movedown ) ].binding;
|
||||
}
|
||||
|
||||
// NOTE: ugliest code ever, gg
|
||||
bool
|
||||
keyboard_input::update_movement( int const Key, int const Action ) {
|
||||
|
||||
bool shift =
|
||||
( ( Key == GLFW_KEY_LEFT_SHIFT )
|
||||
|| ( Key == GLFW_KEY_RIGHT_SHIFT ) );
|
||||
bool movementkey =
|
||||
( ( Key == m_bindingscache.forward )
|
||||
|| ( Key == m_bindingscache.back )
|
||||
|| ( Key == m_bindingscache.left )
|
||||
|| ( Key == m_bindingscache.right )
|
||||
|| ( Key == m_bindingscache.up )
|
||||
|| ( Key == m_bindingscache.down ) );
|
||||
|
||||
if( false == ( shift || movementkey ) ) { return false; }
|
||||
|
||||
if( false == shift ) {
|
||||
// TODO: pass correct entity id once the missing systems are in place
|
||||
if( Key == m_bindingscache.forward ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::moveforwardfast :
|
||||
user_command::moveforward ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.forward ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.back ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::movebackfast :
|
||||
user_command::moveback ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.back ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.left ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::moveleftfast :
|
||||
user_command::moveleft ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.left ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.right ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::moverightfast :
|
||||
user_command::moveright ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.right ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.up ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::moveupfast :
|
||||
user_command::moveup ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.up ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.down ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::movedownfast :
|
||||
user_command::movedown ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.down ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if it's not the movement keys but one of shift keys, we might potentially need to update movement state
|
||||
if( m_keys[ Key ] == Action ) {
|
||||
// but not if it's just repeat
|
||||
return false;
|
||||
}
|
||||
// bit of recursion voodoo here, we fake relevant key presses so we don't have to duplicate the code from above
|
||||
if( m_keys[ m_bindingscache.forward ] != GLFW_RELEASE ) { update_movement( m_bindingscache.forward, m_keys[ m_bindingscache.forward ] ); }
|
||||
if( m_keys[ m_bindingscache.back ] != GLFW_RELEASE ) { update_movement( m_bindingscache.back, m_keys[ m_bindingscache.back ] ); }
|
||||
if( m_keys[ m_bindingscache.left ] != GLFW_RELEASE ) { update_movement( m_bindingscache.left, m_keys[ m_bindingscache.left ] ); }
|
||||
if( m_keys[ m_bindingscache.right ] != GLFW_RELEASE ) { update_movement( m_bindingscache.right, m_keys[ m_bindingscache.right ] ); }
|
||||
if( m_keys[ m_bindingscache.up ] != GLFW_RELEASE ) { update_movement( m_bindingscache.up, m_keys[ m_bindingscache.up ] ); }
|
||||
if( m_keys[ m_bindingscache.down ] != GLFW_RELEASE ) { update_movement( m_bindingscache.down, m_keys[ m_bindingscache.down ] ); }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user