Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit b34f5c3

Browse files
author
Jamie Brynes
authored
Fix Set Kinematic When Not Authoritative not being applied correctly. (#1456)
1 parent 772a2bf commit b34f5c3

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- The 'Build Configuration' Inspector window will no longer report your Android SDK installation as missing if you have a completely fresh Unity installation with the bundled Android SDK. [#1441](https://github.com/spatialos/gdk-for-unity/pull/1441)
2828
- Fixed a bug where having spaces in the path to your project would cause the 'Local launch' and 'Launch standalone client' menu options to fail on MacOS. [#1442](https://github.com/spatialos/gdk-for-unity/pull/1442)
2929
- Fixed a faulty sync point caused by using `ComponentDataFromEntity` of the `WorkerSystem`. [#1430](https://github.com/spatialos/gdk-for-unity/pull/1430)
30+
- Fixed a bug where the Transform Sync Feature Module would not correctly apply the `Is Kinematic` option. [#1456](https://github.com/spatialos/gdk-for-unity/pull/1456)
3031

3132
### Internal
3233

workers/unity/Packages/io.improbable.gdk.transformsynchronization/Systems/DefaultApplyLatestTransformSystem.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Improbable.Gdk.Core;
55
using Unity.Entities;
66
using UnityEngine;
7+
using static Improbable.Gdk.TransformSynchronization.TransformUtils;
78

89
namespace Improbable.Gdk.TransformSynchronization
910
{
@@ -32,7 +33,7 @@ protected override void OnCreate()
3233
internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
3334
where T : class
3435
{
35-
var entityQuery = GetEntityQuery(TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: false, baseComponentTypes));
36+
var entityQuery = GetEntityQuery(ConstructEntityQueryDesc<T>(AuthorityRequirements.Exclude, baseComponentTypes));
3637

3738
applyLatestTransformActions.Add(typeof(T),
3839
() => Entities.With(entityQuery)
@@ -42,7 +43,7 @@ internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
4243

4344
private void UpdateTransformQuery()
4445
{
45-
var transformQueryDesc = TransformUtils.ConstructEntityQueryDesc<UnityEngine.Transform>(requireAuthority: false, baseComponentTypes);
46+
var transformQueryDesc = ConstructEntityQueryDesc<UnityEngine.Transform>(AuthorityRequirements.Exclude, baseComponentTypes);
4647
transformQueryDesc.None = transformQueryDesc.None
4748
.Union(
4849
applyLatestTransformActions.Keys

workers/unity/Packages/io.improbable.gdk.transformsynchronization/Systems/DefaultUpdateLatestTransformSystem.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Improbable.Gdk.Core;
55
using Unity.Entities;
66
using UnityEngine;
7+
using static Improbable.Gdk.TransformSynchronization.TransformUtils;
78

89
namespace Improbable.Gdk.TransformSynchronization
910
{
@@ -32,7 +33,7 @@ protected override void OnCreate()
3233
internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
3334
where T : class
3435
{
35-
var entityQuery = GetEntityQuery(TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: true, baseComponentTypes));
36+
var entityQuery = GetEntityQuery(ConstructEntityQueryDesc<T>(AuthorityRequirements.Require, baseComponentTypes));
3637

3738
updateLatestTransformActions.Add(typeof(T),
3839
() => Entities.With(entityQuery)
@@ -43,7 +44,7 @@ internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
4344

4445
private void UpdateTransformQuery()
4546
{
46-
var transformQueryDesc = TransformUtils.ConstructEntityQueryDesc<UnityEngine.Transform>(requireAuthority: true, baseComponentTypes);
47+
var transformQueryDesc = ConstructEntityQueryDesc<UnityEngine.Transform>(AuthorityRequirements.Require, baseComponentTypes);
4748
transformQueryDesc.None = updateLatestTransformActions.Keys
4849
.Select(ComponentType.ReadOnly)
4950
.ToArray();

workers/unity/Packages/io.improbable.gdk.transformsynchronization/Systems/ResetForAuthorityGainedSystem.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using Improbable.Gdk.Core;
55
using Unity.Entities;
6-
using UnityEngine;
6+
using static Improbable.Gdk.TransformSynchronization.TransformUtils;
77

88
namespace Improbable.Gdk.TransformSynchronization
99
{
@@ -49,7 +49,7 @@ protected override void OnCreate()
4949
internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
5050
where T : class
5151
{
52-
var componentQueryDesc = TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: true, baseComponentTypes);
52+
var componentQueryDesc = ConstructEntityQueryDesc<T>(AuthorityRequirements.Require, baseComponentTypes);
5353
componentQueryDesc.None = baseExcludeComponentTypes;
5454

5555
var entityQuery = GetEntityQuery(componentQueryDesc);
@@ -81,7 +81,7 @@ internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
8181

8282
private void UpdateTransformQuery()
8383
{
84-
var transformQueryDesc = TransformUtils.ConstructEntityQueryDesc<UnityEngine.Transform>(requireAuthority: true, baseComponentTypes);
84+
var transformQueryDesc = ConstructEntityQueryDesc<UnityEngine.Transform>(AuthorityRequirements.Require, baseComponentTypes);
8585
transformQueryDesc.None = resetAuthorityActions.Keys
8686
.Select(ComponentType.ReadOnly)
8787
.Concat(baseExcludeComponentTypes)

workers/unity/Packages/io.improbable.gdk.transformsynchronization/Systems/SetKinematicFromAuthoritySystem.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using Improbable.Gdk.Core;
55
using Unity.Entities;
6+
using static Improbable.Gdk.TransformSynchronization.TransformUtils;
67

78
namespace Improbable.Gdk.TransformSynchronization
89
{
@@ -55,15 +56,15 @@ internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
5556
private void CreateInitAction<T>(EntityQueryBuilder.F_DC<KinematicStateWhenAuth, T> initFunc)
5657
where T : class
5758
{
58-
var entityQuery = GetEntityQuery(TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: false, initBaseComponentTypes));
59+
var entityQuery = GetEntityQuery(ConstructEntityQueryDesc<T>(AuthorityRequirements.Exclude, initBaseComponentTypes));
5960

6061
initKinematicActions.Add(typeof(T), () => Entities.With(entityQuery).ForEach(initFunc));
6162
}
6263

6364
private void CreateAuthChangeAction<T>(AuthChangeFunc<T> authFunc)
6465
where T : class
6566
{
66-
var componentQueryDesc = TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: false, authBaseComponentTypes);
67+
var componentQueryDesc = ConstructEntityQueryDesc<T>(AuthorityRequirements.Ignore, authBaseComponentTypes);
6768
componentQueryDesc.None = componentQueryDesc.None
6869
.Append(ComponentType.ReadOnly<NewlyAddedSpatialOSEntity>())
6970
.ToArray();
@@ -83,7 +84,8 @@ private void CreateAuthChangeAction<T>(AuthChangeFunc<T> authFunc)
8384
return;
8485
}
8586

86-
var auth = changes[changes.Count - 1];
87+
// The first element is actually the latest value!
88+
var auth = changes[0];
8789

8890
authFunc(ref kinematicStateWhenAuth, auth, component);
8991
}));

workers/unity/Packages/io.improbable.gdk.transformsynchronization/TransformUtils.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ public static CompressedQuaternion ToCompressedQuaternion(this Quaternion quater
7070
/// <param name="baseTypes">The base set of types.</param>
7171
/// <typeparam name="T">The type to add.</typeparam>
7272
/// <returns>An <see cref="EntityQueryDesc"/> that is the union of <see cref="baseTypes"/> and typeof(<see cref="T"/>)</returns>
73-
internal static EntityQueryDesc ConstructEntityQueryDesc<T>(bool requireAuthority, params ComponentType[] baseTypes)
73+
internal static EntityQueryDesc ConstructEntityQueryDesc<T>(AuthorityRequirements authorityRequirements, params ComponentType[] baseTypes)
7474
{
7575
var componentType = ComponentType.ReadOnly<T>();
7676
var includedComponentTypes = baseTypes
7777
.Append(componentType);
7878

79-
if (requireAuthority)
79+
if (authorityRequirements == AuthorityRequirements.Require)
8080
{
8181
includedComponentTypes = includedComponentTypes
8282
.Append(ComponentType.ReadOnly<TransformInternal.HasAuthority>());
@@ -87,7 +87,7 @@ internal static EntityQueryDesc ConstructEntityQueryDesc<T>(bool requireAuthorit
8787
All = includedComponentTypes.ToArray(),
8888
};
8989

90-
if (!requireAuthority)
90+
if (authorityRequirements == AuthorityRequirements.Exclude)
9191
{
9292
componentQueryDesc.None = new[]
9393
{
@@ -97,5 +97,12 @@ internal static EntityQueryDesc ConstructEntityQueryDesc<T>(bool requireAuthorit
9797

9898
return componentQueryDesc;
9999
}
100+
101+
internal enum AuthorityRequirements
102+
{
103+
Exclude,
104+
Ignore,
105+
Require
106+
}
100107
}
101108
}

0 commit comments

Comments
 (0)