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

workaround for allowing quit in launcher, fixup freeflymodeflag accesses in TTrain

This commit is contained in:
milek7
2020-10-19 02:12:35 +02:00
parent d13cf5c1a4
commit 9b7f10ab57
8 changed files with 30 additions and 30 deletions

View File

@@ -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<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 10, false, true ) ) };
auto *vehicle { std::get<TDynamicObject *>( 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<TDynamicObject *>( simulation::Region->find_vehicle( Global.pCamera.Pos, 10, false, true ) ) };
auto *vehicle { std::get<TDynamicObject *>( 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<TDynamicObject *>( 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<TDynamicObject *>( simulation::Region->find_vehicle( Command.location, 50, false, true ) ) };

View File

@@ -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())

View File

@@ -90,7 +90,7 @@ public:
double
generate_sync();
void
queue_quit();
queue_quit(bool direct);
bool
is_server() const;
bool

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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();
}

View File

@@ -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) {

View File

@@ -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;