This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-10-17 02:12:03 +08:00
parent c85f350e0a
commit dd2e0e8a46
16 changed files with 52 additions and 611 deletions

View File

@@ -7,7 +7,7 @@
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using DotRecast.Core.Collections;
using Google.Protobuf;
using JNGame.Network.Entity;
using JNGame.Network.Util;
@@ -92,10 +91,10 @@ namespace JNGame.Network
if (hId == 0)
{
int size = 0;
_byteSize.ForEach(child =>
foreach (var child in _byteSize)
{
size += child.Value;
});
}
return size;
}
return _byteSize.GetValueOrDefault(hId, 0);

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using DotRecast.Core.Collections;
using JNGame.Runtime.System;
using JNGame.Util;
@@ -61,10 +60,10 @@ namespace JNGame.Network
int size = 0;
try
{
_byteSize.ForEach(child =>
foreach (var child in _byteSize)
{
size += child.Value;
});
}
}
catch (Exception e)
{

View File

@@ -2,7 +2,6 @@
using System;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using DotRecast.Core.Collections;
using Google.Protobuf;
using JNGame.Network.Action;
using JNGame.Network.Entity;
@@ -142,13 +141,13 @@ namespace JNGame.Network
public void AllSend(int hId,IMessage data = null,Func<SocketClient,bool> filter = null)
{
filter ??= (SocketClient client) => true;
service.GetClients().ForEach(client =>
foreach (var client in service.GetClients())
{
if (filter(client))
{
Send(client, hId, data);
}
});
}
}
}

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using DotRecast.Core.Collections;
using JNGame.Math;
using JNGame.Runtime.Util;
using JNGame.Sync.State.Tile;
@@ -38,11 +37,11 @@ namespace JNGame.Sync.Debuger
DrawContains(service.MaxContains,service.MinContains,Color.red);
//绘制连接区域
service.GetLinkTiles().ForEach(index =>
foreach (var linkTile in service.GetLinkTiles())
{
(LVector2 max, LVector2 min) = service.GetTileContains(index);
(LVector2 max, LVector2 min) = service.GetTileContains(linkTile);
DrawContains(max,min,Color.cyan);
});
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using DotRecast.Core.Collections;
using Entitas;
using JNGame.Runtime.Sync;
using JNGame.Sync.Entity;
@@ -104,13 +103,13 @@ namespace JNGame.Sync.Frame.Entity
//生效延迟销毁
public void DelayDestroy()
{
GetEntities().ForEach(child =>
foreach (var child in GetEntities())
{
if (child.IsDelayDestroy)
{
child.Destroy();
}
});
}
}
//生命周期

View File

@@ -1,6 +1,4 @@
using System;
using System.Linq;
using DotRecast.Core.Collections;
using JNGame.Math;
using JNGame.Sync.Entity.Component;
using JNGame.Sync.Frame.Entity;
@@ -107,7 +105,10 @@ namespace JNGame.Sync.Entity
public override void RemoveAllComponents()
{
GetComponents().ForEach(child => (child as JNComponent)?.OnSyncDestroy());
foreach (var child in GetComponents())
{
(child as JNComponent)?.OnSyncDestroy();
}
base.RemoveAllComponents();
}

View File

@@ -1,7 +1,5 @@
using System.Collections.Generic;
using DotRecast.Core.Collections;
using UnityEngine;
using NotImplementedException = System.NotImplementedException;
namespace JNGame.Sync.System.Data
{
@@ -102,7 +100,7 @@ namespace JNGame.Sync.System.Data
if (isServer)
{
var latest = GetLatest();
latest.Keys.ForEach(key =>
foreach (var key in latest.Keys)
{
if (Data.ContainsKey(key))
{
@@ -114,12 +112,12 @@ namespace JNGame.Sync.System.Data
//如果之前没有则添加
Add(latest[key]);
}
});
Data.ForEach(child =>
}
foreach (var child in Data)
{
//没有则删除
if (!(latest.ContainsKey(child.Key))) Delete(child.Key);
});
}
if (UBytes.Count > 0)
{
OnUByteUpdate(UBytes);
@@ -167,10 +165,10 @@ namespace JNGame.Sync.System.Data
{
var data = new Dictionary<ulong, byte[]>();
Data.ForEach(child =>
foreach (var child in Data)
{
data[child.Key] = child.Value.GetByte();
});
}
return data;

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using DotRecast.Core.Collections;
using JNGame.Math;
using JNGame.Sync.State.Tile;
using JNGame.Sync.State.Tile.Entity;
@@ -88,12 +87,12 @@ namespace JNGame.Sync.System.Data
{
entities = NodeContext.GetEntities();
}
entities.ForEach(child =>
foreach (var child in entities)
{
var entity = new T();
entity.BindEntity(child);
nodes[child.Id] = entity;
});
}
return nodes;
}
@@ -125,7 +124,7 @@ namespace JNGame.Sync.System.Data
if (isServer)
{
var latest = GetLatest();
latest.Keys.ForEach(key =>
foreach (var key in latest.Keys)
{
if (Data.ContainsKey(key))
{
@@ -137,8 +136,8 @@ namespace JNGame.Sync.System.Data
//如果之前没有则添加
Add(latest[key]);
}
});
Data.ForEach(child =>
}
foreach (var child in Data)
{
//没有则删除
if (NodeContext.Query(child.Key) is null)
@@ -152,8 +151,7 @@ namespace JNGame.Sync.System.Data
child.Value.IsActiveSyncOnce = false;
UBytes[child.Key] = child.Value.GetByte();
}
});
}
if (UBytes.Count > 0)
{
OnUByteUpdate(UBytes);
@@ -170,7 +168,7 @@ namespace JNGame.Sync.System.Data
Dictionary<ulong, byte[]> master = new Dictionary<ulong, byte[]>();
Dictionary<ulong, byte[]> slave = new Dictionary<ulong, byte[]>();
all.ForEach(keyValue =>
foreach (var keyValue in all)
{
var entity = NodeContext.Query(keyValue.Key);
//给从服务器发送数据
@@ -178,7 +176,7 @@ namespace JNGame.Sync.System.Data
{
slave[keyValue.Key] = keyValue.Value;
}
});
}
OnSendAllData(all);
OnSendMasterData(master);
@@ -220,7 +218,7 @@ namespace JNGame.Sync.System.Data
}
}
NodeContext.GetEntities().ForEach(child =>
foreach (var child in NodeContext.GetEntities())
{
//如果有则删除
if (lIsTileData.Remove(child.Id,out var data))
@@ -234,7 +232,7 @@ namespace JNGame.Sync.System.Data
if (IsSlave) data.IsActiveSyncOnce = true;
}
}
});
}
//将数据同步到实体中
foreach (var keyValue in lIsTileData)
@@ -308,10 +306,10 @@ namespace JNGame.Sync.System.Data
//需要删除的数据Id
var ids = new List<ulong>();
Data.ForEach(child =>
foreach (var child in Data)
{
if (IsTileInside(index,child.Value)) ids.Add(child.Key);
});
}
//删除数据和实体
ids.ForEach(child =>
@@ -343,14 +341,14 @@ namespace JNGame.Sync.System.Data
lock (Data)
{
Data.ForEach(child =>
foreach (var child in Data)
{
var entity = NodeContext.Query(child.Key);
if (entity is not null && entity.IsHost && filter(entity))
{
data[child.Key] = child.Value.GetByte();
}
});
}
}
return data;
@@ -366,14 +364,14 @@ namespace JNGame.Sync.System.Data
lock (Data)
{
Data.ForEach(child =>
foreach (var child in Data)
{
var entity = NodeContext.Query(child.Key);
if (IsTileInside(index,child.Value) && filter(entity))
{
data[child.Key] = child.Value.GetByte();
}
});
}
}
return data;