mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 09:09:19 +02:00
multiplayer: two sync margins in the ini, and the session decides the trainsets
Two hardcoded constants decided how far a train could drift before it was put
back, and there was no way to change them short of a rebuild. They are settings
now:
multiplayer.sync.running 1.5 // margin while the train is rolling
multiplayer.sync.stop 0.2 // one precise correction once it stands
The split is what the two numbers are for. A moving train is left to its own
physics unless it is well out, because nudging it several times a second is
worse than the error; a standing one is worth getting right to the centimetre,
and it is done once and then left alone until it moves again - a consist that
has had its correction is marked settled, and clears that mark the moment it
rolls. Both travel in SERVER_HELLO: whatever a player has in their own ini, a
session runs to the host's margins, which is the only way the peers agree on
what "out of place" means.
And the trainsets. Every peer loads its own copy of the scenery - that is the
only reason joining takes seconds instead of minutes - but the copy on disk is
not the session: the host may have shunted a set apart, put one together, or be
running a scenery whose consists were edited since. So the composition travels
in a full snapshot, ahead of the positions: which coupler of which vehicle is
joined to which coupler of which other, and with what hoses and cables. A
joining peer breaks what should not be coupled, makes what should, and only
then gets told where everything is - so the per-consist repositioning works on
the session's trains rather than on the ones its own scenery file described.
The vehicles themselves do not travel, and cannot: a peer missing one gets a
line in the log saying so, not a model over the wire.
Uncoupling has to be forced here. TDynamicObject::Dettach() leaves the
mechanical coupler alone unless the buffers are pressed together, which is
right for a player pulling a lever and wrong for putting a peer's world in
order.
Protocol version 5, snapshot version 6.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "utilities/Timer.h"
|
||||
#include "application/application.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/utilities.h"
|
||||
#include "simulation/simulation.h"
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
@@ -15,7 +16,7 @@
|
||||
// 3 - handshake carries build identification and an explicit rejection message
|
||||
// 4 - peer identity, vehicle roster and crew handshake, command source,
|
||||
// logical simulation tick and a versioned state digest instead of the position sum
|
||||
std::uint32_t const EU07_NETWORK_VERSION = 4;
|
||||
std::uint32_t const EU07_NETWORK_VERSION = 5;
|
||||
|
||||
namespace network {
|
||||
|
||||
@@ -195,6 +196,8 @@ void network::server::handle_message(std::shared_ptr<connection> conn, const mes
|
||||
reply.seed = Global.random_seed;
|
||||
reply.timestamp = Global.starting_timestamp;
|
||||
reply.config = pack_session_config();
|
||||
reply.sync_running = Global.multiplayer_sync_running;
|
||||
reply.sync_stop = Global.multiplayer_sync_stop;
|
||||
reply.scenario = Global.SceneryFile;
|
||||
reply.app_version = Global.asVersion;
|
||||
reply.session_token = cmd.session_token;
|
||||
@@ -510,6 +513,17 @@ void network::client::handle_message(std::shared_ptr<connection> conn, const mes
|
||||
return;
|
||||
}
|
||||
|
||||
// the session decides how tightly it is kept in step, not the machine that joined it
|
||||
if ((cmd.sync_running > 0.0) && (cmd.sync_stop > 0.0)) {
|
||||
if ((std::abs(Global.multiplayer_sync_running - (float)cmd.sync_running) > 0.001f)
|
||||
|| (std::abs(Global.multiplayer_sync_stop - (float)cmd.sync_stop) > 0.001f)) {
|
||||
WriteLog("net: the session syncs to " + to_string(cmd.sync_running, 2) + " m while running and "
|
||||
+ to_string(cmd.sync_stop, 2) + " m at a stand", logtype::net);
|
||||
}
|
||||
Global.multiplayer_sync_running = (float)cmd.sync_running;
|
||||
Global.multiplayer_sync_stop = (float)cmd.sync_stop;
|
||||
}
|
||||
|
||||
if (cmd.peer_id != PEER_NONE) {
|
||||
Global.network_peer_id = cmd.peer_id;
|
||||
WriteLog("net: assigned peer id " + std::to_string(cmd.peer_id), logtype::net);
|
||||
|
||||
Reference in New Issue
Block a user