mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-01 10:22:09 +01:00
multiplayer: a player works a train, not a car - and put the corrections right
Second live test. Four things, three of them the same mistake seen from different angles: the session was reasoning about single vehicles where it should have been reasoning about trains. - a peer may now operate anything coupled into the set it is sitting in. This is what "cabchangebackward rejected: not a member of the crew of that vehicle" was: the crew was recorded against one car of a four-car unit, and the cab switch addressed another - every vehicle gets a network id, not only the ones worth driving. Commands are addressed by that id, and a player has to be able to walk into any car of their train. "peer 3 cannot take en71-017rb_4: no such vehicle in this session" was the driving trailer of an EN71 - a full desk, no engine, and nobody assigned to it, so the old test missed it. Having a driving position is what counts now, engine or not - the roster groups vehicles into the trains they are coupled into and the lobby lists one row per train. Coupling is worked out afresh every time, so a train that comes apart becomes two, and because a crew entry sits on the car its player occupies, each half keeps the people who were riding in it - walking to another car of your own train is not a new claim and asks nothing of the crew capacity, which counts people per train Positional correction never actually did anything: it identified a track by name, and most track in a scenery has none, so the lookup returned nothing and place_on_track() was never reached. The client sat 178 m out of place for minutes, reporting four vehicles "put back on the rails" every time while moving none of them. Tracks now travel as their index in the path table, which comes from the scenery file and is therefore the same on every peer. Also from the test: - the camera jumped in and out of the cab on the client whenever the host reversed, because the correction was forcing the server's CabActive and CabOccupied onto it. Which cab somebody sits in is theirs alone - two people sharing a vehicle each have their own - so it is no longer replicated - the correction no longer touches the control positions of the train the local player is working. Their crew's commands reach every peer on their own, and snapping a lever back a fraction of a second after it was moved is what made the reverser look dead - the frame buffer was sized for the old lockstep, up to sixty frames deep. Every frame in it is input lag, so it is down to twelve with a target of one - asking the AI of a vehicle to step aside is given five tries and then said once, instead of every thirty frames forever; and a resync request now has a real cooldown
This commit is contained in:
@@ -36,20 +36,35 @@ constexpr NetworkEntityId ENTITY_NONE = 0;
|
||||
// so raising this number does not call for a structural change
|
||||
constexpr uint8_t CREW_CAPACITY = 2;
|
||||
|
||||
// authoritative description of a single drivable vehicle, as published by the server
|
||||
// authoritative description of a single vehicle, as published by the server.
|
||||
// every vehicle is listed, not only the ones worth driving: commands are addressed by
|
||||
// this id, and a player may walk into any member of the train they are working
|
||||
struct vehicle_entry
|
||||
{
|
||||
NetworkEntityId id{ENTITY_NONE};
|
||||
std::string name;
|
||||
// the train this vehicle is currently coupled into, named by the lowest id in the set.
|
||||
// a player belongs to a train, not to a single car, so this is what the crew, the
|
||||
// permissions and the lobby all work with. it is recomputed as vehicles couple and
|
||||
// uncouple, which is what splits a crew between the halves of a train that came apart
|
||||
NetworkEntityId consist_id{ENTITY_NONE};
|
||||
// how many vehicles that train has, and whether this entry is the one that stands for
|
||||
// it in the lobby
|
||||
uint8_t consist_size{1};
|
||||
bool consist_lead{false};
|
||||
// crew of the whole train, not of this vehicle alone
|
||||
uint8_t crew_count{0};
|
||||
uint8_t crew_capacity{CREW_CAPACITY};
|
||||
bool ai_active{false};
|
||||
bool claimable{false};
|
||||
// has a driving position of its own
|
||||
bool drivable{false};
|
||||
|
||||
bool operator==(vehicle_entry const &Other) const
|
||||
{
|
||||
return id == Other.id && name == Other.name && crew_count == Other.crew_count && crew_capacity == Other.crew_capacity && ai_active == Other.ai_active &&
|
||||
claimable == Other.claimable;
|
||||
return id == Other.id && name == Other.name && consist_id == Other.consist_id && consist_size == Other.consist_size && consist_lead == Other.consist_lead &&
|
||||
crew_count == Other.crew_count && crew_capacity == Other.crew_capacity && ai_active == Other.ai_active && claimable == Other.claimable &&
|
||||
drivable == Other.drivable;
|
||||
}
|
||||
bool operator!=(vehicle_entry const &Other) const { return !(*this == Other); }
|
||||
};
|
||||
@@ -74,6 +89,9 @@ public:
|
||||
|
||||
NetworkEntityId id_of(std::string const &Name) const;
|
||||
NetworkEntityId id_of(TDynamicObject const *Vehicle) const;
|
||||
// the train a vehicle belongs to, and everything coupled into it
|
||||
NetworkEntityId consist_of(NetworkEntityId Id) const;
|
||||
std::vector<NetworkEntityId> consist_members(NetworkEntityId Consist) const;
|
||||
std::string name_of(NetworkEntityId Id) const;
|
||||
TDynamicObject *resolve(NetworkEntityId Id) const;
|
||||
vehicle_entry const *find(NetworkEntityId Id) const;
|
||||
@@ -98,7 +116,8 @@ bool is_multiplayer();
|
||||
// of a session do; a client does not, it only carries out what the server hands it
|
||||
bool is_authority();
|
||||
|
||||
// true for vehicles a player can take over
|
||||
// true for vehicles that carry a driving position of their own. note that a driving
|
||||
// trailer has one without having an engine, and without the scenario putting a driver in
|
||||
bool is_drivable(TDynamicObject const *Vehicle);
|
||||
|
||||
} // namespace network
|
||||
|
||||
Reference in New Issue
Block a user