mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 06:59:18 +02:00
restored support for second movement speed control key, converter sound frequency calculation fix
This commit is contained in:
322
Camera.cpp
322
Camera.cpp
@@ -49,9 +49,8 @@ void TCamera::OnCursorMove(double x, double y)
|
|||||||
void
|
void
|
||||||
TCamera::OnCommand( command_data const &Command ) {
|
TCamera::OnCommand( command_data const &Command ) {
|
||||||
|
|
||||||
double const walkspeed = 1.0;
|
auto const walkspeed { 1.0 };
|
||||||
double const runspeed = ( DebugModeFlag ? 50.0 : 7.5 );
|
auto const runspeed { 7.5 };
|
||||||
double const speedmultiplier = ( DebugModeFlag ? 7.5 : 1.0 );
|
|
||||||
|
|
||||||
switch( Command.command ) {
|
switch( Command.command ) {
|
||||||
|
|
||||||
@@ -63,232 +62,67 @@ TCamera::OnCommand( command_data const &Command ) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case user_command::movevector: {
|
case user_command::movehorizontal:
|
||||||
|
case user_command::movehorizontalfast: {
|
||||||
|
|
||||||
auto const movespeed =
|
auto const movespeed = (
|
||||||
( Type == tp_Free ?
|
Type == tp_Free ? runspeed :
|
||||||
runspeed * speedmultiplier :
|
Type == tp_Follow ? walkspeed :
|
||||||
walkspeed );
|
0.0 );
|
||||||
|
|
||||||
|
auto const speedmultiplier = (
|
||||||
|
( ( Type == tp_Free ) && ( Command.command == user_command::movehorizontalfast ) ) ?
|
||||||
|
30.0 :
|
||||||
|
1.0 );
|
||||||
|
|
||||||
// left-right
|
// left-right
|
||||||
double const movex = reinterpret_cast<double const &>( Command.param1 );
|
auto const movexparam { reinterpret_cast<double const &>( Command.param1 ) };
|
||||||
if( movex > 0.0 ) {
|
|
||||||
m_keys.right = true;
|
|
||||||
m_keys.left = false;
|
|
||||||
}
|
|
||||||
else if( movex < 0.0 ) {
|
|
||||||
m_keys.right = false;
|
|
||||||
m_keys.left = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.right = false;
|
|
||||||
m_keys.left = false;
|
|
||||||
}
|
|
||||||
// 2/3rd of the stick range enables walk speed, past that we lerp between walk and run speed
|
// 2/3rd of the stick range enables walk speed, past that we lerp between walk and run speed
|
||||||
m_moverate.x =
|
auto const movex { walkspeed + ( std::max( 0.0, std::abs( movexparam ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed ) };
|
||||||
walkspeed
|
|
||||||
+ ( std::max( 0.0, std::abs( movex ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed );
|
m_moverate.x = (
|
||||||
|
movexparam > 0.0 ? movex * speedmultiplier :
|
||||||
|
movexparam < 0.0 ? -movex * speedmultiplier :
|
||||||
|
0.0 );
|
||||||
|
|
||||||
// forward-back
|
// forward-back
|
||||||
double const movez = reinterpret_cast<double const &>( Command.param2 );
|
double const movezparam { reinterpret_cast<double const &>( Command.param2 ) };
|
||||||
if( movez > 0.0 ) {
|
auto const movez { walkspeed + ( std::max( 0.0, std::abs( movezparam ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed ) };
|
||||||
m_keys.forward = true;
|
// NOTE: z-axis is flipped given world coordinate system
|
||||||
m_keys.back = false;
|
m_moverate.z = (
|
||||||
}
|
movezparam > 0.0 ? -movez * speedmultiplier :
|
||||||
else if( movez < 0.0 ) {
|
movezparam < 0.0 ? movez * speedmultiplier :
|
||||||
m_keys.forward = false;
|
0.0 );
|
||||||
m_keys.back = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.forward = false;
|
|
||||||
m_keys.back = false;
|
|
||||||
}
|
|
||||||
m_moverate.z =
|
|
||||||
walkspeed
|
|
||||||
+ ( std::max( 0.0, std::abs( movez ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case user_command::moveforward: {
|
case user_command::movevertical:
|
||||||
|
case user_command::moveverticalfast: {
|
||||||
|
|
||||||
|
auto const movespeed = (
|
||||||
|
Type == tp_Free ? runspeed * 0.5 :
|
||||||
|
Type == tp_Follow ? walkspeed :
|
||||||
|
0.0 );
|
||||||
|
|
||||||
|
auto const speedmultiplier = (
|
||||||
|
( ( Type == tp_Free ) && ( Command.command == user_command::moveverticalfast ) ) ?
|
||||||
|
10.0 :
|
||||||
|
1.0 );
|
||||||
|
|
||||||
|
// up-down
|
||||||
|
auto const moveyparam { reinterpret_cast<double const &>( Command.param1 ) };
|
||||||
|
// 2/3rd of the stick range enables walk speed, past that we lerp between walk and run speed
|
||||||
|
auto const movey { walkspeed + ( std::max( 0.0, std::abs( moveyparam ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed ) };
|
||||||
|
|
||||||
|
m_moverate.y = (
|
||||||
|
moveyparam > 0.0 ? movey * speedmultiplier :
|
||||||
|
moveyparam < 0.0 ? -movey * speedmultiplier :
|
||||||
|
0.0 );
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.forward = true;
|
|
||||||
m_moverate.z =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
walkspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.forward = false;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} // switch
|
||||||
case user_command::moveback: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.back = true;
|
|
||||||
m_moverate.z =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
walkspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.back = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::moveleft: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.left = true;
|
|
||||||
m_moverate.x =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
walkspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.left = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::moveright: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.right = true;
|
|
||||||
m_moverate.x =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
walkspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.right = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::moveup: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.up = true;
|
|
||||||
m_moverate.y =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
walkspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.up = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::movedown: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.down = true;
|
|
||||||
m_moverate.y =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
walkspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.down = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::moveforwardfast: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.forward = true;
|
|
||||||
m_moverate.z =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
runspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.forward = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::movebackfast: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.back = true;
|
|
||||||
m_moverate.z =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
runspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.back = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::moveleftfast: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.left = true;
|
|
||||||
m_moverate.x =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
runspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.left = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::moverightfast: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.right = true;
|
|
||||||
m_moverate.x =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
runspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.right = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::moveupfast: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.up = true;
|
|
||||||
m_moverate.y =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
runspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.up = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case user_command::movedownfast: {
|
|
||||||
|
|
||||||
if( Command.action != GLFW_RELEASE ) {
|
|
||||||
m_keys.down = true;
|
|
||||||
m_moverate.y =
|
|
||||||
( Type == tp_Free ?
|
|
||||||
runspeed * speedmultiplier :
|
|
||||||
walkspeed );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_keys.down = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCamera::Update()
|
void TCamera::Update()
|
||||||
@@ -309,61 +143,15 @@ void TCamera::Update()
|
|||||||
|
|
||||||
auto const deltatime = Timer::GetDeltaRenderTime(); // czas bez pauzy
|
auto const deltatime = Timer::GetDeltaRenderTime(); // czas bez pauzy
|
||||||
|
|
||||||
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
|
|
||||||
double a = 0.8; // default (walk) movement speed
|
|
||||||
if( Type == tp_Free ) {
|
|
||||||
// when not in the cab the speed modifiers are active
|
|
||||||
if( Global::shiftState ) { a = 2.5; }
|
|
||||||
if( Global::ctrlState ) { a *= 10.0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
if( ( Type == tp_Free )
|
|
||||||
|| ( false == Global::ctrlState ) ) {
|
|
||||||
// ctrl is used for mirror view, so we ignore the controls when in vehicle if ctrl is pressed
|
|
||||||
if( Console::Pressed( Global::Keys[ k_MechUp ] ) )
|
|
||||||
Velocity.y = clamp( Velocity.y + a * 10.0 * deltatime, -a, a );
|
|
||||||
if( Console::Pressed( Global::Keys[ k_MechDown ] ) )
|
|
||||||
Velocity.y = clamp( Velocity.y - a * 10.0 * deltatime, -a, a );
|
|
||||||
|
|
||||||
// McZapkie-170402: poruszanie i rozgladanie we free takie samo jak w follow
|
|
||||||
if( Console::Pressed( Global::Keys[ k_MechRight ] ) )
|
|
||||||
Velocity.x = clamp( Velocity.x + a * 10.0 * deltatime, -a, a );
|
|
||||||
if( Console::Pressed( Global::Keys[ k_MechLeft ] ) )
|
|
||||||
Velocity.x = clamp( Velocity.x - a * 10.0 * deltatime, -a, a );
|
|
||||||
if( Console::Pressed( Global::Keys[ k_MechForward ] ) )
|
|
||||||
Velocity.z = clamp( Velocity.z - a * 10.0 * deltatime, -a, a );
|
|
||||||
if( Console::Pressed( Global::Keys[ k_MechBackward ] ) )
|
|
||||||
Velocity.z = clamp( Velocity.z + a * 10.0 * deltatime, -a, a );
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
m_moverate = 0.8; // default (walk) movement speed
|
|
||||||
if( Type == tp_Free ) {
|
|
||||||
// when not in the cab the speed modifiers are active
|
|
||||||
if( Global::shiftState ) { m_moverate = 2.5; }
|
|
||||||
if( Global::ctrlState ) { m_moverate *= 10.0; }
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if( ( Type == tp_Free )
|
if( ( Type == tp_Free )
|
||||||
|| ( false == Global::ctrlState )
|
|| ( false == Global::ctrlState )
|
||||||
|| ( true == DebugCameraFlag) ) {
|
|| ( true == DebugCameraFlag ) ) {
|
||||||
// ctrl is used for mirror view, so we ignore the controls when in vehicle if ctrl is pressed
|
// ctrl is used for mirror view, so we ignore the controls when in vehicle if ctrl is pressed
|
||||||
if( m_keys.up )
|
|
||||||
Velocity.y = clamp( Velocity.y + m_moverate.y * 10.0 * deltatime, -m_moverate.y, m_moverate.y );
|
|
||||||
if( m_keys.down )
|
|
||||||
Velocity.y = clamp( Velocity.y - m_moverate.y * 10.0 * deltatime, -m_moverate.y, m_moverate.y );
|
|
||||||
|
|
||||||
// McZapkie-170402: poruszanie i rozgladanie we free takie samo jak w follow
|
// McZapkie-170402: poruszanie i rozgladanie we free takie samo jak w follow
|
||||||
if( m_keys.right )
|
Velocity.x = clamp( Velocity.x + m_moverate.x * 10.0 * deltatime, -m_moverate.x, m_moverate.x );
|
||||||
Velocity.x = clamp( Velocity.x + m_moverate.x * 10.0 * deltatime, -m_moverate.x, m_moverate.x );
|
Velocity.z = clamp( Velocity.z + m_moverate.z * 10.0 * deltatime, -m_moverate.z, m_moverate.z );
|
||||||
if( m_keys.left )
|
Velocity.y = clamp( Velocity.y + m_moverate.y * 10.0 * deltatime, -m_moverate.y, m_moverate.y );
|
||||||
Velocity.x = clamp( Velocity.x - m_moverate.x * 10.0 * deltatime, -m_moverate.x, m_moverate.x );
|
|
||||||
if( m_keys.forward )
|
|
||||||
Velocity.z = clamp( Velocity.z - m_moverate.z * 10.0 * deltatime, -m_moverate.z, m_moverate.z );
|
|
||||||
if( m_keys.back )
|
|
||||||
Velocity.z = clamp( Velocity.z + m_moverate.z * 10.0 * deltatime, -m_moverate.z, m_moverate.z );
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if( ( Type == tp_Free )
|
if( ( Type == tp_Free )
|
||||||
|| ( true == DebugCameraFlag ) ) {
|
|| ( true == DebugCameraFlag ) ) {
|
||||||
|
|||||||
9
Camera.h
9
Camera.h
@@ -26,15 +26,6 @@ enum TCameraType
|
|||||||
class TCamera
|
class TCamera
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
struct keys {
|
|
||||||
bool forward{ false };
|
|
||||||
bool back{ false };
|
|
||||||
bool left{ false };
|
|
||||||
bool right{ false };
|
|
||||||
bool up{ false };
|
|
||||||
bool down{ false };
|
|
||||||
bool run{ false };
|
|
||||||
} m_keys;
|
|
||||||
glm::dvec3 m_moverate;
|
glm::dvec3 m_moverate;
|
||||||
|
|
||||||
public: // McZapkie: potrzebuje do kiwania na boki
|
public: // McZapkie: potrzebuje do kiwania na boki
|
||||||
|
|||||||
@@ -3493,7 +3493,7 @@ void TDynamicObject::RenderSounds() {
|
|||||||
if( MoverParameters->ConverterFlag ) {
|
if( MoverParameters->ConverterFlag ) {
|
||||||
frequency = (
|
frequency = (
|
||||||
MoverParameters->EngineType == ElectricSeriesMotor ?
|
MoverParameters->EngineType == ElectricSeriesMotor ?
|
||||||
MoverParameters->Voltage / ( MoverParameters->NominalVoltage * MoverParameters->RList[ MoverParameters->RlistSize ].Mn ) :
|
( MoverParameters->RunningTraction.TractionVoltage / MoverParameters->NominalVoltage ) * MoverParameters->RList[ MoverParameters->RlistSize ].Mn :
|
||||||
1.0 );
|
1.0 );
|
||||||
frequency = sConverter.m_frequencyoffset + sConverter.m_frequencyfactor * frequency;
|
frequency = sConverter.m_frequencyoffset + sConverter.m_frequencyfactor * frequency;
|
||||||
sConverter
|
sConverter
|
||||||
|
|||||||
@@ -3744,12 +3744,12 @@ void TMoverParameters::ComputeTotalForce(double dt, double dt1, bool FullVer)
|
|||||||
|| ( ( Couplers[ side::rear ].CouplingFlag & ctrain_power ) == ctrain_power ) ) ) {
|
|| ( ( Couplers[ side::rear ].CouplingFlag & ctrain_power ) == ctrain_power ) ) ) {
|
||||||
// potem ulepszyc! pantogtrafy!
|
// potem ulepszyc! pantogtrafy!
|
||||||
Voltage =
|
Voltage =
|
||||||
std::max(
|
std::max(
|
||||||
RunningTraction.TractionVoltage,
|
RunningTraction.TractionVoltage,
|
||||||
#ifdef EU07_USE_OLD_HVCOUPLERS
|
#ifdef EU07_USE_OLD_HVCOUPLERS
|
||||||
std::max( HVCouplers[side::front][hvcoupler::voltage], HVCouplers[side::rear][hvcoupler::voltage] ) );
|
std::max( HVCouplers[side::front][hvcoupler::voltage], HVCouplers[side::rear][hvcoupler::voltage] ) );
|
||||||
#else
|
#else
|
||||||
std::max( Couplers[ side::front ].power_high.voltage, Couplers[ side::rear ].power_high.voltage ) );
|
std::max( Couplers[ side::front ].power_high.voltage, Couplers[ side::rear ].power_high.voltage ) );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
11
command.cpp
11
command.cpp
@@ -70,19 +70,16 @@ commanddescription_sequence Commands_descriptions = {
|
|||||||
const int k_FailedEngineCutOff = 35;
|
const int k_FailedEngineCutOff = 35;
|
||||||
*/
|
*/
|
||||||
{ "viewturn", command_target::entity },
|
{ "viewturn", command_target::entity },
|
||||||
{ "movevector", command_target::entity },
|
{ "movehorizontal", command_target::entity },
|
||||||
|
{ "movehorizontalfast", command_target::entity },
|
||||||
|
{ "movevertical", command_target::entity },
|
||||||
|
{ "moveverticalfast", command_target::entity },
|
||||||
{ "moveleft", command_target::entity },
|
{ "moveleft", command_target::entity },
|
||||||
{ "moveright", command_target::entity },
|
{ "moveright", command_target::entity },
|
||||||
{ "moveforward", command_target::entity },
|
{ "moveforward", command_target::entity },
|
||||||
{ "moveback", command_target::entity },
|
{ "moveback", command_target::entity },
|
||||||
{ "moveup", command_target::entity },
|
{ "moveup", command_target::entity },
|
||||||
{ "movedown", command_target::entity },
|
{ "movedown", command_target::entity },
|
||||||
{ "moveleftfast", command_target::entity },
|
|
||||||
{ "moverightfast", command_target::entity },
|
|
||||||
{ "moveforwardfast", command_target::entity },
|
|
||||||
{ "movebackfast", command_target::entity },
|
|
||||||
{ "moveupfast", command_target::entity },
|
|
||||||
{ "movedownfast", command_target::entity },
|
|
||||||
/*
|
/*
|
||||||
const int k_CabForward = 42;
|
const int k_CabForward = 42;
|
||||||
const int k_CabBackward = 43;
|
const int k_CabBackward = 43;
|
||||||
|
|||||||
11
command.h
11
command.h
@@ -65,19 +65,16 @@ enum class user_command {
|
|||||||
const int k_FailedEngineCutOff = 35;
|
const int k_FailedEngineCutOff = 35;
|
||||||
*/
|
*/
|
||||||
viewturn,
|
viewturn,
|
||||||
movevector,
|
movehorizontal,
|
||||||
|
movehorizontalfast,
|
||||||
|
movevertical,
|
||||||
|
moveverticalfast,
|
||||||
moveleft,
|
moveleft,
|
||||||
moveright,
|
moveright,
|
||||||
moveforward,
|
moveforward,
|
||||||
moveback,
|
moveback,
|
||||||
moveup,
|
moveup,
|
||||||
movedown,
|
movedown,
|
||||||
moveleftfast,
|
|
||||||
moverightfast,
|
|
||||||
moveforwardfast,
|
|
||||||
movebackfast,
|
|
||||||
moveupfast,
|
|
||||||
movedownfast,
|
|
||||||
/*
|
/*
|
||||||
const int k_CabForward = 42;
|
const int k_CabForward = 42;
|
||||||
const int k_CabBackward = 43;
|
const int k_CabBackward = 43;
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ gamepad_input::process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, g
|
|||||||
double const movex = static_cast<double>( Leftstick.x );
|
double const movex = static_cast<double>( Leftstick.x );
|
||||||
double const movez = static_cast<double>( Leftstick.y );
|
double const movez = static_cast<double>( Leftstick.y );
|
||||||
m_relay.post(
|
m_relay.post(
|
||||||
user_command::movevector,
|
user_command::movehorizontal,
|
||||||
reinterpret_cast<std::uint64_t const &>( movex ),
|
reinterpret_cast<std::uint64_t const &>( movex ),
|
||||||
reinterpret_cast<std::uint64_t const &>( movez ),
|
reinterpret_cast<std::uint64_t const &>( movez ),
|
||||||
GLFW_PRESS,
|
GLFW_PRESS,
|
||||||
@@ -231,42 +231,6 @@ gamepad_input::process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, g
|
|||||||
m_triggers = Triggers;
|
m_triggers = Triggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
gamepad_input::process_axis( float const Value, float const Previousvalue, float const Multiplier, user_command Command, std::uint16_t const Recipient ) {
|
|
||||||
|
|
||||||
process_axis( Value, Previousvalue, Multiplier, Command, Command, Recipient );
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gamepad_input::process_axis( float const Value, float const Previousvalue, float const Multiplier, user_command Command1, user_command Command2, std::uint16_t const Recipient ) {
|
|
||||||
|
|
||||||
user_command command{ Command1 };
|
|
||||||
if( Value * Multiplier > 0.9 ) {
|
|
||||||
command = Command2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Value * Multiplier > 0.0f ) {
|
|
||||||
|
|
||||||
m_relay.post(
|
|
||||||
command,
|
|
||||||
0, 0,
|
|
||||||
GLFW_PRESS,
|
|
||||||
Recipient
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// if we had movement before but not now, report this as 'button' release
|
|
||||||
if( Previousvalue != 0.0f ) {
|
|
||||||
m_relay.post(
|
|
||||||
command, // doesn't matter which movement 'mode' we report
|
|
||||||
0, 0,
|
|
||||||
GLFW_RELEASE,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gamepad_input::process_mode( float const Value, std::uint16_t const Recipient ) {
|
gamepad_input::process_mode( float const Value, std::uint16_t const Recipient ) {
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ private:
|
|||||||
// methods
|
// methods
|
||||||
void on_button( gamepad_button const Button, int const Action );
|
void on_button( gamepad_button const Button, int const Action );
|
||||||
void process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, glm::vec2 const &Triggers );
|
void process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, glm::vec2 const &Triggers );
|
||||||
void process_axis( float const Value, float const Previousvalue, float const Multiplier, user_command Command, std::uint16_t const Recipient );
|
|
||||||
void process_axis( float const Value, float const Previousvalue, float const Multiplier, user_command Command1, user_command Command2, /*user_command Command3,*/ std::uint16_t const Recipient );
|
|
||||||
void process_mode( float const Value, std::uint16_t const Recipient );
|
void process_mode( float const Value, std::uint16_t const Recipient );
|
||||||
|
|
||||||
// members
|
// members
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "keyboardinput.h"
|
#include "keyboardinput.h"
|
||||||
|
#include "globals.h"
|
||||||
#include "logs.h"
|
#include "logs.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
@@ -131,16 +132,16 @@ keyboard_input::key( int const Key, int const Action ) {
|
|||||||
return false;
|
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
|
// store key state
|
||||||
if( Key != -1 ) {
|
if( Key != -1 ) {
|
||||||
m_keys[ Key ] = Action;
|
m_keys[ Key ] = Action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
// include active modifiers for currently pressed key, except if the key is a modifier itself
|
// include active modifiers for currently pressed key, except if the key is a modifier itself
|
||||||
auto const key =
|
auto const key =
|
||||||
Key
|
Key
|
||||||
@@ -260,7 +261,13 @@ keyboard_input::default_bindings() {
|
|||||||
{ GLFW_KEY_R | keymodifier::shift | keymodifier::control },
|
{ GLFW_KEY_R | keymodifier::shift | keymodifier::control },
|
||||||
// viewturn
|
// viewturn
|
||||||
{ -1 },
|
{ -1 },
|
||||||
// movevector
|
// movehorizontal
|
||||||
|
{ -1 },
|
||||||
|
// movehorizontalfast
|
||||||
|
{ -1 },
|
||||||
|
// movevertical
|
||||||
|
{ -1 },
|
||||||
|
// moveverticalfast
|
||||||
{ -1 },
|
{ -1 },
|
||||||
// moveleft
|
// moveleft
|
||||||
{ GLFW_KEY_LEFT },
|
{ GLFW_KEY_LEFT },
|
||||||
@@ -274,18 +281,6 @@ keyboard_input::default_bindings() {
|
|||||||
{ GLFW_KEY_PAGE_UP },
|
{ GLFW_KEY_PAGE_UP },
|
||||||
// movedown
|
// movedown
|
||||||
{ GLFW_KEY_PAGE_DOWN },
|
{ GLFW_KEY_PAGE_DOWN },
|
||||||
// moveleftfast
|
|
||||||
{ -1 },
|
|
||||||
// moverightfast
|
|
||||||
{ -1 },
|
|
||||||
// moveforwardfast
|
|
||||||
{ -1 },
|
|
||||||
// movebackfast
|
|
||||||
{ -1 },
|
|
||||||
// moveupfast
|
|
||||||
{ -1 },
|
|
||||||
// movedownfast
|
|
||||||
{ -1 },
|
|
||||||
/*
|
/*
|
||||||
const int k_CabForward = 42;
|
const int k_CabForward = 42;
|
||||||
const int k_CabBackward = 43;
|
const int k_CabBackward = 43;
|
||||||
@@ -422,10 +417,7 @@ keyboard_input::bind() {
|
|||||||
bool
|
bool
|
||||||
keyboard_input::update_movement( int const Key, int const Action ) {
|
keyboard_input::update_movement( int const Key, int const Action ) {
|
||||||
|
|
||||||
bool shift =
|
bool const movementkey =
|
||||||
( ( Key == GLFW_KEY_LEFT_SHIFT )
|
|
||||||
|| ( Key == GLFW_KEY_RIGHT_SHIFT ) );
|
|
||||||
bool movementkey =
|
|
||||||
( ( Key == m_bindingscache.forward )
|
( ( Key == m_bindingscache.forward )
|
||||||
|| ( Key == m_bindingscache.back )
|
|| ( Key == m_bindingscache.back )
|
||||||
|| ( Key == m_bindingscache.left )
|
|| ( Key == m_bindingscache.left )
|
||||||
@@ -433,93 +425,61 @@ keyboard_input::update_movement( int const Key, int const Action ) {
|
|||||||
|| ( Key == m_bindingscache.up )
|
|| ( Key == m_bindingscache.up )
|
||||||
|| ( Key == m_bindingscache.down ) );
|
|| ( Key == m_bindingscache.down ) );
|
||||||
|
|
||||||
if( false == ( shift || movementkey ) ) { return false; }
|
return ( true == movementkey );
|
||||||
|
}
|
||||||
|
|
||||||
if( false == shift ) {
|
void
|
||||||
// TODO: pass correct entity id once the missing systems are in place
|
keyboard_input::poll() {
|
||||||
if( Key == m_bindingscache.forward ) {
|
|
||||||
m_keys[ Key ] = Action;
|
glm::vec2 const movementhorizontal {
|
||||||
m_relay.post(
|
// x-axis
|
||||||
( m_shift ?
|
( Global::shiftState ? 1.f : 0.5f ) *
|
||||||
user_command::moveforwardfast :
|
( m_keys[ m_bindingscache.left ] != GLFW_RELEASE ? -1.f :
|
||||||
user_command::moveforward ),
|
m_keys[ m_bindingscache.right ] != GLFW_RELEASE ? 1.f :
|
||||||
0, 0,
|
0.f ),
|
||||||
m_keys[ m_bindingscache.forward ],
|
// z-axis
|
||||||
0 );
|
( Global::shiftState ? 1.f : 0.5f ) *
|
||||||
return true;
|
( m_keys[ m_bindingscache.forward ] != GLFW_RELEASE ? 1.f :
|
||||||
}
|
m_keys[ m_bindingscache.back ] != GLFW_RELEASE ? -1.f :
|
||||||
else if( Key == m_bindingscache.back ) {
|
0.f ) };
|
||||||
m_keys[ Key ] = Action;
|
|
||||||
m_relay.post(
|
if( ( movementhorizontal.x != 0.f || movementhorizontal.y != 0.f )
|
||||||
( m_shift ?
|
|| ( m_movementhorizontal.x != 0.f || m_movementhorizontal.y != 0.f ) ) {
|
||||||
user_command::movebackfast :
|
double const movexparam = static_cast<double>( movementhorizontal.x );
|
||||||
user_command::moveback ),
|
double const movezparam = static_cast<double>( movementhorizontal.y );
|
||||||
0, 0,
|
m_relay.post(
|
||||||
m_keys[ m_bindingscache.back ],
|
( true == Global::ctrlState ?
|
||||||
0 );
|
user_command::movehorizontalfast :
|
||||||
return true;
|
user_command::movehorizontal ),
|
||||||
}
|
reinterpret_cast<std::uint64_t const &>( movexparam ),
|
||||||
else if( Key == m_bindingscache.left ) {
|
reinterpret_cast<std::uint64_t const &>( movezparam ),
|
||||||
m_keys[ Key ] = Action;
|
GLFW_PRESS,
|
||||||
m_relay.post(
|
0 );
|
||||||
( 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;
|
m_movementhorizontal = movementhorizontal;
|
||||||
|
|
||||||
|
float const movementvertical {
|
||||||
|
// y-axis
|
||||||
|
( Global::shiftState ? 1.f : 0.5f ) *
|
||||||
|
( m_keys[ m_bindingscache.up ] != GLFW_RELEASE ? 1.f :
|
||||||
|
m_keys[ m_bindingscache.down ] != GLFW_RELEASE ? -1.f :
|
||||||
|
0.f ) };
|
||||||
|
|
||||||
|
if( ( movementvertical != 0.f )
|
||||||
|
|| ( m_movementvertical != 0.f ) ) {
|
||||||
|
double const moveyparam = static_cast<double>( movementvertical );
|
||||||
|
m_relay.post(
|
||||||
|
( true == Global::ctrlState ?
|
||||||
|
user_command::moveverticalfast :
|
||||||
|
user_command::movevertical ),
|
||||||
|
reinterpret_cast<std::uint64_t const &>( moveyparam ),
|
||||||
|
0,
|
||||||
|
GLFW_PRESS,
|
||||||
|
0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_movementvertical = movementvertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public:
|
|||||||
bool
|
bool
|
||||||
key( int const Key, int const Action );
|
key( int const Key, int const Action );
|
||||||
void
|
void
|
||||||
poll() {}
|
poll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// types
|
// types
|
||||||
@@ -70,6 +70,8 @@ private:
|
|||||||
bool m_shift{ false };
|
bool m_shift{ false };
|
||||||
bool m_ctrl{ false };
|
bool m_ctrl{ false };
|
||||||
bindings_cache m_bindingscache;
|
bindings_cache m_bindingscache;
|
||||||
|
glm::vec2 m_movementhorizontal;
|
||||||
|
float m_movementvertical;
|
||||||
std::array<char, GLFW_KEY_LAST + 1> m_keys;
|
std::array<char, GLFW_KEY_LAST + 1> m_keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user