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

@ -806,12 +806,12 @@
<Reference Include="System.Xml.Serialization">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\NetStandard\compat\2.1.0\shims\netfx\System.Xml.Serialization.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
</ItemGroup>

View File

@ -18,26 +18,9 @@ namespace JNGame.Sync.State.Tile.Entity
foreach (var entity in base.GetEntities())
{
//生命周期
bool isContains = SyncTile.IsContains(entity.Position);
bool isHost = entity.IsHost;
//更新权限
entity.HostUpdate();
//从服务器 如果数据不是自己创建的则自己永远没有权限
if (SyncTile.IsSlave && !(entity.IsSelfCreate)) isContains = false;
entity.IsHost = isContains;
//区块进入生命周期
if (!isHost && isContains)
{
entity.OnTileEnter();
}
//区块移出生命周期
if (isHost && !isContains)
{
entity.OnTileExit();
}
//判断实体是否在所属区块 在则 更新
if (entity.IsHost)
{

View File

@ -38,6 +38,8 @@ namespace JNGame.Sync.State.Tile.Entity
public abstract class JNTileEntity : JNEntity,IJNTileCycle,IJNTileEntity
{
private JNSSTileServerService SyncTile => Context.GetSync() as JNSSTileServerService;
/// <summary>
/// 是否有权限
/// </summary>
@ -84,6 +86,28 @@ namespace JNGame.Sync.State.Tile.Entity
public abstract void TileSyncData(ISTileData data);
public virtual void HostUpdate()
{
bool isContains = SyncTile.IsContains(Position);
bool isHost = IsHost;
//从服务器 如果数据不是自己创建的则自己永远没有权限
if (SyncTile.IsSlave && !(IsSelfCreate)) isContains = false;
IsHost = isContains;
//区块进入生命周期
if (!isHost && isContains)
{
OnTileEnter();
}
//区块移出生命周期
if (isHost && !isContains)
{
OnTileExit();
}
}
//区块生命周期
public virtual void OnTileEnter()
{

View File

@ -49,7 +49,7 @@ namespace JNGame.Sync.Frame.Entity
public void AddEntity(ulong id, JNEntity entity)
{
Entities.Add(id,entity as T);
Entities[id] = entity as T;
}
public void RemoveEntity(ulong id)

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);
});
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using DotRecast.Core.Collections;
using JNGame.Sync.Frame.Service;
@ -59,15 +60,12 @@ namespace JNGame.Sync.System
public JNRandomSystem Random => GetSystem<JNRandomSystem>();
//数据集
public Dictionary<ulong, T> Data = new();
public ConcurrentDictionary<ulong, T> Data = new();
public virtual T[] Datas {
get
{
lock (Data)
{
return Data.Values.ToArray();
}
return Data.Values.ToArray();
}
}
@ -80,7 +78,7 @@ namespace JNGame.Sync.System
/// <summary>
/// 返回最新数据 (收集最新的ISData数据 正常来讲只有服务端会运行)
/// </summary>
public virtual Dictionary<ulong, T> GetLatest()
public virtual ConcurrentDictionary<ulong, T> GetLatest()
{
return new ();
}

View File

@ -75,7 +75,7 @@ namespace AppGame.Sync
GetSystems<ISStateDataSystem>().ForEach(child =>
{
if (child.NetID != frame.NetID) return;
child.OnInsertUBytes(message);
child.OnInsertUBytes(message,true);
});
});
}

View File

@ -1,18 +1,12 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using AppGame;
using AppGame.Systems.CServer;
using DotRecast.Core.Collections;
using Google.Protobuf;
using JNGame.Math;
using JNGame.Sync.Entity;
using JNGame.Sync.State.Tile.Entity;
using JNGame.Sync.System;
using JNGame.Sync.System.Data;
using Newtonsoft.Json;
using Plugins.JNGame.Network.Action;
using Plugins.JNGame.Util;

View File

@ -2809,12 +2809,12 @@
<Reference Include="System.Xml.Serialization">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\NetStandard\compat\2.1.0\shims\netfx\System.Xml.Serialization.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
</ItemGroup>

View File

@ -0,0 +1,3 @@
Base path: 'C:/APP/UnityEdit/2021.3.33f1c1/Editor/Data', plugins path 'C:/APP/UnityEdit/2021.3.33f1c1/Editor/Data/PlaybackEngines'
Cmd: initializeCompiler

View File

@ -839,12 +839,12 @@
<Reference Include="System.Xml.XPath.XDocument">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\UnityReferenceAssemblies\unity-4.8-api\Facades\System.Xml.XPath.XDocument.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TestRunner">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.TestRunner.dll</HintPath>
</Reference>

View File

@ -916,12 +916,12 @@
<Reference Include="System.Xml.Serialization">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\NetStandard\compat\2.1.0\shims\netfx\System.Xml.Serialization.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="StompyRobot.SRF.csproj">

View File

@ -830,12 +830,12 @@
<Reference Include="System.Xml.XPath.XDocument">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\UnityReferenceAssemblies\unity-4.8-api\Facades\System.Xml.XPath.XDocument.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TestRunner">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.TestRunner.dll</HintPath>
</Reference>

View File

@ -861,12 +861,12 @@
<Reference Include="System.Xml.Serialization">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\NetStandard\compat\2.1.0\shims\netfx\System.Xml.Serialization.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
</ItemGroup>

View File

@ -806,12 +806,12 @@
<Reference Include="System.Xml.Serialization">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\NetStandard\compat\2.1.0\shims\netfx\System.Xml.Serialization.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="UniTask.csproj">

View File

@ -806,12 +806,12 @@
<Reference Include="System.Xml.Serialization">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\NetStandard\compat\2.1.0\shims\netfx\System.Xml.Serialization.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="UniTask.csproj">

View File

@ -826,12 +826,12 @@
<Reference Include="System.Xml.XPath.XDocument">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\UnityReferenceAssemblies\unity-4.8-api\Facades\System.Xml.XPath.XDocument.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TestRunner">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.TestRunner.dll</HintPath>
</Reference>

View File

@ -878,12 +878,12 @@
<Reference Include="System.Xml.Serialization">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\NetStandard\compat\2.1.0\shims\netfx\System.Xml.Serialization.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="UniTask.csproj">

View File

@ -810,12 +810,12 @@
<Reference Include="Unity.TextMeshPro">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="UniTask.csproj">

View File

@ -878,12 +878,12 @@
<Reference Include="System.Xml.Serialization">
<HintPath>C:\APP\UnityEdit\2021.3.33f1c1\Editor\Data\NetStandard\compat\2.1.0\shims\netfx\System.Xml.Serialization.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>D:\Jisol\JisolGame\JNFrame2\Library\ScriptAssemblies\UnityEditor.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
</ItemGroup>