Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Unity.Netcode.Components;
using Unity.Netcode.GameObjects.Editor.Configuration;
using Unity.Netcode.Logging;
using UnityEditor;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class NetworkManagerEditor : NetcodeEditorBase<NetworkManager>
private SerializedProperty m_SpawnTimeOutProperty;
private SerializedProperty m_RpcHashSizeProperty;
private SerializedProperty m_LoadSceneTimeOutProperty;
private SerializedProperty m_TransformSyncModeProperty;
private SerializedProperty m_PrefabsList;

private SerializedProperty m_NetworkProfileMetrics;
Expand Down Expand Up @@ -144,6 +146,7 @@ private void Initialize()
m_NetworkMessageMetrics = m_NetworkConfigProperty.FindPropertyRelative("NetworkMessageMetrics");
#endif
m_RpcHashSizeProperty = m_NetworkConfigProperty.FindPropertyRelative("RpcHashSize");
m_TransformSyncModeProperty = m_NetworkConfigProperty.FindPropertyRelative(nameof(NetworkConfig.TransformSyncMode));
m_PrefabsList = m_NetworkConfigProperty
.FindPropertyRelative(nameof(NetworkConfig.Prefabs))
.FindPropertyRelative(nameof(NetworkPrefabs.NetworkPrefabsLists));
Expand Down Expand Up @@ -192,6 +195,7 @@ private void CheckNullProperties()
#endif

m_RpcHashSizeProperty = m_NetworkConfigProperty.FindPropertyRelative("RpcHashSize");
m_TransformSyncModeProperty = m_NetworkConfigProperty.FindPropertyRelative(nameof(NetworkConfig.TransformSyncMode));
m_PrefabsList = m_NetworkConfigProperty
.FindPropertyRelative(nameof(NetworkConfig.Prefabs))
.FindPropertyRelative(nameof(NetworkPrefabs.NetworkPrefabsLists));
Expand Down Expand Up @@ -335,6 +339,17 @@ private void DisplayNetworkManagerProperties()
EditorGUILayout.PropertyField(m_PrefabsList);
}

EditorGUILayout.Space();
EditorGUILayout.LabelField("Transform Synchronization", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_TransformSyncModeProperty, new GUIContent("Mode"));
if (m_NetworkManager.NetworkConfig.TransformSyncMode == TransformSyncModes.Batched)
{
EditorGUILayout.HelpBox(
$"{nameof(NetworkTransform.UseUnreliableDeltas)} does not apply in this mode. Delivery is determined per state " +
"update as opposed to per component. Every peer in a session has to use the same mode.",
MessageType.Info);
}

EditorGUILayout.Space();
EditorGUILayout.LabelField("Scene Management Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_EnableSceneManagementProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,13 @@ public void Clear()
/// Resets the current interpolator to the target value.
/// </summary>
/// <remarks>
/// This is used when first synchronizing/initializing and when telporting an object.
/// This is used when first synchronizing/initializing and when teleporting an object.<br />
/// No baseline measurement is recorded.<br />
/// A baseline is stamped with the local ServerTime.Time.<br />
/// The measurements that follow carry the older tick they were authored on.<br />
/// AddMeasurement would drop every one of those.<br />
/// The interpolator is left the way a freshly spawned one is instead.<br />
/// <paramref name="serverTime"/> is not used. Mark this obsolete and deprecate it at a later date.
/// </remarks>
/// <param name="targetValue">The target value to reset the interpolator to</param>
/// <param name="serverTime">The current server time</param>
Expand All @@ -288,7 +294,9 @@ internal void ResetTo(Transform parent, T targetValue, double serverTime)
{
// Clear the interpolator
Clear();
InternalReset(parent, targetValue, serverTime);

// No baseline measurement. See the ResetTo remarks above.
InternalReset(parent, targetValue, serverTime, false);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;

namespace Unity.Netcode.Components
{
/// <summary>
/// The NGO non-authority instance's transform state used by <see cref="InterpolateTransformJob"/>.
/// See also:
/// - <see cref="NativeInterpolator"/>
/// - <see cref="NativeInterpolatorState"/>
/// </summary>
internal struct InterpolationEntry
{
internal NativeInterpolatorState Position;
internal NativeInterpolatorState Rotation;
internal NativeInterpolatorState Scale;

/// <summary>
/// The delta frame time whether fixed or standard delta.
/// </summary>
internal float DeltaTime;

/// <summary>
/// The "ticks ago" time used to decide which buffered measurements are ready to consume.
/// </summary>
internal double TickLatencyAsTime;

/// <summary>
/// The render time used by <see cref="NetworkTransform.InterpolationTypes.LegacyLerp"/> only.
/// </summary>
internal double LegacyRenderTime;

internal double CurrentTime;
internal double MinDeltaTime;
internal double MaxDeltaTime;

internal NetworkTransform.InterpolationTypes PositionInterpolationType;
internal NetworkTransform.InterpolationTypes RotationInterpolationType;
internal NetworkTransform.InterpolationTypes ScaleInterpolationType;

internal bool SynchronizePosition;
internal bool SynchronizeRotation;
internal bool SynchronizeScale;

// Results, read back on the main thread and applied to the transform there.
internal float4 InterpolatedPosition;
internal float4 InterpolatedRotation;
internal float4 InterpolatedScale;
}

/// <summary>
/// Non-Authority Only:
/// Handles interpolation for every registered non-authority <see cref="NetworkTransform"/> in
/// a parallel job.
/// </summary>
/// <remarks>
/// This performs the buffer consumption and interpolation between two state updates only.<br />
/// Applying the results to the transforms stays on the main thread, which keeps this job free
/// of hierarchy write ordering.<br />
/// Each entry owns its own slice of <see cref="BufferedItems"/>, so no two indices address the same items.<br />
/// The whole array can be written without aliasing (access is to a distinct, independent memory region).
/// </remarks>
[BurstCompile]
internal struct InterpolateTransformJob : IJobParallelFor
{
public NativeArray<InterpolationEntry> Entries;

/// <summary>
/// The shared state measurement storage. Disabling the safety restriction is what allows each index to write
/// into its own slice of one array; <see cref="NativeInterpolatorState.BufferOffset"/> keeps those
/// slices disjoint.
/// </summary>
[NativeDisableParallelForRestriction]
public NativeArray<BufferedItemNative> BufferedItems;

public void Execute(int index)
{
var entry = Entries[index];

if (entry.SynchronizePosition)
{
entry.InterpolatedPosition = Advance(ref entry.Position, ref entry, entry.PositionInterpolationType);
}

if (entry.SynchronizeRotation)
{
entry.InterpolatedRotation = Advance(ref entry.Rotation, ref entry, entry.RotationInterpolationType);
}

if (entry.SynchronizeScale)
{
entry.InterpolatedScale = Advance(ref entry.Scale, ref entry, entry.ScaleInterpolationType);
}

Entries[index] = entry;
}

private float4 Advance(ref NativeInterpolatorState state, ref InterpolationEntry entry, NetworkTransform.InterpolationTypes interpolationType)
{
if (interpolationType == NetworkTransform.InterpolationTypes.LegacyLerp)
{
return NativeInterpolator.UpdateLegacy(ref state, ref BufferedItems, entry.DeltaTime, entry.LegacyRenderTime, entry.CurrentTime);
}

return NativeInterpolator.Update(ref state, ref BufferedItems, entry.DeltaTime, entry.TickLatencyAsTime,
entry.MinDeltaTime, entry.MaxDeltaTime, interpolationType == NetworkTransform.InterpolationTypes.Lerp);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading