mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-20 10:45:27 +00:00
Merge exp/seamless-transfer-2: seamless instance moves keep the player in place
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -499,8 +499,9 @@ void EntityManager::SerializeEntity(const Entity& entity) {
|
||||
}
|
||||
}
|
||||
|
||||
void EntityManager::DestructAllEntities(const SystemAddress& sysAddr) {
|
||||
void EntityManager::DestructAllEntities(const SystemAddress& sysAddr, const LWOOBJID except) {
|
||||
for (auto* entity : m_Entities | std::views::values) {
|
||||
if (entity && except != LWOOBJID_EMPTY && entity->GetObjectID() == except) continue;
|
||||
DestructEntity(entity, sysAddr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@ public:
|
||||
void SerializeEntity(const Entity& entity);
|
||||
|
||||
void ConstructAllEntities(const SystemAddress& sysAddr);
|
||||
void DestructAllEntities(const SystemAddress& sysAddr);
|
||||
// Takes every object away from one client, except `except` when given
|
||||
void DestructAllEntities(const SystemAddress& sysAddr, LWOOBJID except = LWOOBJID_EMPTY);
|
||||
|
||||
void SetGhostDistanceMax(float value);
|
||||
void SetGhostDistanceMin(float value);
|
||||
|
||||
@@ -227,12 +227,20 @@ void CharacterComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInit
|
||||
outBitStream.Write(m_RacesFinished);
|
||||
outBitStream.Write(m_FirstPlaceRaceFinishes);
|
||||
|
||||
outBitStream.Write0();
|
||||
outBitStream.Write(m_IsLanding);
|
||||
if (m_IsLanding) {
|
||||
outBitStream.Write<uint16_t>(m_LastRocketConfig.size());
|
||||
for (uint16_t character : m_LastRocketConfig) {
|
||||
outBitStream.Write(character);
|
||||
// The world transition state, two bits: 0 none, 1 arriving by rocket, 2 leaving. The client's
|
||||
// LWOCharacterComponent::PostCharacterLoaded (0x00c71660) fades the screen in from white and pushes its
|
||||
// gameplay state again when it reads 0. A client that kept its scene gets 3, which nothing acts on.
|
||||
if (m_KeepClientScene) {
|
||||
outBitStream.Write1();
|
||||
outBitStream.Write1();
|
||||
} else {
|
||||
outBitStream.Write0();
|
||||
outBitStream.Write(m_IsLanding);
|
||||
if (m_IsLanding) {
|
||||
outBitStream.Write<uint16_t>(m_LastRocketConfig.size());
|
||||
for (uint16_t character : m_LastRocketConfig) {
|
||||
outBitStream.Write(character);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,13 @@ public:
|
||||
void SetLastCustomBuild(const std::u16string& tokenizedLOTList) { m_LastRocketConfig = tokenizedLOTList; }
|
||||
bool GetIsLanding() const { return m_IsLanding; }
|
||||
|
||||
/**
|
||||
* Constructions written while this is set tell the client there is no world transition to show (state 3 instead
|
||||
* of 0 or the rocket landing). For the one construction a client gets of its own player after a seamless instance
|
||||
* move (docs/SeamlessTransfer.md).
|
||||
*/
|
||||
void SetKeepClientScene(const bool value) { m_KeepClientScene = value; }
|
||||
|
||||
/**
|
||||
* Find a player's rocket
|
||||
* @param player the entity that triggered the event
|
||||
@@ -435,6 +442,11 @@ private:
|
||||
*/
|
||||
bool m_IsLanding;
|
||||
|
||||
/**
|
||||
* Whether constructions say there is no world transition to show (SetKeepClientScene)
|
||||
*/
|
||||
bool m_KeepClientScene = false;
|
||||
|
||||
/**
|
||||
* The configuration of the last used rocket, essentially a string of LOTs separated by commas
|
||||
*/
|
||||
|
||||
@@ -143,8 +143,11 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo
|
||||
if (!bIsInitialUpdate) m_DirtyBubble = false;
|
||||
}
|
||||
|
||||
outBitStream.Write(m_DirtyPosition || bIsInitialUpdate);
|
||||
if (m_DirtyPosition || bIsInitialUpdate) {
|
||||
// A client that kept its player across a seamless instance move knows where it stands better than the save does:
|
||||
// its construction leaves the frame out, and LWOBasePhysComponent::Deserialize (0x00bf5a10) then sets nothing
|
||||
const bool writePosition = bIsInitialUpdate ? !m_KeepClientPosition : m_DirtyPosition;
|
||||
outBitStream.Write(writePosition);
|
||||
if (writePosition) {
|
||||
outBitStream.Write(m_Position.x);
|
||||
outBitStream.Write(m_Position.y);
|
||||
outBitStream.Write(m_Position.z);
|
||||
|
||||
@@ -216,6 +216,13 @@ public:
|
||||
*/
|
||||
bool GetIsTeleporting() const { return m_IsTeleporting; }
|
||||
|
||||
/**
|
||||
* Constructions written while this is set carry no position, rotation or velocity. For the one construction a
|
||||
* client gets of its own player after a seamless instance move (docs/SeamlessTransfer.md): the client applies a
|
||||
* construction's frame to its player at once, which would pull it back to where it was saved.
|
||||
*/
|
||||
void SetKeepClientPosition(const bool value) { m_KeepClientPosition = value; }
|
||||
|
||||
/**
|
||||
* Returns the Physics entity for the component
|
||||
* @return Physics entity for the component
|
||||
@@ -400,6 +407,11 @@ private:
|
||||
*/
|
||||
void UpdateSpeedBoost();
|
||||
|
||||
/**
|
||||
* Whether constructions leave the position out (SetKeepClientPosition)
|
||||
*/
|
||||
bool m_KeepClientPosition = false;
|
||||
|
||||
/**
|
||||
* The list of speed boosts for this entity
|
||||
*/
|
||||
|
||||
@@ -70,7 +70,11 @@ namespace GameMessages {
|
||||
return;
|
||||
}
|
||||
const auto* const zoneControlEntity = Game::entityManager->GetZoneControlEntity();
|
||||
SendPlayerReady(entity->GetObjectID(), zoneControlEntity ? zoneControlEntity->GetObjectID() : LWOOBJID_EMPTY, sysAddr);
|
||||
// A client that kept its player across a seamless instance move is ready already; PlayerReady would only put
|
||||
// its camera's pitch back to the default (LWOCharacterComponent::iSendMessage, 0x00d34330)
|
||||
if (!WorldMigration::ArrivesSeamlessly(entity->GetObjectID())) {
|
||||
SendPlayerReady(entity->GetObjectID(), zoneControlEntity ? zoneControlEntity->GetObjectID() : LWOOBJID_EMPTY, sysAddr);
|
||||
}
|
||||
entity->SetPlayerReadyForUpdates();
|
||||
|
||||
// Venture vision from equipped items was sent before the client's UI existed on a fresh login
|
||||
|
||||
@@ -40,6 +40,10 @@ namespace {
|
||||
// Give up on a migration after this long moving; whoever is left stays (or is saved when the world shuts down)
|
||||
constexpr float MAX_MOVE_SECONDS = 150.0f;
|
||||
constexpr float STATUS_INTERVAL = 1.0f;
|
||||
// How long after it was sent a seamless arrival is expected (the reconnect takes a second or two)
|
||||
constexpr float SEAMLESS_ARRIVAL_SECONDS = 30.0f;
|
||||
// A client that arrived without reloading and hasn't sent PlayerLoaded after this gets it run for them
|
||||
constexpr float SEAMLESS_LOADED_FALLBACK_SECONDS = 5.0f;
|
||||
// Carried state for a player who never arrives
|
||||
constexpr float CARRIED_EXPIRY_SECONDS = 300.0f;
|
||||
|
||||
@@ -185,10 +189,13 @@ namespace {
|
||||
MasterPackets::SendToMaster(carried);
|
||||
}
|
||||
|
||||
// Seamless: take every object we sent away first. The client deletes them but keeps its own player object when
|
||||
// that ghost goes (LWOGhostComponent::OnGhostReceiveDestruction), and the target's construction of the
|
||||
// player is adopted by it. Same ordered channel as the transfer, so these arrive before it.
|
||||
if (order.seamless) Game::entityManager->DestructAllEntities(sysAddr);
|
||||
// Seamless: take every object we sent away first, except their own player. The client keeps its player object
|
||||
// either way (LWOGhostComponent::OnGhostReceiveDestruction, 0x00c99410), but losing its last ghost puts it out
|
||||
// of scope: it fades out, and fades back in with the login effect when the target constructs it
|
||||
// (LWOBaseRenderComponent::OnEnterScope, 0x00be2150). With its old ghost left alone, the target's
|
||||
// construction just takes over (LwoClientGhostManager::OnReceiveConstruction, 0x00b31c30). Same ordered
|
||||
// channel as the transfer, so these arrive before it.
|
||||
if (order.seamless) Game::entityManager->DestructAllEntities(sysAddr, playerId);
|
||||
|
||||
ClientPackets::TransferToWorld transfer;
|
||||
transfer.serverIP = LUString(order.targetIp);
|
||||
@@ -391,7 +398,14 @@ void WorldMigration::OnDisconnected(const SystemAddress& sysAddr) {
|
||||
|
||||
bool WorldMigration::ArrivesSeamlessly(LWOOBJID characterId) {
|
||||
const auto it = g_Carried.find(characterId);
|
||||
return it != g_Carried.end() && it->second.first.seamless;
|
||||
// Only for a while: a client that logs in again later has no scene and needs LOAD_STATIC_ZONE
|
||||
return it != g_Carried.end() && it->second.first.seamless && it->second.second <= SEAMLESS_ARRIVAL_SECONDS;
|
||||
}
|
||||
|
||||
void WorldMigration::KeepClientPlayer(Entity* player, const bool keep) {
|
||||
if (!player || (keep && !ArrivesSeamlessly(player->GetObjectID()))) return;
|
||||
if (auto* physics = player->GetComponent<ControllablePhysicsComponent>()) physics->SetKeepClientPosition(keep);
|
||||
if (auto* characterComponent = player->GetComponent<CharacterComponent>()) characterComponent->SetKeepClientScene(keep);
|
||||
}
|
||||
|
||||
void WorldMigration::OnSeamlessArrival(Entity* player) {
|
||||
@@ -399,10 +413,11 @@ void WorldMigration::OnSeamlessArrival(Entity* player) {
|
||||
const auto playerId = player->GetObjectID();
|
||||
const auto sysAddr = player->GetSystemAddress();
|
||||
LOG("Player %llu arrived without reloading the zone", playerId);
|
||||
// The client already finished loading on the old instance and won't send PlayerLoaded again: do what it would
|
||||
// trigger, once the constructions have had a moment to arrive
|
||||
player->AddCallbackTimer(1.0f, [playerId, sysAddr]() {
|
||||
if (!Game::entityManager->GetEntity(playerId)) return;
|
||||
// The client sends PlayerLoaded itself once its character got the construction
|
||||
// (LWOCharacterComponent::PostCharacterLoaded, 0x00c71660). Should that not come, do what it would trigger.
|
||||
player->AddCallbackTimer(SEAMLESS_LOADED_FALLBACK_SECONDS, [playerId, sysAddr]() {
|
||||
if (!g_Carried.contains(playerId) || !Game::entityManager->GetEntity(playerId)) return;
|
||||
LOG("Player %llu sent no PlayerLoaded after arriving without a reload, running it for them", playerId);
|
||||
RakNet::BitStream empty;
|
||||
GameMessageHandler::HandleMessage(empty, sysAddr, playerId, MessageType::Game::PLAYER_LOADED);
|
||||
});
|
||||
|
||||
@@ -51,7 +51,12 @@ namespace WorldMigration {
|
||||
// not be sent LOAD_STATIC_ZONE (that tears the scene down); load it at once instead
|
||||
bool ArrivesSeamlessly(LWOOBJID characterId);
|
||||
|
||||
// Its player entity was created and constructed: run what the client's PlayerLoaded would have
|
||||
// While `keep` is set, constructions of a seamlessly arriving player leave out what would reset its client's own
|
||||
// player: the position (the client stands where it is) and the world transition (no fade from white). Set only
|
||||
// around the construction that goes to the player's own client; does nothing for other players.
|
||||
void KeepClientPlayer(Entity* player, bool keep);
|
||||
|
||||
// Its player entity was created and constructed: the client sends PlayerLoaded itself; a fallback runs it if not
|
||||
void OnSeamlessArrival(Entity* player);
|
||||
|
||||
// MIGRATE_STATUS from master: tell the GM who asked, if they are here
|
||||
|
||||
Reference in New Issue
Block a user