From 9b7f10ab57f50543fdbab3ee62f389be40ad5736 Mon Sep 17 00:00:00 2001 From: milek7 Date: Mon, 19 Oct 2020 02:12:35 +0200 Subject: [PATCH] workaround for allowing quit in launcher, fixup freeflymodeflag accesses in TTrain --- Train.cpp | 22 +++++++++++----------- application.cpp | 14 +++++++++----- application.h | 2 +- drivermode.cpp | 2 -- driveruilayer.cpp | 4 ++-- launcher/launcheruilayer.cpp | 4 ++-- simulation.cpp | 2 +- uilayer.cpp | 10 ++++------ 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Train.cpp b/Train.cpp index 89f38b02..a64cdd29 100644 --- a/Train.cpp +++ b/Train.cpp @@ -1315,7 +1315,7 @@ void TTrain::OnCommand_independentbrakeset( TTrain *Train, command_data const &C void TTrain::OnCommand_independentbrakebailoff( TTrain *Train, command_data const &Command ) { - if( false == FreeFlyModeFlag ) { + if( false == Command.freefly ) { // TODO: check if this set of conditions can be simplified. // it'd be more flexible to have an attribute indicating whether bail off position is supported if( ( Train->mvControlled->TrainType != dt_EZT ) @@ -1865,7 +1865,7 @@ void TTrain::OnCommand_brakeactingspeedsetrapid( TTrain *Train, command_data con void TTrain::OnCommand_brakeloadcompensationincrease( TTrain *Train, command_data const &Command ) { - if( ( true == FreeFlyModeFlag ) + if( ( true == Command.freefly ) && ( Command.action == GLFW_PRESS ) ) { auto *vehicle { Train->find_nearest_consist_vehicle(Command.freefly, Command.location) }; if( vehicle != nullptr ) { @@ -1876,7 +1876,7 @@ void TTrain::OnCommand_brakeloadcompensationincrease( TTrain *Train, command_dat void TTrain::OnCommand_brakeloadcompensationdecrease( TTrain *Train, command_data const &Command ) { - if( ( true == FreeFlyModeFlag ) + if( ( true == Command.freefly ) && ( Command.action == GLFW_PRESS ) ) { auto *vehicle { Train->find_nearest_consist_vehicle(Command.freefly, Command.location) }; if( vehicle != nullptr ) { @@ -4260,17 +4260,17 @@ void TTrain::OnCommand_redmarkertogglerearright( TTrain *Train, command_data con void TTrain::OnCommand_redmarkerstoggle( TTrain *Train, command_data const &Command ) { - if( ( true == FreeFlyModeFlag ) + if( ( true == Command.freefly ) && ( Command.action == GLFW_PRESS ) ) { - auto *vehicle { std::get( simulation::Region->find_vehicle( Global.pCamera.Pos, 10, false, true ) ) }; + auto *vehicle { std::get( simulation::Region->find_vehicle( Command.location, 10, false, true ) ) }; if( vehicle == nullptr ) { return; } int const CouplNr { clamp( vehicle->DirectionGet() - * ( Math3D::LengthSquared3( vehicle->HeadPosition() - Global.pCamera.Pos ) > Math3D::LengthSquared3( vehicle->RearPosition() - Global.pCamera.Pos ) ? + * ( Math3D::LengthSquared3( vehicle->HeadPosition() - Command.location ) > Math3D::LengthSquared3( vehicle->RearPosition() - Command.location ) ? 1 : -1 ), 0, 1 ) }; // z [-1,1] zrobić [0,1] @@ -4286,17 +4286,17 @@ void TTrain::OnCommand_redmarkerstoggle( TTrain *Train, command_data const &Comm void TTrain::OnCommand_endsignalstoggle( TTrain *Train, command_data const &Command ) { - if( ( true == FreeFlyModeFlag ) + if( ( true == Command.freefly ) && ( Command.action == GLFW_PRESS ) ) { - auto *vehicle { std::get( simulation::Region->find_vehicle( Global.pCamera.Pos, 10, false, true ) ) }; + auto *vehicle { std::get( simulation::Region->find_vehicle( Command.location, 10, false, true ) ) }; if( vehicle == nullptr ) { return; } int const CouplNr { clamp( vehicle->DirectionGet() - * ( Math3D::LengthSquared3( vehicle->HeadPosition() - Global.pCamera.Pos ) > Math3D::LengthSquared3( vehicle->RearPosition() - Global.pCamera.Pos ) ? + * ( Math3D::LengthSquared3( vehicle->HeadPosition() - Command.location ) > Math3D::LengthSquared3( vehicle->RearPosition() - Command.location ) ? 1 : -1 ), 0, 1 ) }; // z [-1,1] zrobić [0,1] @@ -5520,7 +5520,7 @@ void TTrain::OnCommand_nearestcarcouplingdisconnect( TTrain *Train, command_data void TTrain::OnCommand_nearestcarcoupleradapterattach( TTrain *Train, command_data const &Command ) { - if( ( true == FreeFlyModeFlag ) + if( ( true == Command.freefly ) && ( Command.action == GLFW_PRESS ) ) { // tryb freefly, press only auto *vehicle { std::get( simulation::Region->find_vehicle( Command.location, 50, false, true ) ) }; @@ -5537,7 +5537,7 @@ void TTrain::OnCommand_nearestcarcoupleradapterattach( TTrain *Train, command_da void TTrain::OnCommand_nearestcarcoupleradapterremove( TTrain *Train, command_data const &Command ) { - if( ( true == FreeFlyModeFlag ) + if( ( true == Command.freefly ) && ( Command.action == GLFW_PRESS ) ) { // tryb freefly, press only auto *vehicle { std::get( simulation::Region->find_vehicle( Command.location, 50, false, true ) ) }; diff --git a/application.cpp b/application.cpp index 3894a187..47415d9c 100644 --- a/application.cpp +++ b/application.cpp @@ -165,8 +165,14 @@ double eu07_application::generate_sync() { return sync; } -void eu07_application::queue_quit() { - glfwSetWindowShouldClose(m_windows[0], GLFW_TRUE); +void eu07_application::queue_quit(bool direct) { + if (direct || !m_modes[m_modestack.top()]->is_command_processor()) { + glfwSetWindowShouldClose(m_windows[0], GLFW_TRUE); + return; + } + + command_relay relay; + relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0); } bool @@ -885,9 +891,7 @@ eu07_application::init_modes() { if ((!Global.network_servers.empty() || Global.network_client) && Global.SceneryFile.empty()) { ErrorLog("launcher mode is currently not supported in network mode"); return -1; - } - // NOTE: we could delay creation/initialization until transition to specific mode is requested, - // but doing it in one go at the start saves us some error checking headache down the road + } // activate the default mode if (Global.SceneryFile.empty()) diff --git a/application.h b/application.h index 6c9c09d3..fad68789 100644 --- a/application.h +++ b/application.h @@ -90,7 +90,7 @@ public: double generate_sync(); void - queue_quit(); + queue_quit(bool direct); bool is_server() const; bool diff --git a/drivermode.cpp b/drivermode.cpp index 75df4c5c..67e490fd 100644 --- a/drivermode.cpp +++ b/drivermode.cpp @@ -285,8 +285,6 @@ driver_mode::update() { auto const deltarealtime = Timer::GetDeltaRenderTime(); // nie uwzględnia pauzowania ani mnożenia czasu simulation::State.process_commands(); - simulation::State.process_commands(); - // fixed step render time routines fTime50Hz += deltarealtime; // w pauzie też trzeba zliczać czas, bo przy dużym FPS będzie problem z odczytem ramek diff --git a/driveruilayer.cpp b/driveruilayer.cpp index 1cf504b3..07e2cfe8 100644 --- a/driveruilayer.cpp +++ b/driveruilayer.cpp @@ -231,8 +231,8 @@ driver_ui::render_() { if( ImGui::Button( STR_C("Resume"), ImVec2( 150, 0 ) ) ) { m_relay.post(user_command::pausetoggle, 0.0, 0.0, GLFW_PRESS, 0); } - if( ImGui::Button( STR_C("Quit"), ImVec2( 150, 0 ) ) ) { - m_relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0); + if( ImGui::Button( STR_C("Quit"), ImVec2( 150, 0 ) ) ) { + Application.queue_quit(false); } if (!m_paused) { diff --git a/launcher/launcheruilayer.cpp b/launcher/launcheruilayer.cpp index ab7a6ddd..031dcda1 100644 --- a/launcher/launcheruilayer.cpp +++ b/launcher/launcheruilayer.cpp @@ -38,8 +38,8 @@ void launcher_ui::render_() m_vehiclepicker_panel.is_open = !m_vehiclepicker_panel.is_open; if (ImGui::Button(STR_C("Keymapper"), ImVec2(-1, 0))) m_keymapper_panel.is_open = !m_keymapper_panel.is_open; - if (ImGui::Button(STR_C("Quit"), ImVec2(-1, 0))) - Application.queue_quit(); + if (ImGui::Button(STR_C("Quit"), ImVec2(-1, 0))) + Application.queue_quit(false); } ImGui::End(); } diff --git a/simulation.cpp b/simulation.cpp index b353bc5f..ea42c0ed 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -444,7 +444,7 @@ void state_manager::process_commands() { if (commanddata.command == user_command::quitsimulation) { // TBD: allow clients to go into offline mode? - Application.queue_quit(); + Application.queue_quit(true); } if (DebugModeFlag) { diff --git a/uilayer.cpp b/uilayer.cpp index 51bfec54..6a63657e 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -288,8 +288,7 @@ bool ui_layer::on_key(int const Key, int const Action) if (m_quit_active) { if (Key == GLFW_KEY_Y) { - command_relay relay; - relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0); + Application.queue_quit(false); return true; } else if (Key == GLFW_KEY_N) { m_quit_active = false; @@ -364,10 +363,9 @@ void ui_layer::render_quit_widget() ImGui::SetNextWindowSize(ImVec2(0, 0)); ImGui::Begin(STR_C("Quit"), &m_quit_active, ImGuiWindowFlags_NoResize); ImGui::TextUnformatted(STR_C("Quit simulation?")); - if (ImGui::Button(STR_C("Yes"))) { - command_relay relay; - relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0); - } + if (ImGui::Button(STR_C("Yes"))) + Application.queue_quit(false); + ImGui::SameLine(); if (ImGui::Button(STR_C("No"))) m_quit_active = false;