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

Commit 9ea8fd4

Browse files
authored
Remove the View (#1364)
* Remove Components from the view Remove Authority from the view Remove AuthImminentLoss support * Remove entities from View * Remove ViewStorage types * Fix up WorkerInspector to no longer use View * Move worker flags to Worker * Changelog + Upgrade guide
1 parent ad77599 commit 9ea8fd4

File tree

24 files changed

+96
-294
lines changed

24 files changed

+96
-294
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased
44

5+
### Breaking Changes
6+
7+
- The `Authority` field on Readers and Writers has been changed to `HasAuthority`. It now returns a bool to indicate whether you have authority over the component it represents. [#1364](https://github.com/spatialos/gdk-for-unity/pull/1364)
8+
- This no longer supports AuthorityImminentLoss.
9+
- ComponentUpdateSystem no longer has the API `GetAuthority`, `GetComponent`, and `HasComponent`. [#1364](https://github.com/spatialos/gdk-for-unity/pull/1364)
10+
- Use the Unity Entities `EntityManager` instead.
11+
512
### Added
613

714
- Added capability to test commands through the `MockConnectionHandler`. [#1437](https://github.com/spatialos/gdk-for-unity/pull/1437)
@@ -21,6 +28,7 @@
2128

2229
- Added C# bindings for C Event Tracing API. [#1440](https://github.com/spatialos/gdk-for-unity/pull/1440)
2330
- Added native classes for IO operations in Event Tracing API. [#1444](https://github.com/spatialos/gdk-for-unity/pull/1444)
31+
- Removed the `View` class and its generated storage classes. [#1364](https://github.com/spatialos/gdk-for-unity/pull/1364)
2432

2533
## `0.3.9` - 2020-07-24
2634

UPGRADE_GUIDE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Upgrade Guide
22

3+
## From `0.3.9` to `0.3.10`
4+
5+
### ComponentUpdateSystem API changes
6+
7+
The methods `GetAuthority`, `GetComponent`, and `HasComponent` have been removed from the `ComponentUpdateSystem`.
8+
They can be replaced by similar usage of the `EntityManager`.
9+
10+
* `componentUpdateSystem.GetAuthority(entityId, componentId)` to `EntityManager.HasComponent<ComponentType.Authority>(entity)`.
11+
* `componentUpdateSystem.GetComponent<ComponentType.Snapshot>(entityId)` to `EntityManager.GetComponentData<ComponentType.Component>(entity)`.
12+
* `componentUpdateSystem.HasComponent(componentId, entityId)` to `EntityManager.HasComponent<ComponentType.Component>(entity)`
13+
14+
The `WorkerSystem` and `ComponentDatabase` can be used to convert from `entityId` to `entity`, and from `componentId` to a component type.
15+
16+
### Readers and Writers Authority
17+
18+
The `Reader` and `Writer` classes have had their `public Authority Authority` property changed to `public bool HasAuthority`. `HasAuthority` now indicates whether you have authority over the given component or not.
19+
320
## From `0.3.7` to `0.3.8`
421

522
### Asset based entity representation

workers/unity/Assets/Playground/Scripts/MonoBehaviours/ToggleRotationCommandSender.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Improbable.Gdk.Core;
22
using Improbable.Gdk.Subscriptions;
3-
using Improbable.Worker.CInterop;
43
using UnityEngine;
54

65
namespace Playground.MonoBehaviours
@@ -16,7 +15,7 @@ public class ToggleRotationCommandSender : MonoBehaviour
1615

1716
private void Update()
1817
{
19-
if (reader.Authority != Authority.NotAuthoritative)
18+
if (reader.HasAuthority)
2019
{
2120
// Perform sending logic only on non-authoritative workers.
2221
return;

workers/unity/Packages/io.improbable.gdk.core/.codegen/Source/CoreCodegenJob.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public CoreCodegenJob(CodegenJobOptions options, IFileSystem fileSystem, Details
5656
c => ($"{c.Name}EcsViewManager.cs", UnityEcsViewManagerGenerator.Generate),
5757
c => ($"{c.Name}ComponentDiffStorage.cs", ComponentDiffStorageGenerator.Generate),
5858
c => ($"{c.Name}ComponentDiffDeserializer.cs", ComponentDiffDeserializerGenerator.Generate),
59-
c => ($"{c.Name}ViewStorage.cs", ViewStorageGenerator.Generate),
6059
c => ($"{c.Name}Metaclass.cs", MetaclassGenerator.Generate));
6160

6261
Logger.Trace("Adding job targets for commands.");

workers/unity/Packages/io.improbable.gdk.core/.codegen/Source/Generators/Core/MetaclassGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public static CodeWriter Generate(UnityComponentDetails componentDetails)
4545
public Type DiffDeserializer {{ get; }} = typeof({rootNamespace}.DiffComponentDeserializer);
4646
4747
public Type DiffStorage {{ get; }} = typeof({rootNamespace}.DiffComponentStorage);
48-
public Type ViewStorage {{ get; }} = typeof({rootNamespace}.{componentDetails.Name}ViewStorage);
4948
public Type EcsViewManager {{ get; }} = typeof({rootNamespace}.EcsViewManager);
5049
public Type DynamicInvokable {{ get; }} = typeof({rootNamespace}.{componentDetails.Name}Dynamic);
5150
");

workers/unity/Packages/io.improbable.gdk.core/Components/IComponentMetaclass.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public interface IComponentMetaclass
1818
Type DiffDeserializer { get; }
1919

2020
Type DiffStorage { get; }
21-
Type ViewStorage { get; }
2221
Type EcsViewManager { get; }
2322
Type DynamicInvokable { get; }
2423

workers/unity/Packages/io.improbable.gdk.core/Dynamic/ComponentDatabase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ public static IComponentMetaclass GetMetaclass(uint componentId)
4343
return metaclass;
4444
}
4545

46+
public static IComponentMetaclass GetMetaclass<T>() where T : ISpatialComponentData
47+
{
48+
if (!ComponentsToIds.TryGetValue(typeof(T), out var id))
49+
{
50+
throw new ArgumentException($"Can not find Metaclass for unregistered SpatialOS component {nameof(T)}.");
51+
}
52+
53+
return Metaclasses[id];
54+
}
55+
4656
public static uint GetComponentId<T>() where T : ISpatialComponentData
4757
{
4858
if (!ComponentsToIds.TryGetValue(typeof(T), out var id))

workers/unity/Packages/io.improbable.gdk.core/Subscriptions/CommandSenderReceiverSubscriptionManagerBase.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,21 @@ public override void ResetValue(ISubscription subscription)
124124
public abstract class CommandReceiverSubscriptionManagerBase<T> : SubscriptionManager<T>
125125
where T : ICommandReceiver
126126
{
127-
private readonly ComponentUpdateSystem componentUpdateSystem;
127+
private readonly EntityManager entityManager;
128128

129129
private Dictionary<EntityId, HashSet<Subscription<T>>> entityIdToReceiveSubscriptions;
130130

131131
private HashSet<EntityId> entitiesMatchingRequirements = new HashSet<EntityId>();
132132
private HashSet<EntityId> entitiesNotMatchingRequirements = new HashSet<EntityId>();
133133

134-
private readonly uint componentId;
134+
private readonly ComponentType componentAuthType;
135135

136136
protected CommandReceiverSubscriptionManagerBase(World world, uint componentId) : base(world)
137137
{
138-
this.componentId = componentId;
139-
componentUpdateSystem = world.GetExistingSystem<ComponentUpdateSystem>();
138+
var componentMetaClass = ComponentDatabase.GetMetaclass(componentId);
139+
componentAuthType = componentMetaClass.Authority;
140+
141+
entityManager = world.EntityManager;
140142

141143
var constraintSystem = world.GetExistingSystem<ComponentConstraintsCallbackSystem>();
142144

@@ -196,8 +198,7 @@ public override Subscription<T> Subscribe(EntityId entityId)
196198
}
197199

198200
if (WorkerSystem.TryGetEntity(entityId, out var entity)
199-
&& componentUpdateSystem.HasComponent(componentId, entityId)
200-
&& componentUpdateSystem.GetAuthority(entityId, componentId) != Authority.NotAuthoritative)
201+
&& entityManager.HasComponent(entity, componentAuthType))
201202
{
202203
entitiesMatchingRequirements.Add(entityId);
203204
subscription.SetAvailable(CreateReceiver(World, entity, entityId));

workers/unity/Packages/io.improbable.gdk.core/Subscriptions/Reader.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public abstract class Reader<TComponent, TUpdate> : IRequireable
1717
protected readonly EntityManager EntityManager;
1818
protected readonly Entity Entity;
1919
protected readonly EntityId EntityId;
20+
2021
private static readonly uint ComponentId = ComponentDatabase.GetComponentId<TComponent>();
22+
private static readonly ComponentType ComponentAuthType = ComponentDatabase.GetMetaclass<TComponent>().Authority;
2123

2224
private Dictionary<Action<Authority>, ulong> authorityCallbackToCallbackKey;
2325
private Dictionary<Action<TUpdate>, ulong> updateCallbackToCallbackKey;
@@ -35,16 +37,16 @@ public TComponent Data
3537
}
3638
}
3739

38-
public Authority Authority
40+
public bool HasAuthority
3941
{
4042
get
4143
{
4244
if (!IsValid)
4345
{
44-
throw new InvalidOperationException("Cannot read authority when Reader is not valid");
46+
throw new InvalidOperationException($"Cannot read {nameof(HasAuthority)} when Reader is not valid");
4547
}
4648

47-
return ComponentUpdateSystem.GetAuthority(EntityId, ComponentId);
49+
return EntityManager.HasComponent(Entity, ComponentAuthType);
4850
}
4951
}
5052

workers/unity/Packages/io.improbable.gdk.core/Subscriptions/StandardSubscriptionManagers/WorkerFlagSubscriptionManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public class WorkerFlagReader
4141
public bool IsValid;
4242

4343
private readonly WorkerFlagCallbackSystem callbackSystem;
44-
private readonly View view;
44+
private readonly WorkerSystem workerSystem;
4545

4646
private Dictionary<Action<string, string>, ulong> callbackToKey;
4747

4848
public WorkerFlagReader(World world)
4949
{
5050
IsValid = true;
5151
callbackSystem = world.GetExistingSystem<WorkerFlagCallbackSystem>();
52-
view = world.GetExistingSystem<WorkerSystem>().View;
52+
workerSystem = world.GetExistingSystem<WorkerSystem>();
5353
}
5454

5555
public event Action<string, string> OnWorkerFlagChange
@@ -92,7 +92,7 @@ public event Action<string, string> OnWorkerFlagChange
9292

9393
public string GetFlag(string name)
9494
{
95-
return view.GetWorkerFlag(name);
95+
return workerSystem.GetWorkerFlag(name);
9696
}
9797

9898
internal void RemoveAllCallbacks()

0 commit comments

Comments
 (0)