mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
public abstract class SFrameDataSystem<T> : SDataSystem<T> where T : ISData,new()
|
||||
{
|
||||
|
||||
public override void OnSyncUpdate()
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
Data = GetLatest();
|
||||
}
|
||||
|
@@ -70,6 +70,9 @@ namespace JNGame.Sync.System.Data
|
||||
|
||||
public bool isServer => Type is SStateDataEnum.ServerClient or SStateDataEnum.Server;
|
||||
public bool isClient => Type is SStateDataEnum.ServerClient or SStateDataEnum.Client;
|
||||
|
||||
//待插入的数据
|
||||
private Queue<Dictionary<ulong, byte[]>> WaitUBytes = new ();
|
||||
|
||||
protected SStateDataSystem(SStateDataEnum type)
|
||||
{
|
||||
@@ -77,8 +80,12 @@ namespace JNGame.Sync.System.Data
|
||||
}
|
||||
|
||||
|
||||
public override void OnSyncUpdate()
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
while (WaitUBytes.Count > 0)
|
||||
{
|
||||
OnUByteUpdate(WaitUBytes.Dequeue());
|
||||
}
|
||||
|
||||
//服务器: 发送最近数据
|
||||
if (isServer)
|
||||
@@ -125,8 +132,7 @@ namespace JNGame.Sync.System.Data
|
||||
/// <returns></returns>
|
||||
public void OnInsertUBytes(Dictionary<ulong, byte[]> bytes)
|
||||
{
|
||||
//提交数据更新
|
||||
OnUByteUpdate(bytes);
|
||||
WaitUBytes.Enqueue(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -78,6 +78,26 @@ namespace JNGame.Sync.System.Data
|
||||
{
|
||||
}
|
||||
|
||||
public override Dictionary<ulong, T> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<ulong, T>();
|
||||
E[] entities = null;
|
||||
if (IsMaster)
|
||||
{
|
||||
entities = NodeContext.GetHostEntities();
|
||||
}else if (IsSlave)
|
||||
{
|
||||
entities = NodeContext.GetEntities();
|
||||
}
|
||||
entities.ForEach(child =>
|
||||
{
|
||||
var entity = new T();
|
||||
entity.BindEntity(child);
|
||||
nodes.Add(child.Id,entity);
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public override void OnUByteUpdate(Dictionary<ulong, byte[]> bytes)
|
||||
{
|
||||
base.OnUByteUpdate(bytes);
|
||||
@@ -153,6 +173,9 @@ namespace JNGame.Sync.System.Data
|
||||
foreach (var keyValue in lIsTileData)
|
||||
{
|
||||
var entity = NodeContext.TileSyncCreate(keyValue.Key);
|
||||
|
||||
//如果当前是从服务器则同步的实体都是 从 主服务器 同步给 从服务器
|
||||
if (IsSlave) entity.IsSyncSlave = true;
|
||||
entity?.TileSyncData(keyValue.Value);
|
||||
//将实体绑定到数据中
|
||||
keyValue.Value.BindEntity(entity);
|
||||
@@ -164,13 +187,19 @@ namespace JNGame.Sync.System.Data
|
||||
public override void Update(T data)
|
||||
{
|
||||
var entity = NodeContext.Query(data.Id);
|
||||
if (entity is null || !entity.IsHost) return;
|
||||
if (IsMaster)
|
||||
{
|
||||
if (entity is null || !entity.IsHost) return;
|
||||
}
|
||||
base.Update(data);
|
||||
}
|
||||
public override void Add(T data)
|
||||
{
|
||||
var entity = NodeContext.Query(data.Id);
|
||||
if (entity is null || !entity.IsHost) return;
|
||||
if (IsMaster)
|
||||
{
|
||||
if (entity is null || !entity.IsHost) return;
|
||||
}
|
||||
base.Add(data);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user