mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
修复主从交互bug
This commit is contained in:
@@ -26,6 +26,6 @@ namespace JNGame.Sync.State.Tile.Entity.Component
|
||||
public virtual void OnTileEnter(){}
|
||||
|
||||
public virtual void OnTileExit(){}
|
||||
|
||||
public void OnTileSlaveExit(){}
|
||||
}
|
||||
}
|
@@ -125,6 +125,7 @@ namespace JNGame.Sync.State.Tile.Entity
|
||||
if (isHost && !isContains)
|
||||
{
|
||||
OnTileExit();
|
||||
if (SyncTile.IsSlave) OnTileSlaveExit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,5 +148,13 @@ namespace JNGame.Sync.State.Tile.Entity
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnTileSlaveExit()
|
||||
{
|
||||
//给组件生命周期
|
||||
foreach (var component in GetComponents())
|
||||
{
|
||||
(component as JNTileComponent)?.OnTileSlaveExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,5 +13,10 @@
|
||||
/// </summary>
|
||||
public void OnTileExit();
|
||||
|
||||
/// <summary>
|
||||
/// 从服务器 - 退出当前区块
|
||||
/// </summary>
|
||||
public void OnTileSlaveExit();
|
||||
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using Entitas;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity.Component.Components;
|
||||
@@ -17,18 +18,20 @@ namespace JNGame.Sync.Frame.Entity
|
||||
|
||||
//方便查抄的实体Map
|
||||
public Dictionary<ulong, T> Entities = new ();
|
||||
|
||||
public JNContext(): base((new T()).NewCLookup().Count, () => new T())
|
||||
|
||||
public JNContext()
|
||||
: this((new T()).NewCLookup().Count, () => new T())
|
||||
{
|
||||
CLookup = (new T()).NewCLookup();
|
||||
}
|
||||
|
||||
public JNContext(int totalComponents, Func<T> entityFactory) : base(totalComponents, entityFactory)
|
||||
public JNContext(int totalComponents, Func<T> entityFactory) : this(totalComponents, 0, null, null, entityFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public JNContext(int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func<IEntity, IAERC> aercFactory, Func<T> entityFactory) : base(totalComponents, startCreationIndex, contextInfo, aercFactory, entityFactory)
|
||||
public JNContext(int totalComponents, int startCreationIndex, ContextInfo contextInfo, Func<IEntity, IAERC> aercFactory, Func<T> entityFactory)
|
||||
: base(totalComponents, startCreationIndex, contextInfo, aercFactory, entityFactory)
|
||||
{
|
||||
CLookup = (new T()).NewCLookup();
|
||||
}
|
||||
|
||||
public JNSyncService GetSync()
|
||||
@@ -96,8 +99,20 @@ namespace JNGame.Sync.Frame.Entity
|
||||
BindLifeCycle(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
//生效延迟销毁
|
||||
public void DelayDestroy()
|
||||
{
|
||||
GetEntities().ForEach(child =>
|
||||
{
|
||||
if (child.IsDelayDestroy)
|
||||
{
|
||||
child.Destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//帧同步 生命周期
|
||||
//生命周期
|
||||
public virtual void OnSyncStart(){}
|
||||
|
||||
public virtual void OnSyncUpdate(int dt)
|
||||
@@ -122,6 +137,7 @@ namespace JNGame.Sync.Frame.Entity
|
||||
public abstract void InitReference(JNSyncService data);
|
||||
public void AddEntity(ulong id,JNEntity entity);
|
||||
public void RemoveEntity(ulong id);
|
||||
public void DelayDestroy();
|
||||
|
||||
}
|
||||
|
||||
|
@@ -19,12 +19,18 @@ namespace JNGame.Sync.Entity
|
||||
}
|
||||
|
||||
//给所有实体推帧
|
||||
public void Simulate()
|
||||
public virtual void Simulate()
|
||||
{
|
||||
for (var i = 0; i < allContexts.Length; i++)
|
||||
{
|
||||
(allContexts[i] as IJNContext)?.OnSyncUpdate(Sync.DeltaTime);
|
||||
}
|
||||
|
||||
//延迟销毁
|
||||
for (var i = 0; i < allContexts.Length; i++)
|
||||
{
|
||||
(allContexts[i] as IJNContext)?.DelayDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
public T GetContext<T>() where T : IContext
|
||||
|
@@ -50,6 +50,8 @@ namespace JNGame.Sync.Entity
|
||||
/// </summary>
|
||||
public LVector3 Position => Transform.Position;
|
||||
|
||||
public bool IsDelayDestroy { get; private set; } = false;
|
||||
|
||||
public virtual void OnInit(IJNContext context,ulong id = 0)
|
||||
{
|
||||
Context = context;
|
||||
@@ -127,12 +129,18 @@ namespace JNGame.Sync.Entity
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
//清理缓存
|
||||
Context.RemoveEntity(Id);
|
||||
OnSyncDestroy();
|
||||
RemoveAllComponents();
|
||||
base.Destroy();
|
||||
}
|
||||
|
||||
public void DelayDestroy()
|
||||
{
|
||||
IsDelayDestroy = true;
|
||||
}
|
||||
|
||||
//生命周期
|
||||
public virtual void OnSyncStart(){}
|
||||
|
||||
@@ -146,7 +154,11 @@ namespace JNGame.Sync.Entity
|
||||
}
|
||||
|
||||
public virtual void OnSyncDestroy()
|
||||
{}
|
||||
{
|
||||
_id = 0;
|
||||
IsDelayDestroy = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -148,7 +148,6 @@ namespace JNGame.Sync.System.Data
|
||||
if (NodeContext.Query(child.Key) is null)
|
||||
{
|
||||
Delete(child.Key);
|
||||
return;
|
||||
}
|
||||
|
||||
//主动更新
|
||||
@@ -179,7 +178,7 @@ namespace JNGame.Sync.System.Data
|
||||
{
|
||||
var entity = NodeContext.Query(keyValue.Key);
|
||||
//给从服务器发送数据
|
||||
if (IsMaster && entity is not null && entity.IsSyncSlave)
|
||||
if (IsMaster && ((entity is not null && entity.IsSyncSlave) || keyValue.Value == SDByteOperate.Delete))
|
||||
{
|
||||
slave[keyValue.Key] = keyValue.Value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user