mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
提交Cue案例
This commit is contained in:
@@ -25,6 +25,8 @@ namespace JNGame.Sync.Entity
|
||||
|
||||
public T GetComponent<T>() where T : JNComponent;
|
||||
|
||||
public T GetSystem<T>() where T : SLogicSystem;
|
||||
|
||||
}
|
||||
|
||||
public abstract class JNEntity : Entitas.Entity,IJNEntity,IComparable
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Entitas;
|
||||
using JNGame.Runtime.Util;
|
||||
using JNGame.Sync;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using JNGame.Sync.System;
|
||||
@@ -73,7 +74,7 @@ namespace JNGame.Runtime.Sync
|
||||
|
||||
public override Systems Add(ISystem system)
|
||||
{
|
||||
(system as SLogicSystem)?.OnSyncStart();
|
||||
(system as IJNSyncCycle)?.OnSyncStart();
|
||||
return base.Add(system);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using HotScripts.JNGame.Runtime.Sync.System.Logic;
|
||||
using JNGame.Sync.Frame;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JNGame.Sync.System.Data
|
||||
{
|
||||
@@ -12,10 +15,6 @@ namespace JNGame.Sync.System.Data
|
||||
public abstract class SEventDataSystem : SDataSystemBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 服务器事件
|
||||
/// </summary>
|
||||
private Queue<SEvent> ServerEvents = new();
|
||||
/// <summary>
|
||||
/// 客户端事件
|
||||
/// </summary>
|
||||
@@ -39,35 +38,60 @@ namespace JNGame.Sync.System.Data
|
||||
}
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
|
||||
while (WaitUBytes.Count > 0)
|
||||
{
|
||||
OnUByteUpdate(WaitUBytes.Dequeue());
|
||||
}
|
||||
|
||||
if (isServer)
|
||||
JNEventSystem Event = GetSystem<JNEventSystem>();
|
||||
|
||||
if (Event is null)
|
||||
{
|
||||
if (ServerEvents.Count <= 0) return;
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
Debug.LogWarning("请保证逻辑层有 JNEventSystem 系统");
|
||||
return;
|
||||
}
|
||||
|
||||
//如果是帧同步系统则直接保存
|
||||
if (Sync is JNSyncFrameService)
|
||||
{
|
||||
while (Event.ViewEvent.Count > 0)
|
||||
{
|
||||
using (BinaryWriter writer = new BinaryWriter(ms))
|
||||
{
|
||||
int count = ServerEvents.Count;
|
||||
//写入数量
|
||||
writer.Write(count);
|
||||
for (int i = count - 1; i >= 0; i--)
|
||||
{
|
||||
var data = ServerEvents.Dequeue().ToByteArray();
|
||||
//写入数据大小
|
||||
writer.Write(data.Length);
|
||||
//写入数据
|
||||
writer.Write(data);
|
||||
}
|
||||
}
|
||||
// 发送完整的字节数组
|
||||
OnSendUBytes(ms.ToArray());
|
||||
ClientEvents.Enqueue(Event.ViewEvent.Dequeue());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (WaitUBytes.Count > 0)
|
||||
{
|
||||
OnUByteUpdate(WaitUBytes.Dequeue());
|
||||
}
|
||||
|
||||
if (isServer)
|
||||
{
|
||||
if (Event.ViewEvent.Count <= 0) return;
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (BinaryWriter writer = new BinaryWriter(ms))
|
||||
{
|
||||
int count = Event.ViewEvent.Count;
|
||||
//写入数量
|
||||
writer.Write(count);
|
||||
for (int i = count - 1; i >= 0; i--)
|
||||
{
|
||||
var data = Event.ViewEvent.Dequeue().ToByteArray();
|
||||
//写入数据大小
|
||||
writer.Write(data.Length);
|
||||
//写入数据
|
||||
writer.Write(data);
|
||||
}
|
||||
}
|
||||
// 发送完整的字节数组
|
||||
OnSendUBytes(ms.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//触发事件
|
||||
while (ClientEvents.Count > 0)
|
||||
{
|
||||
ReceiveEvent(ClientEvents.Dequeue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,6 +101,11 @@ namespace JNGame.Sync.System.Data
|
||||
/// <param name="bytes"></param>
|
||||
/// <returns>是否清空UBytes</returns>
|
||||
public abstract void OnSendUBytes(byte[] bytes);
|
||||
|
||||
/// <summary>
|
||||
/// 接收事件 实现
|
||||
/// </summary>
|
||||
protected abstract void ReceiveEvent(SEvent @event);
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -110,19 +139,6 @@ namespace JNGame.Sync.System.Data
|
||||
}
|
||||
}
|
||||
|
||||
public void AddEvent(int type,byte[] data)
|
||||
{
|
||||
//只有服务器才可以添加事件
|
||||
if (isServer)
|
||||
{
|
||||
ServerEvents.Enqueue(new SEvent()
|
||||
{
|
||||
Type = type,
|
||||
Data = data,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class SEvent
|
||||
{
|
||||
/// <summary>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Sync.Frame;
|
||||
using UnityEngine;
|
||||
|
||||
namespace JNGame.Sync.System.Data
|
||||
@@ -90,6 +91,14 @@ namespace JNGame.Sync.System.Data
|
||||
|
||||
public override void OnSyncUpdate(int dt)
|
||||
{
|
||||
|
||||
|
||||
//如果是帧同步系统则直接保存
|
||||
if (Sync is JNSyncFrameService)
|
||||
{
|
||||
Data = GetLatest();
|
||||
return;
|
||||
}
|
||||
|
||||
while (WaitUBytes.Count > 0)
|
||||
{
|
||||
|
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
|
||||
namespace HotScripts.JNGame.Runtime.Sync.System.Logic
|
||||
{
|
||||
public class JNEventSystem : SLogicSystem
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 渲染层 专用事件
|
||||
/// </summary>
|
||||
public Queue<SEventDataSystem.SEvent> ViewEvent = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加数据层事件(用于通知渲染层)
|
||||
/// </summary>
|
||||
public void AddViewEvent(int type,byte[] data)
|
||||
{
|
||||
ViewEvent.Enqueue(new SEventDataSystem.SEvent()
|
||||
{
|
||||
Type = type,
|
||||
Data = data,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1116c94f10954a2084f93bc6e8a61ece
|
||||
timeCreated: 1729876016
|
@@ -61,7 +61,7 @@ namespace JNGame.Sync.View
|
||||
}
|
||||
foreach (var delete in deletes)
|
||||
{
|
||||
ViewRemove(views[delete].Data);
|
||||
ViewRemove(delete,views[delete].Data);
|
||||
views.Remove(delete);
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace JNGame.Sync.View
|
||||
public abstract GameObject NewView(T data);
|
||||
public abstract ConcurrentDictionary<ulong, T> GetData();
|
||||
|
||||
public abstract void ViewRemove(GameObject view);
|
||||
public abstract void ViewRemove(ulong id,GameObject view);
|
||||
|
||||
public T GetService<T>() where T : SBaseSystem
|
||||
{
|
||||
|
Reference in New Issue
Block a user