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

Commit 0b31b7f

Browse files
authored
Upgrade FPS to fully use player lifecycle module (#149)
1 parent 2c7958a commit 0b31b7f

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Changed
6+
7+
- Updated the `ConnectionController` and `ClientWorkerConnector` to make full use of the updated Player Lifecycle Feature Module.
8+
59
### Internal
610

711
- Fixed package dependencies.
@@ -30,7 +34,7 @@
3034
- Now make use of nested prefabs.
3135
- Completely new set of default tiles used to populate the world.
3236
- Updated the build configuration asset.
33-
- Reduced the amount of health that gets regenerated.
37+
- Reduced the amount of health that gets regenerated.
3438
- Map generation is now asynchronous.
3539

3640
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ This starter project is designed to help you get started quickly with the [Spati
44

55
## Getting started
66

7-
For information on installing, running and playing the FPS Starter Project, please see our [getting started guide](https://docs.improbable.io/unity/alpha/content/get-started/get-started).
7+
For information on installing, running and playing the FPS Starter Project, please see our [getting started guide](https://docs.improbable.io/unity/alpha/projects/fps/get-started/get-started).
88

99
© 2019 Improbable

gdk.pinned

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bf7978a2dacfe9b95892d05d39c0b5cff348e707
1+
9ffeb3a183dcfe5407172d82eac79fdd7ec1b5e3

workers/unity/Assets/Fps/Scripts/Config/FpsEntityTemplates.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ namespace Fps
1313
{
1414
public static class FpsEntityTemplates
1515
{
16-
public static EntityTemplate Spawner()
16+
public static EntityTemplate Spawner(Coordinates spawnerCoordinates)
1717
{
18-
var position = new Position.Snapshot { Coords = new Vector3().ToSpatialCoordinates() };
19-
var metadata = new Metadata.Snapshot { EntityType = "PlayerCreator" };
18+
var position = new Position.Snapshot(spawnerCoordinates);
19+
var metadata = new Metadata.Snapshot("PlayerCreator");
2020

2121
var template = new EntityTemplate();
2222
template.AddComponent(position, WorkerUtils.UnityGameLogic);
@@ -47,7 +47,7 @@ public static EntityTemplate SimulatedPlayerCoordinatorTrigger()
4747

4848
public static EntityTemplate Player(string workerId, byte[] args)
4949
{
50-
var client = $"workerId:{workerId}";
50+
var client = EntityTemplate.GetWorkerAccessAttribute(workerId);
5151

5252
var (spawnPosition, spawnYaw, spawnPitch) = SpawnPoints.GetRandomSpawnPoint();
5353

@@ -96,7 +96,7 @@ public static EntityTemplate Player(string workerId, byte[] args)
9696
template.AddComponent(gunStateComponent, client);
9797
template.AddComponent(healthComponent, WorkerUtils.UnityGameLogic);
9898
template.AddComponent(healthRegenComponent, WorkerUtils.UnityGameLogic);
99-
PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, client, WorkerUtils.UnityGameLogic);
99+
PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, WorkerUtils.UnityGameLogic);
100100

101101
template.SetReadAccess(WorkerUtils.UnityClient, WorkerUtils.UnityGameLogic, WorkerUtils.AndroidClient, WorkerUtils.iOSClient);
102102
template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

workers/unity/Assets/Fps/Scripts/Editor/SnapshotGenerator/SnapshotMenu.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using Improbable;
23
using Improbable.Gdk.Core;
34
using Improbable.Gdk.DeploymentManager;
45
using UnityEditor;
@@ -16,8 +17,7 @@ public class SnapshotMenu : MonoBehaviour
1617

1718
private static void GenerateSnapshot(Snapshot snapshot)
1819
{
19-
var spawner = FpsEntityTemplates.Spawner();
20-
snapshot.AddEntity(spawner);
20+
snapshot.AddEntity(FpsEntityTemplates.Spawner(Coordinates.Zero));
2121
}
2222

2323
[MenuItem("SpatialOS/Generate FPS Snapshot")]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ protected override void HandleWorkerConnectionEstablished()
3232
{
3333
var world = Worker.World;
3434

35-
// Only take the Heartbeat from the PlayerLifecycleConfig Client Systems.
36-
world.GetOrCreateManager<HandlePlayerHeartbeatRequestSystem>();
35+
PlayerLifecycleHelper.AddClientSystems(world, autoRequestPlayerCreation: false);
36+
PlayerLifecycleConfig.MaxPlayerCreationRetries = 0;
3737

3838
var fallback = new GameObjectCreatorFromMetadata(Worker.WorkerType, Worker.Origin, Worker.LogDispatcher);
3939

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Improbable;
22
using Improbable.Gdk.Core;
3+
using Improbable.Gdk.PlayerLifecycle;
34
using Improbable.Gdk.Subscriptions;
45
using Improbable.PlayerLifecycle;
56
using Improbable.Worker.CInterop;
@@ -81,8 +82,8 @@ public void OnReadyToSpawn()
8182

8283
private void SpawnPlayer()
8384
{
84-
var request = new CreatePlayerRequestType();
85-
commandSender.SendCreatePlayerCommand(new EntityId(1), request, OnCreatePlayerResponse);
85+
clientWorkerConnector.Worker.World.GetExistingManager<SendCreatePlayerRequestSystem>()
86+
.RequestPlayerCreation(callback: OnCreatePlayerResponse);
8687
}
8788

8889
public void ConnectAction()

0 commit comments

Comments
 (0)