mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-03 17:50:21 +01:00
multiplayer: a cab belongs to the peer it is on, and the first one aboard drives
Joining a crew did nothing. The cab was being built by a replicated entervehicle that the authority posted only when it had no cab of its own - which is exactly the case that never happens for the second person to board. The host claims a vehicle, the server builds a cab, and from then on every further claim finds one already standing over there, posts nothing, and the joining peer waits forever for a command that is not coming. A cab is not a shared object. Each participant has their own, with their own camera and their own view of it, and nothing about it needs to travel. So it is built locally by whoever needs one: the driver mode does it for the player when their claim is granted, and the authority does it for itself, because it needs a cab to address the AI handover commands to. That also stops a cab being created on every peer for every claimed vehicle, which is what the entervehicle broadcast was doing. Who runs a shared train is no longer decided by car numbering. It is whoever boarded first, and it stays with them: every crew member is stamped with a session-wide counter when they sit down, and the smallest stamp on the whole consist owns the physics. Coupling, uncoupling and renumbering do not move it, and neither does somebody else joining - each handover is a stutter in the ride of the person who has been driving, and they are the one who would notice it. The stamps travel with CREW_UPDATE and in the snapshot, because a client works out ownership for itself and has to arrive at the same answer. Chat: the key that opens it is now read before imgui gets a look at the input. Any window holding the keyboard - the lobby, most likely, which is precisely where a client sits - would swallow it, so on that side the panel could not be opened at all. The exception is text actually being typed, which is the chat box itself; escape closes that. A client also logs what it says, so if a line goes missing it is clear which half of the trip lost it. Protocol version 6, snapshot version 7.
This commit is contained in:
@@ -16,6 +16,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class TDynamicObject;
|
||||
class TTrain;
|
||||
|
||||
namespace network
|
||||
{
|
||||
|
||||
@@ -26,6 +29,11 @@ struct vehicle_crew
|
||||
{
|
||||
NetworkEntityId entity_id{ENTITY_NONE};
|
||||
std::vector<PeerId> crew;
|
||||
// when each of them sat down, on a counter that runs across the whole session. this
|
||||
// is what settles who runs the physics of a shared train: the one who got there first
|
||||
// keeps it, so their ride stays smooth and nobody's authority changes under them when
|
||||
// somebody else joins or the consist is renumbered
|
||||
std::vector<uint64_t> crew_since;
|
||||
// whether the AI was actually driving before the first human arrived. a vehicle that
|
||||
// nobody was driving must not suddenly acquire an AI driver when its crew leaves
|
||||
bool ai_before_claim{false};
|
||||
@@ -76,7 +84,9 @@ public:
|
||||
NetworkEntityId vehicle_of(PeerId Peer) const;
|
||||
|
||||
// client side: takes over the crew of one vehicle as published by the server
|
||||
void mirror(NetworkEntityId Id, std::vector<PeerId> const &Crew);
|
||||
void mirror(NetworkEntityId Id, std::vector<PeerId> const &Crew, std::vector<uint64_t> const &Since);
|
||||
// the join stamps of a crew, in the same order as crew_of()
|
||||
std::vector<uint64_t> crew_since_of(NetworkEntityId Id) const;
|
||||
// puts a peer on a vehicle without asking about capacity; used when somebody walks to
|
||||
// another car of the train they are already working
|
||||
void take_seat(PeerId Peer, NetworkEntityId Id);
|
||||
@@ -171,4 +181,11 @@ claim_result claim_by_name(PeerId Peer, std::string const &Vehicle, NetworkEntit
|
||||
// very same authority layer as input arriving over the wire, only without the transport
|
||||
void filter_commands(PeerId Peer, command_queue::commands_map &Commands);
|
||||
|
||||
// makes sure this peer has a cab instance for a vehicle, building one if it has none.
|
||||
// the cab is a local object - each participant has their own, with their own camera and
|
||||
// their own view - so it is never replicated: the second person to board a train finds
|
||||
// the cab already built on the peer that got there first and would otherwise wait for a
|
||||
// command that is never coming
|
||||
TTrain *ensure_local_cab(TDynamicObject *Vehicle);
|
||||
|
||||
} // namespace network
|
||||
|
||||
Reference in New Issue
Block a user