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

multiplayer: the session imposes the settings that decide the physics

server_hello.config had been a TODO carrying a zero, and every peer ran with
whatever its own eu07.ini happened to say - including a vehicle physics thread
count, which makes the order vehicles are stepped in depend on how threads get
scheduled.

- the handshake now carries a bitfield of the settings that change how the
  physics comes out (full physics, realistic control) and a joining peer takes
  them on, saying in the log what changed
- a multiplayer session runs the vehicle physics on one thread on every peer,
  host included

Settings that only affect what a player sees or how comfortable the controls
feel stay with the player; only what alters the outcome belongs in here.
This commit is contained in:
2026-09-06 19:58:28 +00:00
parent 30fa68cfd8
commit 65159b9546
5 changed files with 58 additions and 2 deletions

View File

@@ -184,6 +184,43 @@ bool crew_registry::leave(PeerId Peer, NetworkEntityId Id)
return true;
}
int64_t pack_session_config()
{
int64_t config{0};
if (Global.FullPhysics)
config |= CONFIG_FULLPHYSICS;
if (Global.RealisticControlMode)
config |= CONFIG_REALISTICCONTROL;
return config;
}
void apply_session_config(int64_t Config)
{
bool const fullphysics{(Config & CONFIG_FULLPHYSICS) != 0};
bool const realisticcontrol{(Config & CONFIG_REALISTICCONTROL) != 0};
if (Global.FullPhysics != fullphysics)
WriteLog(std::string("net: the session runs with full physics ") + (fullphysics ? "on" : "off"), logtype::net);
if (Global.RealisticControlMode != realisticcontrol)
WriteLog(std::string("net: the session runs with realistic control ") + (realisticcontrol ? "on" : "off"), logtype::net);
Global.FullPhysics = fullphysics;
Global.RealisticControlMode = realisticcontrol;
}
void enforce_session_settings()
{
if (Global.trainThreads != 0)
{
// the order vehicles are stepped in must not depend on how threads happen to be
// scheduled; a session cannot afford that kind of drift
WriteLog("net: multiplayer session, running the vehicle physics on one thread", logtype::net);
Global.trainThreads = 0;
}
}
PeerId resolve_peer_identity(uint64_t &Token)
{
static std::unordered_map<uint64_t, PeerId> known;