| 1267 | } |
| 1268 | |
| 1269 | void AAlsCharacter::RefreshViewNetworkSmoothing(const float DeltaTime) |
| 1270 | { |
| 1271 | // Based on UCharacterMovementComponent::SmoothClientPosition_Interpolate() |
| 1272 | // and UCharacterMovementComponent::SmoothClientPosition_UpdateVisuals(). |
| 1273 | |
| 1274 | auto& NetworkSmoothing{ViewState.NetworkSmoothing}; |
| 1275 | |
| 1276 | if (!NetworkSmoothing.bEnabled || |
| 1277 | NetworkSmoothing.ClientTime >= NetworkSmoothing.ServerTime || |
| 1278 | NetworkSmoothing.Duration <= UE_SMALL_NUMBER || |
| 1279 | (MovementBase.bHasRelativeRotation && IsNetMode(NM_ListenServer))) |
| 1280 | { |
| 1281 | // Can't use network smoothing on the listen server when the character |
| 1282 | // is standing on a rotating object, as it causes constant rotation jitter. |
| 1283 | |
| 1284 | NetworkSmoothing.InitialRotation = MovementBase.bHasRelativeRotation |
| 1285 | ? (MovementBase.Rotation * ReplicatedViewRotation.Quaternion()).Rotator() |
| 1286 | : ReplicatedViewRotation; |
| 1287 | |
| 1288 | NetworkSmoothing.TargetRotation = NetworkSmoothing.InitialRotation; |
| 1289 | NetworkSmoothing.FinalRotation = NetworkSmoothing.InitialRotation; |
| 1290 | |
| 1291 | return; |
| 1292 | } |
| 1293 | |
| 1294 | if (MovementBase.bHasRelativeRotation) |
| 1295 | { |
| 1296 | // Offset the rotations to keep them in the movement base space. |
| 1297 | |
| 1298 | NetworkSmoothing.InitialRotation.Pitch += MovementBase.DeltaRotation.Pitch; |
| 1299 | NetworkSmoothing.InitialRotation.Yaw += MovementBase.DeltaRotation.Yaw; |
| 1300 | NetworkSmoothing.InitialRotation.Normalize(); |
| 1301 | |
| 1302 | NetworkSmoothing.TargetRotation.Pitch += MovementBase.DeltaRotation.Pitch; |
| 1303 | NetworkSmoothing.TargetRotation.Yaw += MovementBase.DeltaRotation.Yaw; |
| 1304 | NetworkSmoothing.TargetRotation.Normalize(); |
| 1305 | |
| 1306 | NetworkSmoothing.FinalRotation.Pitch += MovementBase.DeltaRotation.Pitch; |
| 1307 | NetworkSmoothing.FinalRotation.Yaw += MovementBase.DeltaRotation.Yaw; |
| 1308 | NetworkSmoothing.FinalRotation.Normalize(); |
| 1309 | } |
| 1310 | |
| 1311 | NetworkSmoothing.ClientTime += DeltaTime; |
| 1312 | |
| 1313 | const auto InterpolationAmount{ |
| 1314 | UAlsMath::Clamp01(1.0f - (NetworkSmoothing.ServerTime - NetworkSmoothing.ClientTime) / NetworkSmoothing.Duration) |
| 1315 | }; |
| 1316 | |
| 1317 | if (!FAnimWeight::IsFullWeight(InterpolationAmount)) |
| 1318 | { |
| 1319 | NetworkSmoothing.FinalRotation = UAlsRotation::LerpRotation(NetworkSmoothing.InitialRotation, |
| 1320 | NetworkSmoothing.TargetRotation, |
| 1321 | InterpolationAmount); |
| 1322 | } |
| 1323 | else |
| 1324 | { |
| 1325 | NetworkSmoothing.ClientTime = NetworkSmoothing.ServerTime; |
| 1326 | NetworkSmoothing.FinalRotation = NetworkSmoothing.TargetRotation; |
nothing calls this directly
no outgoing calls
no test coverage detected