mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[EntitySystemOf(typeof(LSServerUpdater))]
|
||||
[FriendOf(typeof(LSServerUpdater))]
|
||||
public static partial class LSServerUpdaterSystem
|
||||
{
|
||||
[EntitySystem]
|
||||
private static void Awake(this LSServerUpdater self)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[EntitySystem]
|
||||
private static void Update(this LSServerUpdater self)
|
||||
{
|
||||
Room room = self.GetParent<Room>();
|
||||
long timeNow = room.Fiber().TimeInfo.ServerFrameTime();
|
||||
|
||||
|
||||
int frame = room.AuthorityFrame + 1;
|
||||
if (timeNow < room.FixedTimeCounter.FrameTime(frame))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OneFrameInputs oneFrameInputs = self.GetOneFrameMessage(frame);
|
||||
++room.AuthorityFrame;
|
||||
|
||||
OneFrameInputs sendInput = new();
|
||||
oneFrameInputs.CopyTo(sendInput);
|
||||
|
||||
RoomMessageHelper.BroadCast(room, sendInput);
|
||||
|
||||
room.Update(oneFrameInputs);
|
||||
}
|
||||
|
||||
private static OneFrameInputs GetOneFrameMessage(this LSServerUpdater self, int frame)
|
||||
{
|
||||
Room room = self.GetParent<Room>();
|
||||
FrameBuffer frameBuffer = room.FrameBuffer;
|
||||
OneFrameInputs oneFrameInputs = frameBuffer.FrameInputs(frame);
|
||||
frameBuffer.MoveForward(frame);
|
||||
|
||||
if (oneFrameInputs.Inputs.Count == LSConstValue.MatchCount)
|
||||
{
|
||||
return oneFrameInputs;
|
||||
}
|
||||
|
||||
OneFrameInputs preFrameInputs = null;
|
||||
if (frameBuffer.CheckFrame(frame - 1))
|
||||
{
|
||||
preFrameInputs = frameBuffer.FrameInputs(frame - 1);
|
||||
}
|
||||
|
||||
// 有人输入的消息没过来,给他使用上一帧的操作
|
||||
foreach (long playerId in room.PlayerIds)
|
||||
{
|
||||
if (oneFrameInputs.Inputs.ContainsKey(playerId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preFrameInputs != null && preFrameInputs.Inputs.TryGetValue(playerId, out LSInput input))
|
||||
{
|
||||
// 使用上一帧的输入
|
||||
oneFrameInputs.Inputs[playerId] = input;
|
||||
}
|
||||
else
|
||||
{
|
||||
oneFrameInputs.Inputs[playerId] = new LSInput();
|
||||
}
|
||||
}
|
||||
|
||||
return oneFrameInputs;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user