87 lines
2.1 KiB
C#
Raw Normal View History

2024-09-14 04:37:53 +08:00
using System.Collections.Concurrent;
using System.Collections.Generic;
2024-08-17 14:27:18 +08:00
using System.Linq;
using DotRecast.Core.Collections;
using JNGame.Sync.Frame.Service;
using NotImplementedException = System.NotImplementedException;
namespace JNGame.Sync.System
{
public class SDByteOperate
{
public static readonly byte[] DELETE = { 0 }; //删除
public static bool IsDelete(byte[] value)
{
return value.Length == 1 && value[0] == DELETE[0];
}
}
/// <summary>
/// 数据接口
/// </summary>
public abstract class ISData : IJNSyncId
{
/// <summary>
/// 数据唯一Id
/// </summary>
2024-08-23 10:48:19 +08:00
public ulong Id { get; set; }
2024-08-17 14:27:18 +08:00
/// <summary>
/// 判断是否一样
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public abstract bool IsEquals(ISData data);
}
public abstract class SDataSystemBase : SBaseSystem,IJNSyncCycle
{
public abstract void OnSyncStart();
2024-08-31 21:05:29 +08:00
public abstract void OnSyncUpdate(int dt);
2024-08-17 14:27:18 +08:00
public virtual void OnSyncDestroy()
{ }
}
/// <summary>
/// 状态系统 - 数据层
/// </summary>
public abstract class SDataSystem<T> : SDataSystemBase where T : ISData,new()
{
//数据Id
2024-08-23 10:48:19 +08:00
public ulong Id { get; private set; }
2024-08-17 14:27:18 +08:00
public JNRandomSystem Random => GetSystem<JNRandomSystem>();
//数据集
2024-09-14 04:37:53 +08:00
public ConcurrentDictionary<ulong, T> Data = new();
2024-08-17 14:27:18 +08:00
public virtual T[] Datas {
get
{
2024-09-14 04:37:53 +08:00
return Data.Values.ToArray();
2024-08-17 14:27:18 +08:00
}
}
public override void OnSyncStart()
{
//设置数据唯一Id
Id = Random.NextId();
}
/// <summary>
/// 返回最新数据 (收集最新的ISData数据 正常来讲只有服务端会运行)
/// </summary>
2024-09-14 04:37:53 +08:00
public virtual ConcurrentDictionary<ulong, T> GetLatest()
2024-08-17 14:27:18 +08:00
{
return new ();
}
}
}