немного изменена логика работы TransmittedSharedObject, получается теперь, работает даже быстрее
This commit is contained in:
@@ -41,9 +41,7 @@ public class JsonSerialisationModule : ISerialisationModule
|
||||
|
||||
public void PostResponse(NetworkMessage message, int clientId)
|
||||
{
|
||||
var texted = JsonSerializer.Serialize(message);
|
||||
var binary = Encoding.UTF8.GetBytes(texted);
|
||||
_dataSource!.SendTo(clientId, binary);
|
||||
_dataSource!.SendTo(clientId, JsonSerializer.SerializeToUtf8Bytes(message));
|
||||
}
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
|
||||
@@ -14,21 +14,33 @@ public class TransmittedSharedObject<T> where T : notnull
|
||||
throw new NullReferenceException(
|
||||
"DefaultContextRepository was not defined");
|
||||
|
||||
private int _contextId = -1;
|
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public int ContextId { get; init; } = -1;
|
||||
public int ContextId
|
||||
{
|
||||
get => _contextId;
|
||||
init
|
||||
{
|
||||
_contextId = value;
|
||||
Value = GetDefaultContextRepository().GetObject<T>(_contextId)!;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public T? Value => GetDefaultContextRepository().GetObject<T>(ContextId);
|
||||
public T Value { get; private set; }
|
||||
|
||||
public TransmittedSharedObject()
|
||||
{
|
||||
}
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public TransmittedSharedObject(T value)
|
||||
{
|
||||
ContextId = GetDefaultContextRepository().GetObjectIndex(value);
|
||||
Value = value;
|
||||
_contextId = GetDefaultContextRepository().GetObjectIndex(value);
|
||||
}
|
||||
|
||||
public static implicit operator T(TransmittedSharedObject<T> value) => value.Value!;
|
||||
public static implicit operator T(TransmittedSharedObject<T> value) => value.Value;
|
||||
|
||||
public static implicit operator TransmittedSharedObject<T>(T value) =>
|
||||
new() { ContextId = GetDefaultContextRepository().GetObjectIndex(value) };
|
||||
|
||||
Reference in New Issue
Block a user