forked from FabianTerhorst/coreclr-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientDataSnapshot.cs
More file actions
47 lines (40 loc) · 1.58 KB
/
ClientDataSnapshot.cs
File metadata and controls
47 lines (40 loc) · 1.58 KB
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
using System.Collections.Generic;
namespace AltV.Net.EntitySync
{
/// <summary>
/// This contains all snapshots of entities the client visited, and a buffer to use when comparing snapshots to reduce allocations
/// </summary>
public class ClientDataSnapshot
{
// Snapshots of all entities the client visited
private readonly Dictionary<IEntity, DataSnapshot>[] snapshots;
public ClientDataSnapshot(ulong threadCount)
{
snapshots = new Dictionary<IEntity, DataSnapshot>[threadCount];
for (ulong i = 0; i < threadCount; i++)
{
snapshots[i] = new Dictionary<IEntity, DataSnapshot>();
}
}
public bool TryGetSnapshotForEntity(IEntity entity, ulong threadIndex, out DataSnapshot snapshot) =>
snapshots[threadIndex].TryGetValue(entity, out snapshot);
public bool TryGetSnapshotForEntityOnAnySnapshot(IEntity entity, out DataSnapshot snapshot)
{
for (int i = 0, length = snapshots.Length; i < length; i++)
{
if (snapshots[i].TryGetValue(entity, out snapshot))
{
return true;
}
}
snapshot = default;
return false;
}
public void SetSnapshotForEntity(IEntity entity, ulong threadIndex, DataSnapshot snapshot) =>
snapshots[threadIndex][entity] = snapshot;
public Dictionary<IEntity, DataSnapshot> GetSnapshot(ulong threadIndex)
{
return snapshots[threadIndex];
}
}
}