fix: NetworkTransform synchronize position when half float precision is enabled (#2845)

* fix

Edge case fix for half float precision not getting the proper initial base offset.

* update

adding change log entry

* update

adding PR number

* test

updating some of the tests to reduce the verbosity of the debug output.
This commit is contained in:
Noel Stephens 2024-04-05 11:09:59 -05:00 коммит произвёл GitHub
Родитель 5dcc00cd7d
Коммит ac46fa7fda
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 44 добавлений и 36 удалений

Просмотреть файл

@ -20,6 +20,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
### Fixed
- Fixed issue where `NetworkTransform` could not properly synchronize its base position when using half float precision. (#2845)
- Fixed issue where the host was not invoking `OnClientDisconnectCallback` for its own local client when internally shutting down. (#2822)
- Fixed issue where NetworkTransform could potentially attempt to "unregister" a named message prior to it being registered. (#2807)
- Fixed issue where in-scene placed `NetworkObject`s with complex nested children `NetworkObject`s (more than one child in depth) would not synchronize properly if WorldPositionStays was set to true. (#2796)

Просмотреть файл

@ -1424,6 +1424,7 @@ namespace Unity.Netcode.Components
/// <param name="targetClientId">the clientId being synchronized (both reading and writing)</param>
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
{
m_CachedNetworkManager = NetworkManager;
var targetClientId = m_TargetIdBeingSynchronized;
var synchronizationState = new NetworkTransformState()
{
@ -2764,6 +2765,11 @@ namespace Unity.Netcode.Components
m_CachedNetworkManager = NetworkManager;
Initialize();
if (CanCommitToTransform && UseHalfFloatPrecision)
{
SetState(GetSpaceRelativePosition(), GetSpaceRelativeRotation(), GetScale(), false);
}
}
/// <inheritdoc/>

Просмотреть файл

@ -56,13 +56,14 @@ namespace Unity.Netcode.RuntimeTests
// We don't assert on timeout here because we want to log this information during PostAllChildrenLocalTransformValuesMatch
WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesKeptLocalTransformValues(useSubChild));
var success = true;
m_InfoMessage.AppendLine($"[{checkType}][{useSubChild}] Timed out waiting for all children to have the correct local space values:\n");
if (s_GlobalTimeoutHelper.TimedOut)
{
//var waitForMs = new WaitForSeconds(0.001f);
// If we timed out, then wait for a full range of ticks to assure all data has been synchronized before declaring this a failed test.
for (int j = 0; j < m_ServerNetworkManager.NetworkConfig.TickRate; j++)
{
m_InfoMessage.Clear();
m_InfoMessage.AppendLine($"[{checkType}][{useSubChild}] Timed out waiting for all children to have the correct local space values:\n");
var instances = useSubChild ? ChildObjectComponent.SubInstances : ChildObjectComponent.Instances;
success = PostAllChildrenLocalTransformValuesMatch(useSubChild);
TimeTravel(0.001f);

Просмотреть файл

@ -1213,7 +1213,7 @@ namespace Unity.Netcode.RuntimeTests
private void TestValueTypeNativeArray<T>(NativeArray<T> testValue, NativeArray<T> changedValue) where T : unmanaged
{
Debug.Log($"Changing {ArrayStr(testValue)} to {ArrayStr(changedValue)}");
VerboseDebug($"Changing {ArrayStr(testValue)} to {ArrayStr(changedValue)}");
var serverVariable = new NetworkVariable<NativeArray<T>>(testValue);
var clientVariable = new NetworkVariable<NativeArray<T>>(new NativeArray<T>(1, Allocator.Persistent));
using var writer = new FastBufferWriter(1024, Allocator.Temp, int.MaxValue);
@ -1280,7 +1280,7 @@ namespace Unity.Netcode.RuntimeTests
private void TestList<T>(List<T> testValue, List<T> changedValue)
{
Debug.Log($"Changing {ListStr(testValue)} to {ListStr(changedValue)}");
VerboseDebug($"Changing {ListStr(testValue)} to {ListStr(changedValue)}");
var serverVariable = new NetworkVariable<List<T>>(testValue);
var inPlaceList = new List<T>();
var clientVariable = new NetworkVariable<List<T>>(inPlaceList);
@ -1344,7 +1344,7 @@ namespace Unity.Netcode.RuntimeTests
private void TestHashSet<T>(HashSet<T> testValue, HashSet<T> changedValue) where T : IEquatable<T>
{
Debug.Log($"Changing {HashSetStr(testValue)} to {HashSetStr(changedValue)}");
VerboseDebug($"Changing {HashSetStr(testValue)} to {HashSetStr(changedValue)}");
var serverVariable = new NetworkVariable<HashSet<T>>(testValue);
var inPlaceList = new HashSet<T>();
var clientVariable = new NetworkVariable<HashSet<T>>(inPlaceList);
@ -1412,7 +1412,7 @@ namespace Unity.Netcode.RuntimeTests
private void TestDictionary<TKey, TVal>(Dictionary<TKey, TVal> testValue, Dictionary<TKey, TVal> changedValue)
where TKey : IEquatable<TKey>
{
Debug.Log($"Changing {DictionaryStr(testValue)} to {DictionaryStr(changedValue)}");
VerboseDebug($"Changing {DictionaryStr(testValue)} to {DictionaryStr(changedValue)}");
var serverVariable = new NetworkVariable<Dictionary<TKey, TVal>>(testValue);
var inPlaceList = new Dictionary<TKey, TVal>();
var clientVariable = new NetworkVariable<Dictionary<TKey, TVal>>(inPlaceList);
@ -1483,7 +1483,7 @@ namespace Unity.Netcode.RuntimeTests
private void TestValueTypeNativeList<T>(NativeList<T> testValue, NativeList<T> changedValue) where T : unmanaged
{
Debug.Log($"Changing {NativeListStr(testValue)} to {NativeListStr(changedValue)}");
VerboseDebug($"Changing {NativeListStr(testValue)} to {NativeListStr(changedValue)}");
var serverVariable = new NetworkVariable<NativeList<T>>(testValue);
var inPlaceList = new NativeList<T>(1, Allocator.Temp);
var clientVariable = new NetworkVariable<NativeList<T>>(inPlaceList);
@ -1551,7 +1551,7 @@ namespace Unity.Netcode.RuntimeTests
private void TestValueTypeNativeHashSet<T>(NativeHashSet<T> testValue, NativeHashSet<T> changedValue) where T : unmanaged, IEquatable<T>
{
Debug.Log($"Changing {NativeHashSetStr(testValue)} to {NativeHashSetStr(changedValue)}");
VerboseDebug($"Changing {NativeHashSetStr(testValue)} to {NativeHashSetStr(changedValue)}");
var serverVariable = new NetworkVariable<NativeHashSet<T>>(testValue);
var inPlaceList = new NativeHashSet<T>(1, Allocator.Temp);
var clientVariable = new NetworkVariable<NativeHashSet<T>>(inPlaceList);
@ -1626,7 +1626,7 @@ namespace Unity.Netcode.RuntimeTests
where TKey : unmanaged, IEquatable<TKey>
where TVal : unmanaged
{
Debug.Log($"Changing {NativeHashMapStr(testValue)} to {NativeHashMapStr(changedValue)}");
VerboseDebug($"Changing {NativeHashMapStr(testValue)} to {NativeHashMapStr(changedValue)}");
var serverVariable = new NetworkVariable<NativeHashMap<TKey, TVal>>(testValue);
var inPlaceList = new NativeHashMap<TKey, TVal>(1, Allocator.Temp);
var clientVariable = new NetworkVariable<NativeHashMap<TKey, TVal>>(inPlaceList);
@ -2169,10 +2169,10 @@ namespace Unity.Netcode.RuntimeTests
changed2[originalSize + i] = item;
}
Debug.Log($"Original: {ArrayStr(original)}");
Debug.Log($"Changed: {ArrayStr(changed)}");
Debug.Log($"Original2: {ArrayStr(original2)}");
Debug.Log($"Changed2: {ArrayStr(changed2)}");
VerboseDebug($"Original: {ArrayStr(original)}");
VerboseDebug($"Changed: {ArrayStr(changed)}");
VerboseDebug($"Original2: {ArrayStr(original2)}");
VerboseDebug($"Changed2: {ArrayStr(changed2)}");
return (original, original2, changed, changed2);
}
@ -2464,10 +2464,10 @@ namespace Unity.Netcode.RuntimeTests
}
Debug.Log($"Original: {ListStr(original)}");
Debug.Log($"Changed: {ListStr(changed)}");
Debug.Log($"Original2: {ListStr(original2)}");
Debug.Log($"Changed2: {ListStr(changed2)}");
VerboseDebug($"Original: {ListStr(original)}");
VerboseDebug($"Changed: {ListStr(changed)}");
VerboseDebug($"Original2: {ListStr(original2)}");
VerboseDebug($"Changed2: {ListStr(changed2)}");
return (original, original2, changed, changed2);
}
@ -2531,10 +2531,10 @@ namespace Unity.Netcode.RuntimeTests
changed2.Add(item);
}
Debug.Log($"Original: {HashSetStr(original)}");
Debug.Log($"Changed: {HashSetStr(changed)}");
Debug.Log($"Original2: {HashSetStr(original2)}");
Debug.Log($"Changed2: {HashSetStr(changed2)}");
VerboseDebug($"Original: {HashSetStr(original)}");
VerboseDebug($"Changed: {HashSetStr(changed)}");
VerboseDebug($"Original2: {HashSetStr(original2)}");
VerboseDebug($"Changed2: {HashSetStr(changed2)}");
return (original, original2, changed, changed2);
}
@ -2622,10 +2622,10 @@ namespace Unity.Netcode.RuntimeTests
changed2.Add(key, val);
}
Debug.Log($"Original: {DictionaryStr(original)}");
Debug.Log($"Changed: {DictionaryStr(changed)}");
Debug.Log($"Original2: {DictionaryStr(original2)}");
Debug.Log($"Changed2: {DictionaryStr(changed2)}");
VerboseDebug($"Original: {DictionaryStr(original)}");
VerboseDebug($"Changed: {DictionaryStr(changed)}");
VerboseDebug($"Original2: {DictionaryStr(original2)}");
VerboseDebug($"Changed2: {DictionaryStr(changed2)}");
return (original, original2, changed, changed2);
}
@ -3911,10 +3911,10 @@ namespace Unity.Netcode.RuntimeTests
}
Debug.Log($"Original: {NativeListStr(original)}");
Debug.Log($"Changed: {NativeListStr(changed)}");
Debug.Log($"Original2: {NativeListStr(original2)}");
Debug.Log($"Changed2: {NativeListStr(changed2)}");
VerboseDebug($"Original: {NativeListStr(original)}");
VerboseDebug($"Changed: {NativeListStr(changed)}");
VerboseDebug($"Original2: {NativeListStr(original2)}");
VerboseDebug($"Changed2: {NativeListStr(changed2)}");
return (original, original2, changed, changed2);
}
@ -3978,10 +3978,10 @@ namespace Unity.Netcode.RuntimeTests
changed2.Add(item);
}
Debug.Log($"Original: {NativeHashSetStr(original)}");
Debug.Log($"Changed: {NativeHashSetStr(changed)}");
Debug.Log($"Original2: {NativeHashSetStr(original2)}");
Debug.Log($"Changed2: {NativeHashSetStr(changed2)}");
VerboseDebug($"Original: {NativeHashSetStr(original)}");
VerboseDebug($"Changed: {NativeHashSetStr(changed)}");
VerboseDebug($"Original2: {NativeHashSetStr(original2)}");
VerboseDebug($"Changed2: {NativeHashSetStr(changed2)}");
return (original, original2, changed, changed2);
}
@ -4070,10 +4070,10 @@ namespace Unity.Netcode.RuntimeTests
changed2.Add(key, val);
}
Debug.Log($"Original: {NativeHashMapStr(original)}");
Debug.Log($"Changed: {NativeHashMapStr(changed)}");
Debug.Log($"Original2: {NativeHashMapStr(original2)}");
Debug.Log($"Changed2: {NativeHashMapStr(changed2)}");
VerboseDebug($"Original: {NativeHashMapStr(original)}");
VerboseDebug($"Changed: {NativeHashMapStr(changed)}");
VerboseDebug($"Original2: {NativeHashMapStr(original2)}");
VerboseDebug($"Changed2: {NativeHashMapStr(changed2)}");
return (original, original2, changed, changed2);
}