diff --git a/Source/ZMMO/Game/Network/ZMMOWorldSubsystem.cpp b/Source/ZMMO/Game/Network/ZMMOWorldSubsystem.cpp index b65fa04..f5ce148 100644 --- a/Source/ZMMO/Game/Network/ZMMOWorldSubsystem.cpp +++ b/Source/ZMMO/Game/Network/ZMMOWorldSubsystem.cpp @@ -195,15 +195,45 @@ void UZMMOWorldSubsystem::HandlePlayerStateUpdate(const int32 EntityId, const in Snapshot.LastProcessedInputSeq = InputSeq; Snapshot.PositionCm = PosCm; Snapshot.VelocityCmS = VelCmS; - // Yaw nao chega no opcode S_PLAYER_STATE actual; derivamos do XY da - // velocidade quando significativo, caso contrario mantemos rotacao do ator. - if (!FVector(VelCmS.X, VelCmS.Y, 0.0f).IsNearlyZero(1.0f)) + + // Etapa 7 (server-side networking refactor): yaw agora chega no + // snapshot quantizado v3. Buscamos via TryGetLastPlayerStateExtended + // (cache local do plugin). Se PSF_HasYaw nao estiver set ou se o cache + // nao tiver entrada, caimos no fallback antigo (derivar do XY da + // velocidade ou manter rotacao do ator). + bool bYawFromSnapshot = false; + if (UZeusNetworkSubsystem* ZeusNet = ResolveZeusNetworkSubsystem()) { - Snapshot.YawDeg = FMath::RadiansToDegrees(FMath::Atan2(VelCmS.Y, VelCmS.X)); + int32 CachedInputSeq = 0; + FVector CachedPos = FVector::ZeroVector; + FVector CachedVel = FVector::ZeroVector; + float CachedYawDeg = 0.f; + int32 CachedFlags = 0; + int64 CachedServerTimeMs = 0; + if (ZeusNet->TryGetLastPlayerStateExtended( + EntityId, CachedInputSeq, CachedPos, CachedVel, + CachedYawDeg, CachedFlags, CachedServerTimeMs)) + { + constexpr int32 PSF_HasYaw = 1 << 5; + if ((CachedFlags & PSF_HasYaw) != 0) + { + Snapshot.YawDeg = CachedYawDeg; + bYawFromSnapshot = true; + } + } } - else + if (!bYawFromSnapshot) { - Snapshot.YawDeg = Actor->GetActorRotation().Yaw; + // Fallback: deriva yaw do XY da velocidade quando significativo; + // caso contrario mantem rotacao do ator (comportamento pre-Etapa 7). + if (!FVector(VelCmS.X, VelCmS.Y, 0.0f).IsNearlyZero(1.0f)) + { + Snapshot.YawDeg = FMath::RadiansToDegrees(FMath::Atan2(VelCmS.Y, VelCmS.X)); + } + else + { + Snapshot.YawDeg = Actor->GetActorRotation().Yaw; + } } Snapshot.bGrounded = bGrounded; Snapshot.ServerTimeMs = ServerTimeMs;