mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
maintenance: minor code cleanup
This commit is contained in:
30
Camera.cpp
30
Camera.cpp
@@ -31,27 +31,29 @@ void TCamera::Init(vector3 NPos, vector3 NAngle)
|
||||
Type = (Global::bFreeFly ? tp_Free : tp_Follow);
|
||||
};
|
||||
|
||||
void TCamera::OnCursorMove(double x, double y)
|
||||
{
|
||||
// McZapkie-170402: zeby mysz dzialala zawsze if (Type==tp_Follow)
|
||||
void TCamera::OnCursorMove(double x, double y) {
|
||||
|
||||
Yaw -= x;
|
||||
Pitch -= y;
|
||||
if (Yaw > M_PI)
|
||||
while( Yaw > M_PI ) {
|
||||
Yaw -= 2 * M_PI;
|
||||
else if (Yaw < -M_PI)
|
||||
}
|
||||
while( Yaw < -M_PI ) {
|
||||
Yaw += 2 * M_PI;
|
||||
if (Type == tp_Follow) // jeżeli jazda z pojazdem
|
||||
{
|
||||
clamp(Pitch, -M_PI_4, M_PI_4); // ograniczenie kąta spoglądania w dół i w górę
|
||||
}
|
||||
Pitch -= y;
|
||||
if (Type == tp_Follow) {
|
||||
// jeżeli jazda z pojazdem ograniczenie kąta spoglądania w dół i w górę
|
||||
Pitch = clamp( Pitch, -M_PI_4, M_PI_4 );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
TCamera::OnCommand( command_data const &Command ) {
|
||||
|
||||
auto const walkspeed { 1.0 };
|
||||
auto const runspeed { 7.5 };
|
||||
|
||||
bool iscameracommand { true };
|
||||
switch( Command.command ) {
|
||||
|
||||
case user_command::viewturn: {
|
||||
@@ -122,7 +124,15 @@ TCamera::OnCommand( command_data const &Command ) {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
iscameracommand = false;
|
||||
break;
|
||||
}
|
||||
} // switch
|
||||
|
||||
return iscameracommand;
|
||||
}
|
||||
|
||||
void TCamera::Update()
|
||||
|
||||
2
Camera.h
2
Camera.h
@@ -42,7 +42,7 @@ class TCamera
|
||||
void Reset() {
|
||||
Pitch = Yaw = Roll = 0; };
|
||||
void OnCursorMove(double const x, double const y);
|
||||
void OnCommand( command_data const &Command );
|
||||
bool OnCommand( command_data const &Command );
|
||||
void Update();
|
||||
vector3 GetDirection();
|
||||
bool SetMatrix(glm::dmat4 &Matrix);
|
||||
|
||||
@@ -7598,6 +7598,11 @@ void TMoverParameters::LoadFIZ_DList( std::string const &Input ) {
|
||||
extract_value( dizel_nmax, "nmax", Input, "" );
|
||||
extract_value( dizel_nominalfill, "nominalfill", Input, "" );
|
||||
extract_value( dizel_Mstand, "Mstand", Input, "" );
|
||||
|
||||
if( dizel_nMmax == dizel_nmax ) {
|
||||
// HACK: guard against cases where nMmax == nmax, leading to division by 0 in momentum calculation
|
||||
dizel_nMmax = dizel_nmax - 1.0 / 60.0;
|
||||
}
|
||||
}
|
||||
|
||||
void TMoverParameters::LoadFIZ_FFList( std::string const &Input ) {
|
||||
|
||||
36
Train.cpp
36
Train.cpp
@@ -5903,42 +5903,6 @@ TTrain::radio_message( sound_source *Message, int const Channel ) {
|
||||
.play( sound_flags::exclusive );
|
||||
}
|
||||
|
||||
void TTrain::Silence()
|
||||
{ // wyciszenie dźwięków przy wychodzeniu
|
||||
#ifdef EU07_USE_OLD_SOUNDCODE
|
||||
dsbNastawnikJazdy.Stop();
|
||||
dsbNastawnikBocz.Stop();
|
||||
dsbRelay.Stop();
|
||||
dsbPneumaticRelay.Stop();
|
||||
dsbSwitch.Stop();
|
||||
dsbPneumaticSwitch.Stop();
|
||||
dsbReverserKey.Stop();
|
||||
dsbCouplerAttach.Stop();
|
||||
dsbCouplerDetach.Stop();
|
||||
dsbDieselIgnition.Stop();
|
||||
dsbWejscie_na_bezoporow.Stop();
|
||||
dsbWejscie_na_drugi_uklad.Stop();
|
||||
rsBrake.Stop();
|
||||
rsSlippery.Stop();
|
||||
rsHiss.Stop();
|
||||
rsHissU.Stop();
|
||||
rsHissE.Stop();
|
||||
rsHissX.Stop();
|
||||
rsHissT.Stop();
|
||||
rsSBHiss.Stop();
|
||||
rsRunningNoise.Stop();
|
||||
rsEngageSlippery.Stop();
|
||||
rsFadeSound.Stop();
|
||||
dsbHasler.Stop(); // wyłączenie dźwięków opuszczanej kabiny
|
||||
dsbBuzzer.Stop();
|
||||
dsbSlipAlarm.Stop(); // dźwięk alarmu przy poślizgu
|
||||
// sConverter.Stop();
|
||||
// sSmallCompressor->Stop();
|
||||
dsbCouplerStretch.Stop();
|
||||
dsbBufferClamp.Stop();
|
||||
#endif
|
||||
};
|
||||
|
||||
void TTrain::SetLights()
|
||||
{
|
||||
TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->ActiveCab < 0 ? 1 : 0, 4);
|
||||
|
||||
1
Train.h
1
Train.h
@@ -492,7 +492,6 @@ private:
|
||||
inline TMoverParameters *Controlled() { return mvControlled; };
|
||||
inline TMoverParameters const *Controlled() const { return mvControlled; };
|
||||
void DynamicSet(TDynamicObject *d);
|
||||
void Silence();
|
||||
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
117
World.cpp
117
World.cpp
@@ -512,9 +512,7 @@ void TWorld::OnKeyDown(int cKey)
|
||||
// works always in debug mode, or for stopped/slow moving vehicles otherwise
|
||||
Controlled = tmp; // przejmujemy nowy
|
||||
mvControlled = Controlled->ControlledFind()->MoverParameters;
|
||||
if( Train )
|
||||
Train->Silence(); // wyciszenie dźwięków opuszczanego pojazdu
|
||||
else
|
||||
if( Train == nullptr )
|
||||
Train = new TTrain(); // jeśli niczym jeszcze nie jeździlismy
|
||||
if( Train->Init( Controlled ) ) { // przejmujemy sterowanie
|
||||
if( !DebugModeFlag ) // w DebugMode nadal prowadzi AI
|
||||
@@ -646,11 +644,15 @@ void TWorld::OnKeyDown(int cKey)
|
||||
if( Controlled->MoverParameters->Radio )
|
||||
simulation::Region->RadioStop( Camera.Pos );
|
||||
}
|
||||
else if (!Global::iPause) //||(cKey==VK_F4)) //podczas pauzy sterownaie nie działa, F4 tak
|
||||
else if (!Global::iPause) //podczas pauzy sterownaie nie działa
|
||||
if (Train)
|
||||
if (Controlled)
|
||||
if ((Controlled->Controller == Humandriver) ? true : DebugModeFlag || (cKey == GLFW_KEY_Q))
|
||||
Train->OnKeyDown(cKey); // przekazanie klawisza do kabiny
|
||||
if( ( cKey == GLFW_KEY_Q )
|
||||
|| ( ( Controlled->Controller == Humandriver )
|
||||
|| ( true == DebugModeFlag ) ) ) {
|
||||
Train->OnKeyDown( cKey ); // przekazanie klawisza do kabiny
|
||||
}
|
||||
|
||||
if (FreeFlyModeFlag) // aby nie odluźniało wagonu za lokomotywą
|
||||
{ // operacje wykonywane na dowolnym pojeździe, przeniesione tu z kabiny
|
||||
/*
|
||||
@@ -659,17 +661,12 @@ void TWorld::OnKeyDown(int cKey)
|
||||
if (cKey == Global::Keys[k_Releaser]) // odluźniacz
|
||||
{ // działa globalnie, sprawdzić zasięg
|
||||
TDynamicObject *temp = Global::DynamicNearest();
|
||||
if (temp)
|
||||
{
|
||||
if (Global::ctrlState) // z ctrl odcinanie
|
||||
{
|
||||
if (temp) {
|
||||
if (Global::ctrlState) // z ctrl odcinanie {
|
||||
temp->MoverParameters->Hamulec->SetBrakeStatus( temp->MoverParameters->Hamulec->GetBrakeStatus() ^ 128 );
|
||||
}
|
||||
else if (temp->MoverParameters->BrakeReleaser(1))
|
||||
{
|
||||
// temp->sBrakeAcc->
|
||||
// dsbPneumaticRelay->SetVolume(DSBVOLUME_MAX);
|
||||
// dsbPneumaticRelay->Play(0,0,0); //temp->Position()-Camera.Pos //???
|
||||
else {
|
||||
temp->MoverParameters->BrakeReleaser(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -722,20 +719,14 @@ void TWorld::OnKeyDown(int cKey)
|
||||
auto *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global::pCameraPosition, 10, false, false ) ) };
|
||||
if (vehicle)
|
||||
{
|
||||
if (Global::ctrlState)
|
||||
if ((vehicle->MoverParameters->LocalBrake == ManualBrake) ||
|
||||
(vehicle->MoverParameters->MBrake == true))
|
||||
vehicle->MoverParameters->IncManualBrakeLevel(1);
|
||||
else
|
||||
;
|
||||
else if (vehicle->MoverParameters->LocalBrake != ManualBrake)
|
||||
if (vehicle->MoverParameters->IncLocalBrakeLevelFAST())
|
||||
if (Train)
|
||||
{ // dźwięk oczywiście jest w kabinie
|
||||
#ifdef EU07_USE_OLD_SOUNDCODE
|
||||
Train->dsbPneumaticRelay.play();
|
||||
#endif
|
||||
}
|
||||
if( Global::ctrlState ) {
|
||||
if( ( vehicle->MoverParameters->LocalBrake == ManualBrake )
|
||||
|| ( vehicle->MoverParameters->MBrake == true ) )
|
||||
vehicle->MoverParameters->IncManualBrakeLevel( 1 );
|
||||
}
|
||||
else if( vehicle->MoverParameters->LocalBrake != ManualBrake ) {
|
||||
vehicle->MoverParameters->IncLocalBrakeLevelFAST();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cKey == Global::Keys[k_DecLocalBrakeLevel])
|
||||
@@ -743,30 +734,19 @@ void TWorld::OnKeyDown(int cKey)
|
||||
auto *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Global::pCameraPosition, 10, false, false ) ) };
|
||||
if (vehicle)
|
||||
{
|
||||
if (Global::ctrlState)
|
||||
if ((vehicle->MoverParameters->LocalBrake == ManualBrake) ||
|
||||
(vehicle->MoverParameters->MBrake == true))
|
||||
vehicle->MoverParameters->DecManualBrakeLevel(1);
|
||||
else
|
||||
;
|
||||
else if (vehicle->MoverParameters->LocalBrake != ManualBrake)
|
||||
if (vehicle->MoverParameters->DecLocalBrakeLevelFAST())
|
||||
if (Train)
|
||||
{ // dźwięk oczywiście jest w kabinie
|
||||
#ifdef EU07_USE_OLD_SOUNDCODE
|
||||
Train->dsbPneumaticRelay.play();
|
||||
#endif
|
||||
}
|
||||
if( Global::ctrlState ) {
|
||||
if( ( vehicle->MoverParameters->LocalBrake == ManualBrake )
|
||||
|| ( vehicle->MoverParameters->MBrake == true ) )
|
||||
vehicle->MoverParameters->DecManualBrakeLevel( 1 );
|
||||
}
|
||||
else if( vehicle->MoverParameters->LocalBrake != ManualBrake ) {
|
||||
vehicle->MoverParameters->DecLocalBrakeLevelFAST();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TWorld::OnMouseMove(double x, double y)
|
||||
{ // McZapkie:060503-definicja obracania myszy
|
||||
Camera.OnCursorMove(x * Global::fMouseXScale / Global::ZoomFactor, -y * Global::fMouseYScale / Global::ZoomFactor);
|
||||
}
|
||||
|
||||
void TWorld::InOutKey( bool const Near )
|
||||
{ // przełączenie widoku z kabiny na zewnętrzny i odwrotnie
|
||||
FreeFlyModeFlag = !FreeFlyModeFlag; // zmiana widoku
|
||||
@@ -775,8 +755,6 @@ void TWorld::InOutKey( bool const Near )
|
||||
if (Train) {
|
||||
// cache current cab position so there's no need to set it all over again after each out-in switch
|
||||
Train->pMechSittingPosition = Train->pMechOffset;
|
||||
// wyłączenie dźwięków kabiny
|
||||
Train->Silence();
|
||||
Train->Dynamic()->bDisplayCab = false;
|
||||
DistantView( Near );
|
||||
}
|
||||
@@ -2101,26 +2079,28 @@ void TWorld::CabChange(TDynamicObject *old, TDynamicObject *now)
|
||||
void TWorld::ChangeDynamic() {
|
||||
|
||||
// Ra: to nie może być tak robione, to zbytnia proteza jest
|
||||
Train->Silence(); // wyłączenie dźwięków opuszczanej kabiny
|
||||
if( Train->Dynamic()->Mechanik ) // AI może sobie samo pójść
|
||||
if( !Train->Dynamic()->Mechanik->AIControllFlag ) // tylko jeśli ręcznie prowadzony
|
||||
{ // jeśli prowadzi AI, to mu nie robimy dywersji!
|
||||
if( Train->Dynamic()->Mechanik ) {
|
||||
// AI może sobie samo pójść
|
||||
if( false == Train->Dynamic()->Mechanik->AIControllFlag ) {
|
||||
// tylko jeśli ręcznie prowadzony
|
||||
// jeśli prowadzi AI, to mu nie robimy dywersji!
|
||||
Train->Dynamic()->MoverParameters->CabDeactivisation();
|
||||
Train->Dynamic()->Controller = AIdriver;
|
||||
// Train->Dynamic()->MoverParameters->SecuritySystem.Status=0; //rozwala CA w EZT
|
||||
Train->Dynamic()->MoverParameters->ActiveCab = 0;
|
||||
Train->Dynamic()->MoverParameters->BrakeLevelSet(
|
||||
Train->Dynamic()->MoverParameters->Handle->GetPos(
|
||||
bh_NP ) ); //rozwala sterowanie hamulcem GF 04-2016
|
||||
Train->Dynamic()->MoverParameters->BrakeLevelSet( Train->Dynamic()->MoverParameters->Handle->GetPos( bh_NP ) ); //rozwala sterowanie hamulcem GF 04-2016
|
||||
Train->Dynamic()->MechInside = false;
|
||||
}
|
||||
}
|
||||
TDynamicObject *temp = Global::changeDynObj;
|
||||
Train->Dynamic()->bDisplayCab = false;
|
||||
Train->Dynamic()->ABuSetModelShake( vector3( 0, 0, 0 ) );
|
||||
Train->Dynamic()->ABuSetModelShake( {} );
|
||||
|
||||
if( Train->Dynamic()->Mechanik ) // AI może sobie samo pójść
|
||||
if( !Train->Dynamic()->Mechanik->AIControllFlag ) // tylko jeśli ręcznie prowadzony
|
||||
Train->Dynamic()->Mechanik->MoveTo( temp ); // przsunięcie obiektu zarządzającego
|
||||
if( false == Train->Dynamic()->Mechanik->AIControllFlag ) {
|
||||
// tylko jeśli ręcznie prowadzony
|
||||
// przsunięcie obiektu zarządzającego
|
||||
Train->Dynamic()->Mechanik->MoveTo( temp );
|
||||
}
|
||||
|
||||
Train->DynamicSet( temp );
|
||||
Controlled = temp;
|
||||
@@ -2129,20 +2109,17 @@ void TWorld::ChangeDynamic() {
|
||||
if( Train->Dynamic()->Mechanik ) // AI może sobie samo pójść
|
||||
if( !Train->Dynamic()->Mechanik->AIControllFlag ) // tylko jeśli ręcznie prowadzony
|
||||
{
|
||||
Train->Dynamic()->MoverParameters->LimPipePress =
|
||||
Controlled->MoverParameters->PipePress;
|
||||
Train->Dynamic()
|
||||
->MoverParameters->CabActivisation(); // załączenie rozrządu (wirtualne kabiny)
|
||||
Train->Dynamic()->MoverParameters->LimPipePress = Controlled->MoverParameters->PipePress;
|
||||
Train->Dynamic()->MoverParameters->CabActivisation(); // załączenie rozrządu (wirtualne kabiny)
|
||||
Train->Dynamic()->Controller = Humandriver;
|
||||
Train->Dynamic()->MechInside = true;
|
||||
}
|
||||
Train->InitializeCab( Train->Dynamic()->MoverParameters->CabNo,
|
||||
Train->Dynamic()->asBaseDir +
|
||||
Train->Dynamic()->MoverParameters->TypeName + ".mmd" );
|
||||
Train->InitializeCab(
|
||||
Train->Dynamic()->MoverParameters->CabNo,
|
||||
Train->Dynamic()->asBaseDir + Train->Dynamic()->MoverParameters->TypeName + ".mmd" );
|
||||
if( !FreeFlyModeFlag ) {
|
||||
Train->Dynamic()->bDisplayCab = true;
|
||||
Train->Dynamic()->ABuSetModelShake(
|
||||
vector3( 0, 0, 0 ) ); // zerowanie przesunięcia przed powrotem?
|
||||
Train->Dynamic()->ABuSetModelShake( {} ); // zerowanie przesunięcia przed powrotem?
|
||||
Train->MechStop();
|
||||
FollowView(); // na pozycję mecha
|
||||
}
|
||||
|
||||
1
World.h
1
World.h
@@ -100,7 +100,6 @@ TWorld();
|
||||
bool InitPerformed() { return m_init; }
|
||||
bool Update();
|
||||
void OnKeyDown( int cKey );
|
||||
void OnMouseMove( double x, double y );
|
||||
void OnCommandGet( multiplayer::DaneRozkaz *pRozkaz );
|
||||
// passes specified sound to all vehicles within range as a radio message broadcasted on specified channel
|
||||
void radio_message( sound_source *Message, int const Channel );
|
||||
|
||||
@@ -66,9 +66,7 @@ commanddescription_sequence Commands_descriptions = {
|
||||
{ "hornhighactivate", command_target::vehicle },
|
||||
{ "radiotoggle", command_target::vehicle },
|
||||
{ "radiostoptest", command_target::vehicle },
|
||||
/*
|
||||
const int k_FailedEngineCutOff = 35;
|
||||
*/
|
||||
|
||||
{ "viewturn", command_target::entity },
|
||||
{ "movehorizontal", command_target::entity },
|
||||
{ "movehorizontalfast", command_target::entity },
|
||||
|
||||
@@ -61,9 +61,7 @@ enum class user_command {
|
||||
hornhighactivate,
|
||||
radiotoggle,
|
||||
radiostoptest,
|
||||
/*
|
||||
const int k_FailedEngineCutOff = 35;
|
||||
*/
|
||||
|
||||
viewturn,
|
||||
movehorizontal,
|
||||
movehorizontalfast,
|
||||
|
||||
@@ -137,7 +137,7 @@ keyboard_input::key( int const Key, int const Action ) {
|
||||
m_keys[ Key ] = Action;
|
||||
}
|
||||
|
||||
if( true == update_movement( Key, Action ) ) {
|
||||
if( true == is_movement_key( Key ) ) {
|
||||
// if the received key was one of movement keys, it's been handled and we don't need to bother further
|
||||
return true;
|
||||
}
|
||||
@@ -350,10 +350,6 @@ const int k_ProgramHelp = 48;
|
||||
// instrumentlighttoggle
|
||||
{ GLFW_KEY_SEMICOLON },
|
||||
/*
|
||||
const int k_Univ1 = 66;
|
||||
const int k_Univ2 = 67;
|
||||
const int k_Univ3 = 68;
|
||||
const int k_Univ4 = 69;
|
||||
const int k_EndSign = 70;
|
||||
const int k_Active = 71;
|
||||
*/
|
||||
@@ -403,8 +399,7 @@ keyboard_input::bind() {
|
||||
}
|
||||
++commandcode;
|
||||
}
|
||||
|
||||
// cache movement key bindings, so we can test them faster in the input loop
|
||||
// cache movement key bindings
|
||||
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;
|
||||
@@ -413,11 +408,10 @@ keyboard_input::bind() {
|
||||
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 ) {
|
||||
keyboard_input::is_movement_key( int const Key ) const {
|
||||
|
||||
bool const movementkey =
|
||||
bool const ismovementkey =
|
||||
( ( Key == m_bindingscache.forward )
|
||||
|| ( Key == m_bindingscache.back )
|
||||
|| ( Key == m_bindingscache.left )
|
||||
@@ -425,7 +419,7 @@ keyboard_input::update_movement( int const Key, int const Action ) {
|
||||
|| ( Key == m_bindingscache.up )
|
||||
|| ( Key == m_bindingscache.down ) );
|
||||
|
||||
return ( true == movementkey );
|
||||
return ismovementkey;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -61,7 +61,7 @@ private:
|
||||
void
|
||||
bind();
|
||||
bool
|
||||
update_movement( int const Key, int const Action );
|
||||
is_movement_key( int const Key ) const;
|
||||
|
||||
// members
|
||||
commandsetup_sequence m_commands;
|
||||
|
||||
Reference in New Issue
Block a user