17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 12:09:19 +02:00

multiplayer: correct a train by sliding it, not by putting it down again

Reversing on the host turned the whole set around on the client, and the
locomotive ended up looking like something derailed making its way across the
scenery. Both come from the same place: a routine correction was calling
place_on_track(), which sets the axles from scratch and works from the
vehicle's own idea of which way it faces. That is right for a peer joining with
nothing to go on, and wrong for a train that is already running - the placement
reorients it.

A correction now slides the vehicle along the track it is already on, by the
difference between the two bogie offsets, which is the same operation the
physics performs on every step. When the two sides disagree about which piece
of track the vehicle is on, it is left alone until they agree; guessing there
is what put a locomotive beside the rails. place_on_track() is kept for the one
case it suits, a peer joining the session.

Also:

- taking a seat works with the game paused. The whole thing sat inside the
  "has any time passed" branch, so with the world stopped the lobby button
  changed the roster and nothing else happened
- the debug panel gets a Network section, shown only in a session: role, peer,
  tick, bytes and messages each way with a running rate, two charts of kB/s so
  the cost of a session can be read off, how far the worst vehicle is out of
  place, and whether the state digest agrees. The separate "network" overlay
  window is gone - everything it said lives there now, together with the lobby
  and refusal messages that had nowhere to be seen
This commit is contained in:
2026-09-07 07:49:47 +00:00
parent c0dbf99f1a
commit a0537356bb
11 changed files with 234 additions and 69 deletions

View File

@@ -183,6 +183,54 @@ bool driver_mode::update()
simulation::State.update_scripting_interface();
simulation::Environment.update();
// taking a seat has to work whether the world is running or not: a player sitting
// in the lobby with the game paused still expects the button to put them in the cab
if (Global.network_leave_pending)
{
// we were taken off the crew (by our own request or by the server), so the
// camera goes back to observing. the cab instance itself stays put, it may
// still be occupied by somebody else or handed back to the AI
Global.network_leave_pending = false;
if (simulation::Train != nullptr)
{
if (!FreeFlyModeFlag)
InOutKey();
simulation::Train = nullptr;
Camera.m_owner = nullptr;
Global.local_start_vehicle = "ghostview";
}
}
if (change_train.empty() && !Global.network_pending_vehicle.empty())
{
// vehicle picked in the multiplayer lobby; the cab itself is built by the
// replicated entervehicle command, we only have to move in once it exists
change_train = Global.network_pending_vehicle;
Global.network_pending_vehicle.clear();
}
if (!change_train.empty())
{
TTrain *train = simulation::Trains.find(change_train);
if (train)
{
Global.local_start_vehicle = change_train;
simulation::Train = train;
InOutKey();
if (!Application.is_server() && !Application.is_client())
{
// in a multiplayer session the AI handover belongs to the server, which
// also knows whether the vehicle had an AI driver in the first place
m_relay.post(user_command::aidriverdisable, 0.0, 0.0, GLFW_PRESS, 0);
}
change_train.clear();
auto ui = std::dynamic_pointer_cast<driver_ui>(m_userinterface);
if (ui != nullptr)
ui->show_multiplayer_lobby(false);
}
}
if (deltatime != 0.0 || false == simulation::is_ready)
{
// jak pauza, to nie ma po co tego przeliczać
@@ -267,52 +315,6 @@ bool driver_mode::update()
// variable step simulation time routines
if (Global.network_leave_pending)
{
// we were taken off the crew (by our own request or by the server), so the
// camera goes back to observing. the cab instance itself stays put, it may
// still be occupied by somebody else or handed back to the AI
Global.network_leave_pending = false;
if (simulation::Train != nullptr)
{
if (!FreeFlyModeFlag)
InOutKey();
simulation::Train = nullptr;
Camera.m_owner = nullptr;
Global.local_start_vehicle = "ghostview";
}
}
if (change_train.empty() && !Global.network_pending_vehicle.empty())
{
// vehicle picked in the multiplayer lobby; the cab itself is built by the
// replicated entervehicle command, we only have to move in once it exists
change_train = Global.network_pending_vehicle;
Global.network_pending_vehicle.clear();
}
if (!change_train.empty())
{
TTrain *train = simulation::Trains.find(change_train);
if (train)
{
Global.local_start_vehicle = change_train;
simulation::Train = train;
InOutKey();
if (!Application.is_server() && !Application.is_client())
{
// in a multiplayer session the AI handover belongs to the server, which
// also knows whether the vehicle had an AI driver in the first place
m_relay.post(user_command::aidriverdisable, 0.0, 0.0, GLFW_PRESS, 0);
}
change_train.clear();
auto ui = std::dynamic_pointer_cast<driver_ui>(m_userinterface);
if (ui != nullptr)
ui->show_multiplayer_lobby(false);
}
}
if (simulation::Train == nullptr && false == FreeFlyModeFlag)
{
// intercept cases when the driven train got removed after entering portal