Skip to content
This repository was archived by the owner on Oct 20, 2021. It is now read-only.

Commit 5f5ce84

Browse files
author
Jamie Brynes
authored
Fast forward FPS project (#222)
1 parent b6ec644 commit 5f5ce84

File tree

10 files changed

+60
-57
lines changed

10 files changed

+60
-57
lines changed

CHANGELOG.md

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

33
## Unreleased
44

5+
### Breaking Changes
6+
7+
- The `AdvancedEntityPipeline` no longer takes an `IEntityGameObjectCreator` instance as a parameter when it is being constructed. [#222](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/222)
8+
- Instead it instantiates an `GameObjectCreatorFromMetadata` as the fallback.
9+
- This change was made as the `GameObjectCreatorFromMetadata` was being used at all call sites for the constructor.
10+
11+
### Added
12+
13+
- Added the `io.improbable.gdk.debug` package as a dependency. [#222](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/222)
14+
15+
### Changed
16+
17+
- The `AdvancedEntityPipeline` now uses the `OwningWorker` component from the PlayerLifecycle feature module [#222](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/222)
18+
- Removed the `DISABLE_REACTIVE_COMPONENTS` scripting define as it is no longer used. [#222](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/222)
19+
520
### Fixed
621

22+
- Fixed a bug where the `SimulatedPlayerWorkerCoordinator` could throw a null reference exception once the worker had disconnected. [#222](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/222)
723
- Fixed a bug where shooting a health pickup throws an exception. [#220](https://github.com/spatialos/gdk-for-unity-fps-starter-project/pull/220)
824

925
## `0.2.5` - 2019-07-18

gdk.pinned

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6689e300c017860a845fe5463b8a06b7caa1492b
1+
ec0f5ce719c2ba6db393d61d6d0fa4c6421b2bd6

spatialos.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "unity_gdk",
33
"project_version": "0.0.1",
4-
"sdk_version": "13.7.1-gdk-for-unity",
4+
"sdk_version": "13.8.2",
55
"dependencies": [
6-
{"name": "standard_library", "version": "13.7.1-gdk-for-unity"}
6+
{"name": "standard_library", "version": "13.8.2"}
77
]
88
}

workers/unity/Assets/Fps/Scripts/SetupLogic/AdvancedEntityPipeline.cs

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Improbable.Gdk.Core;
55
using Improbable.Gdk.GameObjectCreation;
66
using Improbable.Gdk.Movement;
7+
using Improbable.Gdk.PlayerLifecycle;
78
using Improbable.Gdk.StandardTypes;
89
using Improbable.Gdk.Subscriptions;
910
using UnityEngine;
@@ -13,16 +14,16 @@ namespace Fps
1314
{
1415
public class AdvancedEntityPipeline : IEntityGameObjectCreator
1516
{
16-
private const string GameobjectNameFormat = "{0}(SpatialOS {1}, Worker: {2})";
17-
private const string WorkerAttributeFormat = "workerId:{0}";
18-
private const string PlayerMetadata = "Player";
17+
private const string PlayerEntityType = "Player";
1918

2019
private readonly GameObject cachedAuthPlayer;
2120
private readonly GameObject cachedNonAuthPlayer;
2221

23-
private readonly IEntityGameObjectCreator fallback;
24-
private readonly string workerIdAttribute;
25-
private readonly WorkerInWorld worker;
22+
private readonly GameObjectCreatorFromMetadata fallback;
23+
24+
private readonly string workerId;
25+
private readonly string workerType;
26+
private readonly Vector3 workerOrigin;
2627

2728
private readonly Dictionary<EntityId, GameObject> gameObjectsCreated = new Dictionary<EntityId, GameObject>();
2829

@@ -34,58 +35,49 @@ public class AdvancedEntityPipeline : IEntityGameObjectCreator
3435
typeof(Rigidbody)
3536
};
3637

37-
public AdvancedEntityPipeline(WorkerInWorld worker, string authPlayer, string nonAuthPlayer,
38-
IEntityGameObjectCreator fallback)
38+
public AdvancedEntityPipeline(WorkerInWorld worker, string authPlayer, string nonAuthPlayer)
3939
{
40-
this.worker = worker;
41-
this.fallback = fallback;
42-
workerIdAttribute = EntityTemplate.GetWorkerAccessAttribute(worker.WorkerId);
40+
workerId = worker.WorkerId;
41+
workerType = worker.WorkerType;
42+
workerOrigin = worker.Origin;
43+
44+
fallback = new GameObjectCreatorFromMetadata(workerType, workerOrigin, worker.LogDispatcher);
4345
cachedAuthPlayer = Resources.Load<GameObject>(authPlayer);
4446
cachedNonAuthPlayer = Resources.Load<GameObject>(nonAuthPlayer);
4547
}
4648

4749
public void OnEntityCreated(SpatialOSEntity entity, EntityGameObjectLinker linker)
4850
{
49-
if (!entity.HasComponent<Metadata.Component>())
51+
if (!entity.TryGetComponent<Metadata.Component>(out var metadata))
5052
{
5153
return;
5254
}
5355

54-
var prefabName = entity.GetComponent<Metadata.Component>().EntityType;
55-
if (prefabName.Equals(PlayerMetadata))
56+
if (metadata.EntityType == PlayerEntityType)
5657
{
57-
var clientMovement = entity.GetComponent<ClientMovement.Component>();
58-
if (entity.GetComponent<EntityAcl.Component>().ComponentWriteAcl
59-
.TryGetValue(clientMovement.ComponentId, out var clientMovementWrite))
60-
{
61-
var authority = false;
62-
foreach (var attributeSet in clientMovementWrite.AttributeSet)
63-
{
64-
if (attributeSet.Attribute.Contains(workerIdAttribute))
65-
{
66-
authority = true;
67-
}
68-
}
69-
70-
var serverPosition = entity.GetComponent<ServerMovement.Component>();
71-
var position = serverPosition.Latest.Position.ToVector3() + worker.Origin;
72-
73-
var prefab = authority ? cachedAuthPlayer : cachedNonAuthPlayer;
74-
var gameObject = Object.Instantiate(prefab, position, Quaternion.identity);
75-
76-
gameObjectsCreated.Add(entity.SpatialOSEntityId, gameObject);
77-
gameObject.name = GetGameObjectName(prefab, entity, worker);
78-
linker.LinkGameObjectToSpatialOSEntity(entity.SpatialOSEntityId, gameObject, componentsToAdd);
79-
return;
80-
}
58+
CreatePlayerGameObject(entity, linker);
59+
return;
8160
}
8261

8362
fallback.OnEntityCreated(entity, linker);
8463
}
8564

86-
private static string GetGameObjectName(GameObject prefab, SpatialOSEntity entity, Worker worker)
65+
private void CreatePlayerGameObject(SpatialOSEntity entity, EntityGameObjectLinker linker)
8766
{
88-
return string.Format(GameobjectNameFormat, prefab.name, entity.SpatialOSEntityId, worker.WorkerType);
67+
if (!entity.TryGetComponent<OwningWorker.Component>(out var owningWorker))
68+
{
69+
throw new InvalidOperationException("Player entity does not have the OwningWorker component");
70+
}
71+
72+
var serverPosition = entity.GetComponent<ServerMovement.Component>();
73+
var position = serverPosition.Latest.Position.ToVector3() + workerOrigin;
74+
75+
var prefab = owningWorker.WorkerId == workerId ? cachedAuthPlayer : cachedNonAuthPlayer;
76+
var gameObject = Object.Instantiate(prefab, position, Quaternion.identity);
77+
78+
gameObjectsCreated.Add(entity.SpatialOSEntityId, gameObject);
79+
gameObject.name = $"{prefab.name}(SpatialOS {entity.SpatialOSEntityId}, Worker: {workerType})";
80+
linker.LinkGameObjectToSpatialOSEntity(entity.SpatialOSEntityId, gameObject, componentsToAdd);
8981
}
9082

9183
public void OnEntityRemoved(EntityId entityId)

workers/unity/Assets/Fps/Scripts/SetupLogic/ClientWorkerConnector.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ protected override void HandleWorkerConnectionEstablished()
109109
PlayerLifecycleHelper.AddClientSystems(world, autoRequestPlayerCreation: false);
110110
PlayerLifecycleConfig.MaxPlayerCreationRetries = 0;
111111

112-
var fallback = new GameObjectCreatorFromMetadata(Worker.WorkerType, Worker.Origin, Worker.LogDispatcher);
113-
114-
entityPipeline = new AdvancedEntityPipeline(Worker, GetAuthPlayerPrefabPath(),
115-
GetNonAuthPlayerPrefabPath(), fallback);
112+
entityPipeline = new AdvancedEntityPipeline(Worker, GetAuthPlayerPrefabPath(), GetNonAuthPlayerPrefabPath());
116113
entityPipeline.OnRemovedAuthoritativePlayer += RemovingAuthoritativePlayer;
117114

118115
// Set the Worker gameObject to the ClientWorker so it can access PlayerCreater reader/writers

workers/unity/Assets/Fps/Scripts/SetupLogic/SimulatedPlayerCoordinatorWorkerConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private async Task Monitor(int count, int interval, Func<SimulatedPlayerWorkerCo
201201
{
202202
var token = tokenSource.Token;
203203

204-
while (Worker.IsConnected)
204+
while (Worker != null && Worker.IsConnected)
205205
{
206206
if (token.IsCancellationRequested)
207207
{

workers/unity/Assets/Fps/Scripts/SetupLogic/SimulatedPlayerWorkerConnector.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ protected override void HandleWorkerConnectionEstablished()
5656
{
5757
PlayerLifecycleHelper.AddClientSystems(Worker.World, false);
5858

59-
var fallback = new GameObjectCreatorFromMetadata(Worker.WorkerType,
60-
Worker.Origin, Worker.LogDispatcher);
61-
62-
GameObjectCreationHelper.EnableStandardGameObjectCreation(
63-
Worker.World,
64-
new AdvancedEntityPipeline(Worker, AuthPlayer, NonAuthPlayer, fallback));
59+
GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World,
60+
new AdvancedEntityPipeline(Worker, AuthPlayer, NonAuthPlayer));
6561
}
6662
}
6763
}

workers/unity/Packages/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
io.improbable.gdk.buildsystem
22
io.improbable.gdk.core
3+
io.improbable.gdk.debug
34
io.improbable.gdk.deploymentlauncher
45
io.improbable.gdk.gameobjectcreation
56
io.improbable.gdk.mobile

workers/unity/Packages/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {
33
"io.improbable.gdk.buildsystem": "0.2.5",
44
"io.improbable.gdk.core": "0.2.5",
5+
"io.improbable.gdk.debug": "0.2.5",
56
"io.improbable.gdk.deploymentlauncher": "0.2.5",
67
"io.improbable.gdk.deploymentmanager": "file:io.improbable.gdk.deploymentmanager",
78
"io.improbable.gdk.gameobjectcreation": "0.2.5",

workers/unity/ProjectSettings/ProjectSettings.asset

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ PlayerSettings:
621621
webGLThreadsSupport: 0
622622
webGLWasmStreaming: 0
623623
scriptingDefineSymbols:
624-
1: UNITY_POST_PROCESSING_STACK_V2;UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP;DISABLE_REACTIVE_COMPONENTS
625-
4: UNITY_POST_PROCESSING_STACK_V2;UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP;DISABLE_REACTIVE_COMPONENTS
626-
7: UNITY_POST_PROCESSING_STACK_V2;UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP;DISABLE_REACTIVE_COMPONENTS
624+
1: UNITY_POST_PROCESSING_STACK_V2;UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP
625+
4: UNITY_POST_PROCESSING_STACK_V2;UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP
626+
7: UNITY_POST_PROCESSING_STACK_V2;UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP
627627
13: UNITY_POST_PROCESSING_STACK_V2
628628
14: UNITY_POST_PROCESSING_STACK_V2
629629
17: UNITY_POST_PROCESSING_STACK_V2

0 commit comments

Comments
 (0)