mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
优化属性更新逻辑
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity;
|
||||
using JNGame.Sync.Frame.Entity.Components;
|
||||
using JNGame.Sync.State.Tile.Entity.Component;
|
||||
using JNGame.Sync.System.Data;
|
||||
@@ -86,8 +87,27 @@ namespace JNGame.Sync.State.Tile.Entity
|
||||
|
||||
public abstract void TileSyncData(ISTileData data);
|
||||
|
||||
public override void OnInit(IJNContext context, ulong id = 0)
|
||||
{
|
||||
base.OnInit(context, id);
|
||||
|
||||
//如果不是Tile系统则直接拥有权限
|
||||
if (Context.GetSync() is not JNSSTileServerService)
|
||||
{
|
||||
IsHost = true;
|
||||
IsSelfCreate = true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void HostUpdate()
|
||||
{
|
||||
|
||||
//如果不是Tile系统则直接返回
|
||||
if (Context.GetSync() is not JNSSTileServerService)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isContains = SyncTile.IsContains(Position);
|
||||
bool isHost = IsHost;
|
||||
|
||||
|
@@ -50,7 +50,7 @@ namespace JNGame.Sync.Entity
|
||||
/// </summary>
|
||||
public LVector3 Position => Transform.Position;
|
||||
|
||||
public void OnInit(IJNContext context,ulong id = 0)
|
||||
public virtual void OnInit(IJNContext context,ulong id = 0)
|
||||
{
|
||||
Context = context;
|
||||
_id = id;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using UnityEngine;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
@@ -6,6 +7,16 @@ using NotImplementedException = System.NotImplementedException;
|
||||
namespace JNGame.Sync.System.Data
|
||||
{
|
||||
|
||||
public static class SDByteOperate
|
||||
{
|
||||
public static readonly byte[] Delete = { 0 }; //删除
|
||||
|
||||
public static bool IsDelete(byte[] value)
|
||||
{
|
||||
return value.Length == 1 && value[0] == Delete[0];
|
||||
}
|
||||
}
|
||||
|
||||
public enum SStateDataEnum
|
||||
{
|
||||
Server,
|
||||
@@ -57,7 +68,7 @@ namespace JNGame.Sync.System.Data
|
||||
|
||||
/// <summary>
|
||||
/// 状态同步的数据系统 (支持网络数据)
|
||||
/// 注意:帧同步也可以使用不过不建议 因为会有额外开销 除非你的游戏 经常在帧同步或者状态同步之间切换
|
||||
/// 注意:帧同步也可以使用不过不建议 因为会有额外开销 除非你的游戏 经常在帧同步或者状态同步之间切换 如果你要在帧同步系统中使用 则使用 ServerClient类型
|
||||
/// </summary>
|
||||
public abstract class SStateDataSystem<T> : SDataSystem<T>,ISStateDataSystem where T : ISStateData,new()
|
||||
{
|
||||
@@ -79,10 +90,10 @@ namespace JNGame.Sync.System.Data
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
|
||||
while (WaitUBytes.Count > 0)
|
||||
{
|
||||
OnUByteUpdate(WaitUBytes.Dequeue());
|
||||
@@ -241,7 +252,7 @@ namespace JNGame.Sync.System.Data
|
||||
/// </summary>
|
||||
public virtual void Delete(ulong id)
|
||||
{
|
||||
UBytes[id] = SDByteOperate.DELETE;
|
||||
UBytes[id] = SDByteOperate.Delete;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -76,7 +76,6 @@ namespace JNGame.Sync.System.Data
|
||||
public JNSSTileServerService TileSync => Sync as JNSSTileServerService;
|
||||
public bool IsMaster => TileSync is not null && TileSync.IsMaster;
|
||||
public bool IsSlave => TileSync is not null && TileSync.IsSlave;
|
||||
|
||||
|
||||
protected STileDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
@@ -113,6 +112,14 @@ namespace JNGame.Sync.System.Data
|
||||
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
|
||||
//如果不是Tile系统直接调用base
|
||||
if (Sync is not JNSSTileServerService)
|
||||
{
|
||||
base.OnSyncUpdate(dt);
|
||||
return;
|
||||
}
|
||||
|
||||
while (WaitUBytes.Count > 0)
|
||||
{
|
||||
OnUByteUpdate(WaitUBytes.Dequeue());
|
||||
|
@@ -1,23 +1,11 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
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>
|
||||
@@ -76,7 +64,7 @@ namespace JNGame.Sync.System
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回最新数据 (收集最新的ISData数据 正常来讲只有服务端会运行)
|
||||
/// 返回最新数据 (收集最新的ISData数据)
|
||||
/// </summary>
|
||||
public virtual ConcurrentDictionary<ulong, T> GetLatest()
|
||||
{
|
||||
|
@@ -17,7 +17,7 @@ namespace JNGame.Sync.View
|
||||
public abstract class ViewData<T> : IViewData where T : ISData
|
||||
{
|
||||
|
||||
private Dictionary<ulong, ViewGameObject> views = new();
|
||||
protected Dictionary<ulong, ViewGameObject> views = new();
|
||||
private SViewSystem root;
|
||||
public SViewSystem Root => root;
|
||||
|
||||
|
Reference in New Issue
Block a user