This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
SpatialOSReceiveSystem.cs
60 lines (52 loc) · 1.89 KB
/
SpatialOSReceiveSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using Improbable.Gdk.Core.NetworkStats;
using Unity.Entities;
using UnityEngine;
using UnityEngine.Profiling;
namespace Improbable.Gdk.Core
{
/// <summary>
/// Receives incoming messages from the SpatialOS runtime.
/// </summary>
[DisableAutoCreation]
[UpdateInGroup(typeof(SpatialOSReceiveGroup.InternalSpatialOSReceiveGroup))]
public class SpatialOSReceiveSystem : ComponentSystem
{
private WorkerSystem worker;
private EcsViewSystem ecsViewSystem;
private EntitySystem entitySystem;
private NetworkStatisticsSystem networkStatisticsSystem;
protected override void OnCreate()
{
base.OnCreate();
worker = World.GetExistingSystem<WorkerSystem>();
ecsViewSystem = World.GetOrCreateSystem<EcsViewSystem>();
entitySystem = World.GetOrCreateSystem<EntitySystem>();
networkStatisticsSystem = World.GetOrCreateSystem<NetworkStatisticsSystem>();
}
protected override void OnUpdate()
{
try
{
Profiler.BeginSample("GetMessages");
worker.Tick();
Profiler.EndSample();
var diff = worker.Diff;
Profiler.BeginSample("ApplyDiff ECS");
ecsViewSystem.ApplyDiff(diff);
Profiler.EndSample();
Profiler.BeginSample("ApplyDiff Entity");
entitySystem.ApplyDiff(diff);
Profiler.EndSample();
Profiler.BeginSample("ApplyDiff Networking Statistics");
networkStatisticsSystem.ApplyDiff(diff);
Profiler.EndSample();
}
catch (Exception e)
{
worker.LogDispatcher.HandleLog(LogType.Exception, new LogEvent("Exception:")
.WithException(e));
}
}
}
}