16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 22:39:18 +02:00

restored support for second movement speed control key, converter sound frequency calculation fix

This commit is contained in:
tmj-fstate
2018-01-07 23:09:05 +01:00
parent 8d3d50d218
commit 724ed1693e
10 changed files with 138 additions and 441 deletions

View File

@@ -49,9 +49,8 @@ void TCamera::OnCursorMove(double x, double y)
void
TCamera::OnCommand( command_data const &Command ) {
double const walkspeed = 1.0;
double const runspeed = ( DebugModeFlag ? 50.0 : 7.5 );
double const speedmultiplier = ( DebugModeFlag ? 7.5 : 1.0 );
auto const walkspeed { 1.0 };
auto const runspeed { 7.5 };
switch( Command.command ) {
@@ -63,232 +62,67 @@ TCamera::OnCommand( command_data const &Command ) {
break;
}
case user_command::movevector: {
case user_command::movehorizontal:
case user_command::movehorizontalfast: {
auto const movespeed =
( Type == tp_Free ?
runspeed * speedmultiplier :
walkspeed );
auto const movespeed = (
Type == tp_Free ? runspeed :
Type == tp_Follow ? walkspeed :
0.0 );
auto const speedmultiplier = (
( ( Type == tp_Free ) && ( Command.command == user_command::movehorizontalfast ) ) ?
30.0 :
1.0 );
// left-right
double const movex = 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;
}
auto const movexparam { reinterpret_cast<double const &>( Command.param1 ) };
// 2/3rd of the stick range enables walk speed, past that we lerp between walk and run speed
m_moverate.x =
walkspeed
+ ( std::max( 0.0, std::abs( movex ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed );
auto const movex { walkspeed + ( std::max( 0.0, std::abs( movexparam ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed ) };
m_moverate.x = (
movexparam > 0.0 ? movex * speedmultiplier :
movexparam < 0.0 ? -movex * speedmultiplier :
0.0 );
// forward-back
double const movez = reinterpret_cast<double const &>( Command.param2 );
if( movez > 0.0 ) {
m_keys.forward = true;
m_keys.back = false;
}
else if( movez < 0.0 ) {
m_keys.forward = false;
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 );
double const movezparam { reinterpret_cast<double const &>( Command.param2 ) };
auto const movez { walkspeed + ( std::max( 0.0, std::abs( movezparam ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed ) };
// NOTE: z-axis is flipped given world coordinate system
m_moverate.z = (
movezparam > 0.0 ? -movez * speedmultiplier :
movezparam < 0.0 ? movez * speedmultiplier :
0.0 );
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;
}
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;
}
}
} // switch
}
void TCamera::Update()
@@ -309,61 +143,15 @@ void TCamera::Update()
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 )
|| ( 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
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
if( m_keys.right )
Velocity.x = clamp( Velocity.x + m_moverate.x * 10.0 * deltatime, -m_moverate.x, m_moverate.x );
if( m_keys.left )
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 );
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 );
Velocity.y = clamp( Velocity.y + m_moverate.y * 10.0 * deltatime, -m_moverate.y, m_moverate.y );
}
#endif
if( ( Type == tp_Free )
|| ( true == DebugCameraFlag ) ) {

View File

@@ -26,15 +26,6 @@ enum TCameraType
class TCamera
{
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;
public: // McZapkie: potrzebuje do kiwania na boki

View File

@@ -3493,7 +3493,7 @@ void TDynamicObject::RenderSounds() {
if( MoverParameters->ConverterFlag ) {
frequency = (
MoverParameters->EngineType == ElectricSeriesMotor ?
MoverParameters->Voltage / ( MoverParameters->NominalVoltage * MoverParameters->RList[ MoverParameters->RlistSize ].Mn ) :
( MoverParameters->RunningTraction.TractionVoltage / MoverParameters->NominalVoltage ) * MoverParameters->RList[ MoverParameters->RlistSize ].Mn :
1.0 );
frequency = sConverter.m_frequencyoffset + sConverter.m_frequencyfactor * frequency;
sConverter

View File

@@ -3744,12 +3744,12 @@ void TMoverParameters::ComputeTotalForce(double dt, double dt1, bool FullVer)
|| ( ( Couplers[ side::rear ].CouplingFlag & ctrain_power ) == ctrain_power ) ) ) {
// potem ulepszyc! pantogtrafy!
Voltage =
std::max(
RunningTraction.TractionVoltage,
std::max(
RunningTraction.TractionVoltage,
#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
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
}
else {

View File

@@ -70,19 +70,16 @@ commanddescription_sequence Commands_descriptions = {
const int k_FailedEngineCutOff = 35;
*/
{ "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 },
{ "moveright", command_target::entity },
{ "moveforward", command_target::entity },
{ "moveback", command_target::entity },
{ "moveup", 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_CabBackward = 43;

View File

@@ -65,19 +65,16 @@ enum class user_command {
const int k_FailedEngineCutOff = 35;
*/
viewturn,
movevector,
movehorizontal,
movehorizontalfast,
movevertical,
moveverticalfast,
moveleft,
moveright,
moveforward,
moveback,
moveup,
movedown,
moveleftfast,
moverightfast,
moveforwardfast,
movebackfast,
moveupfast,
movedownfast,
/*
const int k_CabForward = 42;
const int k_CabBackward = 43;

View File

@@ -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 movez = static_cast<double>( Leftstick.y );
m_relay.post(
user_command::movevector,
user_command::movehorizontal,
reinterpret_cast<std::uint64_t const &>( movex ),
reinterpret_cast<std::uint64_t const &>( movez ),
GLFW_PRESS,
@@ -231,42 +231,6 @@ gamepad_input::process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, g
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
gamepad_input::process_mode( float const Value, std::uint16_t const Recipient ) {

View File

@@ -65,8 +65,6 @@ private:
// methods
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_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 );
// members

View File

@@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "keyboardinput.h"
#include "globals.h"
#include "logs.h"
#include "parser.h"
#include "world.h"
@@ -131,16 +132,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;
}
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
auto const key =
Key
@@ -260,7 +261,13 @@ keyboard_input::default_bindings() {
{ GLFW_KEY_R | keymodifier::shift | keymodifier::control },
// viewturn
{ -1 },
// movevector
// movehorizontal
{ -1 },
// movehorizontalfast
{ -1 },
// movevertical
{ -1 },
// moveverticalfast
{ -1 },
// moveleft
{ GLFW_KEY_LEFT },
@@ -274,18 +281,6 @@ keyboard_input::default_bindings() {
{ GLFW_KEY_PAGE_UP },
// movedown
{ GLFW_KEY_PAGE_DOWN },
// moveleftfast
{ -1 },
// moverightfast
{ -1 },
// moveforwardfast
{ -1 },
// movebackfast
{ -1 },
// moveupfast
{ -1 },
// movedownfast
{ -1 },
/*
const int k_CabForward = 42;
const int k_CabBackward = 43;
@@ -422,10 +417,7 @@ keyboard_input::bind() {
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 =
bool const movementkey =
( ( Key == m_bindingscache.forward )
|| ( Key == m_bindingscache.back )
|| ( 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.down ) );
if( false == ( shift || movementkey ) ) { return false; }
return ( true == movementkey );
}
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 ] ); }
void
keyboard_input::poll() {
glm::vec2 const movementhorizontal {
// x-axis
( Global::shiftState ? 1.f : 0.5f ) *
( m_keys[ m_bindingscache.left ] != GLFW_RELEASE ? -1.f :
m_keys[ m_bindingscache.right ] != GLFW_RELEASE ? 1.f :
0.f ),
// z-axis
( Global::shiftState ? 1.f : 0.5f ) *
( m_keys[ m_bindingscache.forward ] != GLFW_RELEASE ? 1.f :
m_keys[ m_bindingscache.back ] != GLFW_RELEASE ? -1.f :
0.f ) };
if( ( movementhorizontal.x != 0.f || movementhorizontal.y != 0.f )
|| ( m_movementhorizontal.x != 0.f || m_movementhorizontal.y != 0.f ) ) {
double const movexparam = static_cast<double>( movementhorizontal.x );
double const movezparam = static_cast<double>( movementhorizontal.y );
m_relay.post(
( true == Global::ctrlState ?
user_command::movehorizontalfast :
user_command::movehorizontal ),
reinterpret_cast<std::uint64_t const &>( movexparam ),
reinterpret_cast<std::uint64_t const &>( movezparam ),
GLFW_PRESS,
0 );
}
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;
}
//---------------------------------------------------------------------------

View File

@@ -27,7 +27,7 @@ public:
bool
key( int const Key, int const Action );
void
poll() {}
poll();
private:
// types
@@ -70,6 +70,8 @@ private:
bool m_shift{ false };
bool m_ctrl{ false };
bindings_cache m_bindingscache;
glm::vec2 m_movementhorizontal;
float m_movementvertical;
std::array<char, GLFW_KEY_LAST + 1> m_keys;
};