This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
ComponentUpdateSystem.cs
108 lines (89 loc) · 3.78 KB
/
ComponentUpdateSystem.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System.Collections.Generic;
using Improbable.Worker.CInterop;
using Unity.Entities;
namespace Improbable.Gdk.Core
{
[DisableAutoCreation]
[AlwaysUpdateSystem]
public class ComponentUpdateSystem : ComponentSystem
{
private WorkerSystem worker;
public void SendUpdate<T>(in T update, EntityId entityId) where T : struct, ISpatialComponentUpdate
{
worker.View.UpdateComponent(entityId, in update);
worker.MessagesToSend.AddComponentUpdate(in update, entityId.Id);
}
public void SendEvent<T>(T eventToSend, EntityId entityId) where T : IEvent
{
worker.MessagesToSend.AddEvent(eventToSend, entityId.Id);
}
public ReceivedMessagesSpan<ComponentEventReceived<T>> GetEventsReceived<T>() where T : IEvent
{
var manager = (IDiffEventStorage<T>) worker.Diff.GetComponentDiffStorage(typeof(T));
return manager.GetEvents();
}
public ReceivedMessagesSpan<ComponentEventReceived<T>> GetEventsReceived<T>(EntityId entityId) where T : IEvent
{
var manager = (IDiffEventStorage<T>) worker.Diff.GetComponentDiffStorage(typeof(T));
return manager.GetEvents(entityId);
}
public ReceivedMessagesSpan<ComponentUpdateReceived<T>> GetComponentUpdatesReceived<T>()
where T : ISpatialComponentUpdate
{
var manager = (IDiffUpdateStorage<T>) worker.Diff.GetComponentDiffStorage(typeof(T));
return manager.GetUpdates();
}
public ReceivedMessagesSpan<ComponentUpdateReceived<T>> GetEntityComponentUpdatesReceived<T>(EntityId entityId)
where T : ISpatialComponentUpdate
{
var manager = (IDiffUpdateStorage<T>) worker.Diff.GetComponentDiffStorage(typeof(T));
return manager.GetUpdates(entityId);
}
public ReceivedMessagesSpan<AuthorityChangeReceived> GetAuthorityChangesReceived(uint componentId)
{
var manager = (IDiffAuthorityStorage) worker.Diff.GetComponentDiffStorage(componentId);
return manager.GetAuthorityChanges();
}
public ReceivedMessagesSpan<AuthorityChangeReceived> GetAuthorityChangesReceived(EntityId entityId,
uint componentId)
{
var manager = (IDiffAuthorityStorage) worker.Diff.GetComponentDiffStorage(componentId);
return manager.GetAuthorityChanges(entityId);
}
public List<EntityId> GetComponentsAdded(uint componentId)
{
var manager = worker.Diff.GetComponentDiffStorage(componentId);
return manager.GetComponentsAdded();
}
public List<EntityId> GetComponentsRemoved(uint componentId)
{
var manager = worker.Diff.GetComponentDiffStorage(componentId);
return manager.GetComponentsRemoved();
}
public Authority GetAuthority(EntityId entityId, uint componentId)
{
return worker.View.GetAuthority(entityId, componentId);
}
public T GetComponent<T>(EntityId entityId) where T : struct, ISpatialComponentSnapshot
{
return worker.View.GetComponent<T>(entityId);
}
public void AcknowledgeAuthorityLoss(EntityId entityId, uint componentId)
{
worker.MessagesToSend.AcknowledgeAuthorityLoss(entityId.Id, componentId);
}
public bool HasComponent(uint componentId, EntityId entityId)
{
return worker.View.HasComponent(entityId, componentId);
}
protected override void OnCreate()
{
base.OnCreate();
worker = World.GetExistingSystem<WorkerSystem>();
Enabled = false;
}
protected override void OnUpdate()
{
}
}
}