Skip to content
This repository has been archived by the owner on Dec 5, 2018. It is now read-only.

Commit

Permalink
upgraded to SpatialOS 11.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
johnprobable committed Jul 6, 2017
1 parent 1fb7cab commit 420b760
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 96 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@ This is a SpatialOS starter project with useful core features that you can exten

It contains:

* A Player spawned on client connection as per the [Unity Client Lifecycle Guide](https://spatialos.improbable.io/docs/reference/latest/tutorials/client-lifecycle).
* A Player spawned on client connection as per the [Unity Client Lifecycle Guide](https://spatialos.improbable.io/docs/reference/latest/tutorials/unity-client-lifecycle).
* A Cube spawned through a snapshot via an entity template method and an Unity prefab.
* The rest of the features included in the [BlankProject](https://github.com/spatialos/BlankProject).

Expand Down
17 changes: 13 additions & 4 deletions default_launch.json
Expand Up @@ -19,7 +19,18 @@
}
},
"permissions": [{
"all": {}
"entity_creation": {
"allow": true
},
"entity_deletion": {
"allow": true
},
"entity_query": {
"allow": true,
"components": [
"*"
]
}
}]
},
{
Expand All @@ -33,9 +44,7 @@
},
"entity_query": {
"allow": true,
"components": [
"*"
]
"components": []
}
}]
}
Expand Down
8 changes: 8 additions & 0 deletions schema/improbable/core/Rotation.schema
@@ -0,0 +1,8 @@
package improbable.core;

import "improbable/core/Quaternion.schema";

component Rotation {
id = 1000;
improbable.core.Quaternion rotation = 1;
}
9 changes: 0 additions & 9 deletions schema/improbable/core/WorldTransform.schema

This file was deleted.

Binary file modified snapshots/default.snapshot
Binary file not shown.
Binary file removed snapshots/initial_world.snapshot
Binary file not shown.
4 changes: 2 additions & 2 deletions spatialos.json
@@ -1,8 +1,8 @@
{
"name": "your_project_name_here",
"project_version": "1.0.0",
"sdk_version": "10.4.1",
"sdk_version": "11.0.0",
"dependencies": [
{"name": "WorkerSdkSchema", "version": "10.4.1"}
{"name": "standard_library", "version": "11.0.0"}
]
}
7 changes: 0 additions & 7 deletions workers/gsim/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions workers/gsim/spatialos.gsim.worker.json

This file was deleted.

4 changes: 0 additions & 4 deletions workers/gsim/src/main/scala/DummyMain.scala

This file was deleted.

4 changes: 4 additions & 0 deletions workers/unity/.gitignore
Expand Up @@ -16,6 +16,10 @@ Assembly-CSharp-firstpass.csproj
Assembly-CSharp.csproj
.spatialos

# Improbable Generated Build Scripts for Unity
spatialos.unity.client.build.json
spatialos.unity.worker.build.json

# Standard Unity Ignores
/[Ll]ibrary/
/[Tt]emp/
Expand Down
6 changes: 2 additions & 4 deletions workers/unity/Assets/Editor/SnapshotMenu.cs
Expand Up @@ -2,7 +2,6 @@
using Assets.Gamelogic.EntityTemplates;
using Improbable;
using Improbable.Worker;
using JetBrains.Annotations;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
Expand All @@ -13,10 +12,9 @@ namespace Assets.Editor
public class SnapshotMenu : MonoBehaviour
{
[MenuItem("Improbable/Snapshots/Generate Default Snapshot")]
[UsedImplicitly]
private static void GenerateDefaultSnapshot()
{
var snapshotEntities = new Dictionary<EntityId, SnapshotEntity>();
var snapshotEntities = new Dictionary<EntityId, Entity>();
var currentEntityId = 1;

snapshotEntities.Add(new EntityId(currentEntityId++), EntityTemplateFactory.CreatePlayerCreatorTemplate());
Expand All @@ -25,7 +23,7 @@ private static void GenerateDefaultSnapshot()
SaveSnapshot(snapshotEntities);
}

private static void SaveSnapshot(IDictionary<EntityId, SnapshotEntity> snapshotEntities)
private static void SaveSnapshot(IDictionary<EntityId, Entity> snapshotEntities)
{
File.Delete(SimulationSettings.DefaultSnapshotPath);
var maybeError = Snapshot.Save(SimulationSettings.DefaultSnapshotPath, snapshotEntities);
Expand Down
Binary file modified workers/unity/Assets/EntityPrefabs/Cube.prefab
Binary file not shown.
Binary file modified workers/unity/Assets/EntityPrefabs/Player.prefab
Binary file not shown.
Binary file modified workers/unity/Assets/EntityPrefabs/PlayerCreator.prefab
Binary file not shown.
7 changes: 4 additions & 3 deletions workers/unity/Assets/Gamelogic/Core/Bootstrap.cs
@@ -1,4 +1,5 @@
using Assets.Gamelogic.Utils;
using System;
using Assets.Gamelogic.Utils;
using Improbable;
using Improbable.Core;
using Improbable.Unity;
Expand Down Expand Up @@ -74,9 +75,9 @@ private static void RequestPlayerCreation(EntityId playerCreatorEntityId)
}

// Retry a failed creation of the Player entity after a short delay.
private static void OnCreatePlayerFailure(ICommandErrorDetails _, EntityId playerCreatorEntityId)
private static void OnCreatePlayerFailure(ICommandErrorDetails details, EntityId playerCreatorEntityId)
{
Debug.LogWarning("CreatePlayer command failed - you probably tried to connect too soon. Try again in a few seconds.");
Debug.LogWarningFormat("CreatePlayer command failed. Status code = {0}. - you probably tried to connect too soon. Try again in a few seconds.", details.StatusCode.ToString());
TimerUtils.WaitAndPerform(SimulationSettings.PlayerEntityCreationRetrySecs, () => RequestPlayerCreation(playerCreatorEntityId));
}
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ private CreatePlayerResponse OnCreatePlayer(CreatePlayerRequest request, IComman
private void CreatePlayerWithReservedId(string clientWorkerId)
{
SpatialOS.Commands.ReserveEntityId(PlayerCreationWriter)
.OnSuccess(reservedEntityId => CreatePlayer(clientWorkerId, reservedEntityId))
.OnSuccess(result => CreatePlayer(clientWorkerId, result.ReservedEntityId))
.OnFailure(failure => OnFailedReservation(failure, clientWorkerId));
}

Expand All @@ -47,7 +47,7 @@ private void OnFailedReservation(ICommandErrorDetails response, string clientWor
private void CreatePlayer(string clientWorkerId, EntityId entityId)
{
var playerEntityTemplate = EntityTemplateFactory.CreatePlayerTemplate(clientWorkerId);
SpatialOS.Commands.CreateEntity(PlayerCreationWriter, entityId, SimulationSettings.PlayerPrefabName, playerEntityTemplate)
SpatialOS.Commands.CreateEntity(PlayerCreationWriter, entityId, playerEntityTemplate)
.OnFailure(failure => OnFailedPlayerCreation(failure, clientWorkerId, entityId));
}

Expand Down
33 changes: 22 additions & 11 deletions workers/unity/Assets/Gamelogic/Core/TransformReceiver.cs
@@ -1,39 +1,50 @@
using Assets.Gamelogic.Utils;
using Improbable;
using Improbable.Core;
using Improbable.Unity.CodeGeneration;
using Improbable.Unity.Visualizer;
using UnityEngine;

namespace Assets.Gamelogic.Core
{
public class TransformReceiver : MonoBehaviour
{
[Require]
private WorldTransform.Reader WorldTransformReader;
[Require] private Position.Reader PositionReader;
[Require] private Rotation.Reader RotationReader;

void OnEnable()
{
transform.position = WorldTransformReader.Data.position.ToVector3();
transform.rotation = MathUtils.ToUnityQuaternion(WorldTransformReader.Data.rotation);
transform.position = PositionReader.Data.coords.ToUnityVector();
transform.rotation = MathUtils.ToUnityQuaternion(RotationReader.Data.rotation);

WorldTransformReader.ComponentUpdated.Add(OnComponentUpdated);
PositionReader.ComponentUpdated.Add(OnPositionUpdated);
RotationReader.ComponentUpdated.Add(OnRotationUpdated);
}

void OnDisable()
{
WorldTransformReader.ComponentUpdated.Remove(OnComponentUpdated);
PositionReader.ComponentUpdated.Remove(OnPositionUpdated);
RotationReader.ComponentUpdated.Remove(OnRotationUpdated);
}

void OnComponentUpdated(WorldTransform.Update update)
void OnPositionUpdated(Position.Update update)
{
if (!WorldTransformReader.HasAuthority)
if (!PositionReader.HasAuthority)
{
if (update.position.HasValue)
if (update.coords.HasValue)
{
transform.position = update.position.Value.ToVector3();
transform.position = update.coords.Value.ToUnityVector();
}
}
}

void OnRotationUpdated(Rotation.Update update)
{
if (!RotationReader.HasAuthority)
{
if (update.rotation.HasValue)
{
transform.rotation = MathUtils.ToUnityQuaternion(WorldTransformReader.Data.rotation);
transform.rotation = MathUtils.ToUnityQuaternion(update.rotation.Value);
}
}
}
Expand Down
@@ -1,57 +1,55 @@
using Assets.Gamelogic.Core;
using Improbable;
using Improbable.Core;
using Improbable.Math;
using Improbable.Player;
using Improbable.Unity.Core.Acls;
using Improbable.Worker;
using Quaternion = Improbable.Core.Quaternion;
using UnityEngine;
using Improbable.Unity.Entity;

namespace Assets.Gamelogic.EntityTemplates
{
public class EntityTemplateFactory : MonoBehaviour
{
public static SnapshotEntity CreatePlayerCreatorTemplate()
public static Entity CreatePlayerCreatorTemplate()
{
var playerCreatorEntityTemplate = new SnapshotEntity { Prefab = SimulationSettings.PlayerCreatorPrefabName };

playerCreatorEntityTemplate.Add(new WorldTransform.Data(Coordinates.ZERO, new Quaternion(0,0,0,0)));
playerCreatorEntityTemplate.Add(new PlayerCreation.Data());

var acl = Acl.GenerateServerAuthoritativeAcl(playerCreatorEntityTemplate);
playerCreatorEntityTemplate.SetAcl(acl);
var playerCreatorEntityTemplate = EntityBuilder.Begin()
.AddPositionComponent(Improbable.Coordinates.ZERO.ToUnityVector(), CommonRequirementSets.PhysicsOnly)
.AddMetadataComponent(entityType: SimulationSettings.CubePrefabName)
.SetPersistence(true)
.SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
.AddComponent(new Rotation.Data(new Quaternion(0, 0, 0, 0)), CommonRequirementSets.PhysicsOnly)
.AddComponent(new PlayerCreation.Data(), CommonRequirementSets.PhysicsOnly)
.Build();

return playerCreatorEntityTemplate;
}

public static Entity CreatePlayerTemplate(string clientId)
{
var playerTemplate = new SnapshotEntity { Prefab = SimulationSettings.PlayerPrefabName };

playerTemplate.Add(new WorldTransform.Data(Coordinates.ZERO, new Quaternion(0, 0, 0, 0)));
playerTemplate.Add(new ClientAuthorityCheck.Data());
playerTemplate.Add(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout));

var acl = Acl.Build()
.SetReadAccess(CommonRequirementSets.PhysicsOrVisual)
.SetWriteAccess<WorldTransform>(CommonRequirementSets.PhysicsOnly)
.SetWriteAccess<ClientAuthorityCheck>(CommonRequirementSets.SpecificClientOnly(clientId))
.SetWriteAccess<ClientConnection>(CommonRequirementSets.PhysicsOnly);
playerTemplate.SetAcl(acl);
var playerTemplate = EntityBuilder.Begin()
.AddPositionComponent(Improbable.Coordinates.ZERO.ToUnityVector(), CommonRequirementSets.PhysicsOnly)
.AddMetadataComponent(entityType: SimulationSettings.PlayerPrefabName)
.SetPersistence(false)
.SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
.AddComponent(new Rotation.Data(new Quaternion(0,0,0,0)), CommonRequirementSets.PhysicsOnly)
.AddComponent(new ClientAuthorityCheck.Data(), CommonRequirementSets.SpecificClientOnly(clientId))
.AddComponent(new ClientConnection.Data(SimulationSettings.TotalHeartbeatsBeforeTimeout), CommonRequirementSets.PhysicsOnly)
.Build();

return playerTemplate;
}

public static SnapshotEntity CreateCubeTemplate()
public static Entity CreateCubeTemplate()
{
var cubeTemplate = new SnapshotEntity { Prefab = SimulationSettings.CubePrefabName };

cubeTemplate.Add(new WorldTransform.Data(new Coordinates(0,0,5), new Quaternion(0, 0, 0, 0)));

var acl = Acl.Build()
.SetReadAccess(CommonRequirementSets.PhysicsOrVisual)
.SetWriteAccess<WorldTransform>(CommonRequirementSets.PhysicsOnly);
cubeTemplate.SetAcl(acl);
var cubeTemplate = EntityBuilder.Begin()
.AddPositionComponent(Improbable.Coordinates.ZERO.ToUnityVector(), CommonRequirementSets.PhysicsOnly)
.AddMetadataComponent(entityType: SimulationSettings.CubePrefabName)
.SetPersistence(true)
.SetReadAcl(CommonRequirementSets.PhysicsOrVisual)
.AddComponent(new Rotation.Data(new Quaternion(0, 0, 0, 0)), CommonRequirementSets.PhysicsOnly)
.Build();

return cubeTemplate;
}
Expand Down
10 changes: 1 addition & 9 deletions workers/unity/Assets/Gamelogic/Utils/MathUtils.cs
@@ -1,4 +1,4 @@
using Improbable.Math;
using Improbable;
using UnityEngine;

namespace Assets.Gamelogic.Utils
Expand All @@ -15,12 +15,4 @@ public static Improbable.Core.Quaternion ToNativeQuaternion(Quaternion quaternio
return new Improbable.Core.Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
}
}

public static class CoordinatesExtensions
{
public static Vector3 ToVector3(this Coordinates coordinates)
{
return new Vector3((float)coordinates.X, (float)coordinates.Y, (float)coordinates.Z);
}
}
}
Binary file modified workers/unity/Assets/UnityClient.unity
Binary file not shown.
Binary file modified workers/unity/Assets/UnityWorker.unity
Binary file not shown.
2 changes: 1 addition & 1 deletion workers/unity/ProjectSettings/ProjectVersion.txt
@@ -1 +1 @@
m_EditorVersion: 5.5.2f1
m_EditorVersion: 5.5.3f1
6 changes: 3 additions & 3 deletions workers/unity/spatialos.UnityWorker.worker.json
Expand Up @@ -28,7 +28,7 @@
"+appName",
"${IMPROBABLE_PROJECT_NAME}",
"+receptionistIp",
"${IMPROBABLE_RECEPTIONIST_IP}",
"${IMPROBABLE_RECEPTIONIST_HOST}",
"+receptionistPort",
"${IMPROBABLE_RECEPTIONIST_PORT}",
"+workerType",
Expand Down Expand Up @@ -56,7 +56,7 @@
"+appName",
"${IMPROBABLE_PROJECT_NAME}",
"+receptionistIp",
"${IMPROBABLE_RECEPTIONIST_IP}",
"${IMPROBABLE_RECEPTIONIST_HOST}",
"+receptionistPort",
"${IMPROBABLE_RECEPTIONIST_PORT}",
"+workerType",
Expand Down Expand Up @@ -84,7 +84,7 @@
"+appName",
"${IMPROBABLE_PROJECT_NAME}",
"+receptionistIp",
"${IMPROBABLE_RECEPTIONIST_IP}",
"${IMPROBABLE_RECEPTIONIST_HOST}",
"+receptionistPort",
"${IMPROBABLE_RECEPTIONIST_PORT}",
"+workerType",
Expand Down

0 comments on commit 420b760

Please sign in to comment.