mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 10:19:20 +02:00
First live test showed three things wrong at once.
A client could not take a vehicle. Walking up to a locomotive and pressing the
enter-vehicle key posts entervehicle, which stage 4 classed as a world-wide
command and refused outright ("reserved for the session host"), so the client
never got a cab and every later control command died locally for want of one.
Walking into a cab is a request for a seat, not a world command: the authority
now turns it into a crew claim, for the host through the same path as for a
remote peer, and answers it the way the lobby button is answered.
Nothing but commands was ever replicated. The server sent dt and the commands
it ran, and the client simulated the rest for itself - so a pantograph the host
raised before the client joined, the contents of the memory cells the signalling
reads, brake pressures and switch positions simply never crossed the wire. The
server now streams the authoritative state a few times a second: whatever has
changed since the last one, and the whole of it every so often so a peer heals
from anything it missed. The snapshot carries the vehicle's inputs - line
breaker, battery, converter and compressor permits, pantograph valves, cab,
lights, doors - and lets the receiving peer derive the rest, plus the memory
cells and the switches.
Desync detection demanded that two state digests be equal, on a design where
the client deliberately runs its own physics. They never can be, so it reported
a desync permanently and asked for a resync every five seconds forever, which
fixed nothing because the next step disagreed again. The digest is a log line
now; what is measured instead is how far out of place the routine correction
found us, and a full resync is only asked for when even that is not catching up.
Also: a consist is put back on the rails as a whole or not at all. Correcting
one vehicle while its neighbour stayed put is what was stretching couplers
until they tore - the last test moved six vehicles out of eight, every time.
And the lobby window collapsed to nothing, because its size_max was left at the
-1 default while size_min was set, so imgui was handed a maximum smaller than
the minimum.
72 lines
2.4 KiB
C++
72 lines
2.4 KiB
C++
#pragma once
|
|
#include <memory>
|
|
#include "network/network.h"
|
|
#include "input/command.h"
|
|
|
|
namespace network
|
|
{
|
|
class server_manager
|
|
{
|
|
private:
|
|
std::vector<std::shared_ptr<server>> servers;
|
|
std::shared_ptr<std::fstream> backbuffer;
|
|
|
|
public:
|
|
server_manager();
|
|
|
|
void push_delta(double render_dt, double dt, uint64_t tick, uint64_t state_hash, const command_queue::commands_map &commands);
|
|
command_queue::commands_map pop_commands();
|
|
void create_server(const std::string &backend, const std::string &conf);
|
|
// refreshes the authoritative vehicle roster and publishes it when it changed
|
|
void publish_vehicle_list();
|
|
// brings the world in line with the crew roster and announces every change
|
|
void update_crews();
|
|
// sends the peers what the world actually looks like. this is what keeps a client
|
|
// in line - the command stream alone cannot, because a client runs its own physics
|
|
void publish_state();
|
|
// crew request coming from the local participant, which needs no transport
|
|
void apply_local_claim(NetworkEntityId entity_id);
|
|
void apply_local_leave(NetworkEntityId entity_id);
|
|
|
|
private:
|
|
// how many frames may pass between two unconditional broadcasts of the roster
|
|
static const int PUBLISH_INTERVAL_FRAMES = 120;
|
|
|
|
// how often the authoritative state goes out, and how often it goes out whole
|
|
// rather than as what changed since the last one
|
|
static const int STATE_INTERVAL_FRAMES = 10;
|
|
static const int STATE_FULL_EVERY = 60;
|
|
|
|
std::vector<vehicle_entry> last_published_list;
|
|
int publish_countdown = 0;
|
|
int crew_publish_countdown = 0;
|
|
int state_countdown = 0;
|
|
int state_updates = 0;
|
|
};
|
|
|
|
class manager
|
|
{
|
|
public:
|
|
manager();
|
|
|
|
std::optional<server_manager> servers;
|
|
std::shared_ptr<network::client> client;
|
|
|
|
void create_server(const std::string &backend, const std::string &conf);
|
|
void connect(const std::string &backend, const std::string &conf);
|
|
void update();
|
|
|
|
// routes a lobby request to whoever holds the authority: straight into the crew
|
|
// registry when we are the server, over the wire when we are a client
|
|
void request_claim(NetworkEntityId entity_id);
|
|
void request_leave(NetworkEntityId entity_id);
|
|
|
|
// the local scenario is loaded; a client asks the server for a snapshot of the
|
|
// world as it stands right now
|
|
void notify_scenario_loaded();
|
|
|
|
// our world drifted away from the authoritative one; ask to be corrected
|
|
void request_resync(uint64_t tick, uint64_t state_hash);
|
|
};
|
|
}
|