forked from FabianTerhorst/coreclr-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAltEntitySync.cs
More file actions
102 lines (86 loc) · 3.78 KB
/
AltEntitySync.cs
File metadata and controls
102 lines (86 loc) · 3.78 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
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
using System;
using System.Collections.Generic;
using System.Numerics;
using AltV.Net.EntitySync.Events;
using AltV.Net.EntitySync.SpatialPartitions;
namespace AltV.Net.EntitySync
{
public static class AltEntitySync
{
internal static IIdProvider<ulong> IdProvider;
internal static EntitySyncServer EntitySyncServer;
public static event EntityCreateDelegate OnEntityCreate
{
add => EntitySyncServer.EntityCreateCallbacks.AddLast(value);
remove => EntitySyncServer.EntityCreateCallbacks.Remove(value);
}
public static event EntityRemoveDelegate OnEntityRemove
{
add => EntitySyncServer.EntityRemoveCallbacks.AddLast(value);
remove => EntitySyncServer.EntityRemoveCallbacks.Remove(value);
}
public static void Init(ulong threadCount, Func<ulong, int> syncRate, Func<ulong, bool> netOwnerEvents,
Func<ulong, IClientRepository, NetworkLayer> createNetworkLayer,
Func<ulong, SpatialPartition> createSpatialPartition, IIdProvider<ulong> idProvider)
{
Init(threadCount, syncRate, netOwnerEvents, createNetworkLayer, (entity, tc) => (entity.Id % tc),
(entityId, entityType, tc) => (entityId % tc), createSpatialPartition,
idProvider);
}
public static void Init(ulong threadCount, Func<ulong, int> syncRate, Func<ulong, bool> netOwnerEvents,
Func<ulong, IClientRepository, NetworkLayer> createNetworkLayer,
Func<IEntity, ulong, ulong> entityThreadId,
Func<ulong, ulong, ulong, ulong> entityIdAndTypeThreadId,
Func<ulong, SpatialPartition> createSpatialPartition, IIdProvider<ulong> idProvider)
{
IdProvider = idProvider;
EntitySyncServer =
new EntitySyncServer(threadCount, syncRate, netOwnerEvents, createNetworkLayer, entityThreadId, entityIdAndTypeThreadId,
createSpatialPartition, idProvider);
}
public static void AddEntity(IEntity entity)
{
EntitySyncServer.AddEntity(entity);
}
public static void RemoveEntity(IEntity entity)
{
EntitySyncServer.RemoveEntity(entity);
}
public static void RemoveEntity(ulong id, ulong type)
{
EntitySyncServer.RemoveEntity(id, type);
}
public static bool TryGetEntity(ulong id, ulong type, out IEntity entity)
{
return EntitySyncServer.TryGetEntity(id, type, out entity);
}
public static List<IEntity> FindEntities(Vector3 position, int dimension)
{
return EntitySyncServer.FindEntities(position, dimension);
}
public static IEnumerable<IEntity> GetAllEntities()
{
return EntitySyncServer.GetAllEntities();
}
public static IEntity CreateEntity(ulong type, Vector3 position, int dimension, uint range)
{
return CreateEntity(type, position, dimension, range, new Dictionary<string, object>());
}
public static IEntity CreateEntity(ulong type, Vector3 position, int dimension, uint range,
IDictionary<string, object> data)
{
return EntitySyncServer.CreateEntity(type, position, dimension, range, data);
}
public static IEntity CreateEntityWithOwnIdManagement(ulong id, ulong type, Vector3 position, int dimension, uint range,
IDictionary<string, object> data)
{
return EntitySyncServer.CreateEntity(id, type, position, dimension, range, data);
}
public static void Stop()
{
EntitySyncServer.Stop();
EntitySyncServer = null;
IdProvider = null;
}
}
}