This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-09-14 04:37:53 +08:00
parent 880c054c6c
commit c59ebd6280
33 changed files with 104 additions and 115 deletions

View File

@@ -46,7 +46,7 @@ namespace JNGame.Sync.System.Data
/// <summary>
/// 插入字节
/// </summary>
public void OnInsertUBytes(Dictionary<ulong, byte[]> bytes);
public void OnInsertUBytes(Dictionary<ulong, byte[]> bytes,bool isUpdate = false);
/// <summary>
/// 获取全部字节
@@ -131,11 +131,18 @@ namespace JNGame.Sync.System.Data
/// 插入字节
/// </summary>
/// <returns></returns>
public void OnInsertUBytes(Dictionary<ulong, byte[]> bytes)
public void OnInsertUBytes(Dictionary<ulong, byte[]> bytes,bool isUpdate = false)
{
if (bytes is not null)
{
WaitUBytes.Enqueue(bytes);
if (isUpdate)
{
OnUByteUpdate(bytes);
}
else
{
WaitUBytes.Enqueue(bytes);
}
}
else
{
@@ -150,15 +157,10 @@ namespace JNGame.Sync.System.Data
{
var data = new Dictionary<ulong, byte[]>();
lock (Data)
Data.ForEach(child =>
{
Data.ForEach(child =>
{
data[child.Key] = child.Value.GetByte();
});
}
data[child.Key] = child.Value.GetByte();
});
return data;
@@ -170,27 +172,24 @@ namespace JNGame.Sync.System.Data
public virtual void OnUByteUpdate(Dictionary<ulong, byte[]> bytes)
{
if (bytes is null) return;
lock (Data)
foreach (var info in bytes)
{
foreach (var info in bytes)
if (SDByteOperate.IsDelete(info.Value))
{
if (SDByteOperate.IsDelete(info.Value))
Data.Remove(info.Key,out var remove);
}
else
{
if (Data.TryGetValue(info.Key, out var value))
{
Data.Remove(info.Key);
value.UByte(info.Value);
}
else
{
if (Data.TryGetValue(info.Key, out var value))
{
value.UByte(info.Value);
}
else
{
Data[info.Key] = NewObject(info.Key,info.Value);
}
Data[info.Key] = NewObject(info.Key,info.Value);
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using AppGame.Sync;
using DotRecast.Core.Collections;
@@ -81,9 +82,9 @@ namespace JNGame.Sync.System.Data
{
}
public override Dictionary<ulong, T> GetLatest()
public override ConcurrentDictionary<ulong, T> GetLatest()
{
var nodes = new Dictionary<ulong, T>();
var nodes = new ConcurrentDictionary<ulong, T>();
E[] entities = null;
if (IsMaster)
{
@@ -96,7 +97,7 @@ namespace JNGame.Sync.System.Data
{
var entity = new T();
entity.BindEntity(child);
nodes.Add(child.Id,entity);
nodes[child.Id] = entity;
});
return nodes;
}
@@ -137,7 +138,7 @@ namespace JNGame.Sync.System.Data
Data.ForEach(child =>
{
//没有则删除
if (!(latest.ContainsKey(child.Key)))
if (NodeContext.Query(child.Key) is null)
{
Delete(child.Key);
return;
@@ -202,12 +203,7 @@ namespace JNGame.Sync.System.Data
protected virtual void OnDataSyncContext()
{
Dictionary<ulong, T> lIsTileData;
lock (Data)
{
lIsTileData = new Dictionary<ulong, T>(Data);
}
Dictionary<ulong, T> lIsTileData = new Dictionary<ulong, T>(Data);
NodeContext.GetEntities().ForEach(child =>
{
@@ -240,6 +236,7 @@ namespace JNGame.Sync.System.Data
}
entity?.TileSyncData(keyValue.Value);
entity?.HostUpdate();
//将实体绑定到数据中
keyValue.Value.BindEntity(entity);
}
@@ -266,15 +263,6 @@ namespace JNGame.Sync.System.Data
base.Add(data);
}
public override void Delete(ulong id)
{
var entity = NodeContext.Query(id);
if (entity is null)
{
base.Delete(id);
}
}
/// <summary>
/// 判断数据是否在区块内
/// </summary>
@@ -316,7 +304,7 @@ namespace JNGame.Sync.System.Data
//销毁实体
Data[child].Entity?.Destroy();
//销毁数据
Data.Remove(child);
Data.Remove(child,out var remove);
});
}