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

Commit

Permalink
Fix Set Kinematic When Not Authoritative not being applied correctl…
Browse files Browse the repository at this point in the history
…y. (#1456)
  • Loading branch information
Jamie Brynes authored Aug 17, 2020
1 parent 772a2bf commit b34f5c3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- 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)
- 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)
- Fixed a faulty sync point caused by using `ComponentDataFromEntity` of the `WorkerSystem`. [#1430](https://github.com/spatialos/gdk-for-unity/pull/1430)
- 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)

### Internal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Improbable.Gdk.Core;
using Unity.Entities;
using UnityEngine;
using static Improbable.Gdk.TransformSynchronization.TransformUtils;

namespace Improbable.Gdk.TransformSynchronization
{
Expand Down Expand Up @@ -32,7 +33,7 @@ protected override void OnCreate()
internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
where T : class
{
var entityQuery = GetEntityQuery(TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: false, baseComponentTypes));
var entityQuery = GetEntityQuery(ConstructEntityQueryDesc<T>(AuthorityRequirements.Exclude, baseComponentTypes));

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

private void UpdateTransformQuery()
{
var transformQueryDesc = TransformUtils.ConstructEntityQueryDesc<UnityEngine.Transform>(requireAuthority: false, baseComponentTypes);
var transformQueryDesc = ConstructEntityQueryDesc<UnityEngine.Transform>(AuthorityRequirements.Exclude, baseComponentTypes);
transformQueryDesc.None = transformQueryDesc.None
.Union(
applyLatestTransformActions.Keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Improbable.Gdk.Core;
using Unity.Entities;
using UnityEngine;
using static Improbable.Gdk.TransformSynchronization.TransformUtils;

namespace Improbable.Gdk.TransformSynchronization
{
Expand Down Expand Up @@ -32,7 +33,7 @@ protected override void OnCreate()
internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
where T : class
{
var entityQuery = GetEntityQuery(TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: true, baseComponentTypes));
var entityQuery = GetEntityQuery(ConstructEntityQueryDesc<T>(AuthorityRequirements.Require, baseComponentTypes));

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

private void UpdateTransformQuery()
{
var transformQueryDesc = TransformUtils.ConstructEntityQueryDesc<UnityEngine.Transform>(requireAuthority: true, baseComponentTypes);
var transformQueryDesc = ConstructEntityQueryDesc<UnityEngine.Transform>(AuthorityRequirements.Require, baseComponentTypes);
transformQueryDesc.None = updateLatestTransformActions.Keys
.Select(ComponentType.ReadOnly)
.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using Improbable.Gdk.Core;
using Unity.Entities;
using UnityEngine;
using static Improbable.Gdk.TransformSynchronization.TransformUtils;

namespace Improbable.Gdk.TransformSynchronization
{
Expand Down Expand Up @@ -49,7 +49,7 @@ protected override void OnCreate()
internal void RegisterTransformSyncType<T>(ITransformSync<T> impl)
where T : class
{
var componentQueryDesc = TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: true, baseComponentTypes);
var componentQueryDesc = ConstructEntityQueryDesc<T>(AuthorityRequirements.Require, baseComponentTypes);
componentQueryDesc.None = baseExcludeComponentTypes;

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

private void UpdateTransformQuery()
{
var transformQueryDesc = TransformUtils.ConstructEntityQueryDesc<UnityEngine.Transform>(requireAuthority: true, baseComponentTypes);
var transformQueryDesc = ConstructEntityQueryDesc<UnityEngine.Transform>(AuthorityRequirements.Require, baseComponentTypes);
transformQueryDesc.None = resetAuthorityActions.Keys
.Select(ComponentType.ReadOnly)
.Concat(baseExcludeComponentTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Improbable.Gdk.Core;
using Unity.Entities;
using static Improbable.Gdk.TransformSynchronization.TransformUtils;

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

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

private void CreateAuthChangeAction<T>(AuthChangeFunc<T> authFunc)
where T : class
{
var componentQueryDesc = TransformUtils.ConstructEntityQueryDesc<T>(requireAuthority: false, authBaseComponentTypes);
var componentQueryDesc = ConstructEntityQueryDesc<T>(AuthorityRequirements.Ignore, authBaseComponentTypes);
componentQueryDesc.None = componentQueryDesc.None
.Append(ComponentType.ReadOnly<NewlyAddedSpatialOSEntity>())
.ToArray();
Expand All @@ -83,7 +84,8 @@ private void CreateAuthChangeAction<T>(AuthChangeFunc<T> authFunc)
return;
}

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

authFunc(ref kinematicStateWhenAuth, auth, component);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public static CompressedQuaternion ToCompressedQuaternion(this Quaternion quater
/// <param name="baseTypes">The base set of types.</param>
/// <typeparam name="T">The type to add.</typeparam>
/// <returns>An <see cref="EntityQueryDesc"/> that is the union of <see cref="baseTypes"/> and typeof(<see cref="T"/>)</returns>
internal static EntityQueryDesc ConstructEntityQueryDesc<T>(bool requireAuthority, params ComponentType[] baseTypes)
internal static EntityQueryDesc ConstructEntityQueryDesc<T>(AuthorityRequirements authorityRequirements, params ComponentType[] baseTypes)
{
var componentType = ComponentType.ReadOnly<T>();
var includedComponentTypes = baseTypes
.Append(componentType);

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

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

return componentQueryDesc;
}

internal enum AuthorityRequirements
{
Exclude,
Ignore,
Require
}
}
}

0 comments on commit b34f5c3

Please sign in to comment.