mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 12:39:18 +02: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:
@@ -31,6 +31,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/Logs.h"
|
||||
#include "network/entities.h"
|
||||
#include "network/snapshot.h"
|
||||
#include "network/session.h"
|
||||
/*
|
||||
namespace input {
|
||||
|
||||
@@ -213,6 +214,17 @@ bool driver_mode::update()
|
||||
if (!change_train.empty())
|
||||
{
|
||||
TTrain *train = simulation::Trains.find(change_train);
|
||||
|
||||
if ((train == nullptr) && network::is_multiplayer())
|
||||
{
|
||||
// a cab belongs to the peer it is on: each player has their own, with their own
|
||||
// camera and their own view of it. waiting for a replicated command to build it
|
||||
// only ever worked for the first person aboard a train - the second finds the
|
||||
// cab already standing on the peer that got there first, so nothing is posted
|
||||
// and the lobby button appears to do nothing at all
|
||||
train = network::ensure_local_cab(simulation::Vehicles.find(change_train));
|
||||
}
|
||||
|
||||
if (train)
|
||||
{
|
||||
Global.local_start_vehicle = change_train;
|
||||
@@ -540,20 +552,6 @@ void driver_mode::on_key(int const Key, int const Scancode, int const Action, in
|
||||
|
||||
bool anyModifier = Mods & (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT);
|
||||
|
||||
// the key left of 1 opens and closes the session chat. it is only bound in a session,
|
||||
// so single player keeps it for whatever else may want it later. while the chat has
|
||||
// the keyboard this is never reached: imgui swallows the input before it gets here,
|
||||
// which is exactly what stops typed letters from working the cab
|
||||
if ((Key == GLFW_KEY_GRAVE_ACCENT) && (Action == GLFW_PRESS) && !anyModifier && network::is_multiplayer())
|
||||
{
|
||||
auto ui = std::dynamic_pointer_cast<driver_ui>(m_userinterface);
|
||||
if (ui != nullptr)
|
||||
{
|
||||
ui->toggle_chat();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// give the ui first shot at the input processing...
|
||||
if (!anyModifier && true == m_userinterface->on_key(Key, Action))
|
||||
{
|
||||
@@ -629,6 +627,16 @@ void driver_mode::on_event_poll()
|
||||
m_input.poll();
|
||||
}
|
||||
|
||||
bool driver_mode::toggle_chat()
|
||||
{
|
||||
auto ui = std::dynamic_pointer_cast<driver_ui>(m_userinterface);
|
||||
if (ui == nullptr)
|
||||
return false;
|
||||
|
||||
ui->toggle_chat();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool driver_mode::is_command_processor() const
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user