[+] 接入ET8服务端

[+] 接入ET8服务端
This commit is contained in:
ALEXTANG
2023-07-13 12:23:48 +08:00
parent e0be062006
commit 336d4b2eb9
1316 changed files with 130657 additions and 626 deletions

View File

@@ -0,0 +1,32 @@
using System;
using ET.Client;
using TrueSync;
namespace ET
{
[EntitySystemOf(typeof(LSInputComponent))]
[LSEntitySystemOf(typeof(LSInputComponent))]
public static partial class LSInputComponentSystem
{
[EntitySystem]
private static void Awake(this LSInputComponent self)
{
}
[LSEntitySystem]
private static void LSUpdate(this LSInputComponent self)
{
LSUnit unit = self.GetParent<LSUnit>();
TSVector2 v2 = self.LSInput.V * 6 * 50 / 1000;
if (v2.LengthSquared() < 0.0001f)
{
return;
}
TSVector oldPos = unit.Position;
unit.Position += new TSVector(v2.x, 0, v2.y);
unit.Forward = unit.Position - oldPos;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4fa48744575ea4fd2a4f6e111ce26f11
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
namespace ET
{
public static partial class LSUnitFactory
{
public static LSUnit Init(LSWorld lsWorld, LockStepUnitInfo unitInfo)
{
LSUnitComponent lsUnitComponent = lsWorld.GetComponent<LSUnitComponent>();
LSUnit lsUnit = lsUnitComponent.AddChildWithId<LSUnit>(unitInfo.PlayerId);
lsUnit.Position = unitInfo.Position;
lsUnit.Rotation = unitInfo.Rotation;
lsUnit.AddComponent<LSInputComponent>();
return lsUnit;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a93a389ec0e241f099646159dae6dcd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace ET
{
[FriendOf(typeof(Room))]
public static partial class RoomSystem
{
public static Room Room(this Entity entity)
{
return entity.IScene as Room;
}
public static void Init(this Room self, List<LockStepUnitInfo> unitInfos, long startTime, int frame = -1)
{
self.StartTime = startTime;
self.AuthorityFrame = frame;
self.PredictionFrame = frame;
self.Replay.UnitInfos = unitInfos;
self.FrameBuffer = new FrameBuffer(frame);
self.FixedTimeCounter = new FixedTimeCounter(self.StartTime, 0, LSConstValue.UpdateInterval);
LSWorld lsWorld = self.LSWorld;
lsWorld.Frame = frame + 1;
lsWorld.AddComponent<LSUnitComponent>();
for (int i = 0; i < unitInfos.Count; ++i)
{
LockStepUnitInfo unitInfo = unitInfos[i];
LSUnitFactory.Init(lsWorld, unitInfo);
self.PlayerIds.Add(unitInfo.PlayerId);
}
}
public static void Update(this Room self, OneFrameInputs oneFrameInputs)
{
LSWorld lsWorld = self.LSWorld;
// 设置输入到每个LSUnit身上
LSUnitComponent unitComponent = lsWorld.GetComponent<LSUnitComponent>();
foreach (var kv in oneFrameInputs.Inputs)
{
LSUnit lsUnit = unitComponent.GetChild<LSUnit>(kv.Key);
LSInputComponent lsInputComponent = lsUnit.GetComponent<LSInputComponent>();
lsInputComponent.LSInput = kv.Value;
}
if (!self.IsReplay)
{
// 保存当前帧场景数据
self.SaveLSWorld();
self.Record(self.LSWorld.Frame);
}
lsWorld.Update();
}
public static LSWorld GetLSWorld(this Room self, SceneType sceneType, int frame)
{
MemoryBuffer memoryBuffer = self.FrameBuffer.Snapshot(frame);
memoryBuffer.Seek(0, SeekOrigin.Begin);
LSWorld lsWorld = MongoHelper.Deserialize(typeof (LSWorld), memoryBuffer) as LSWorld;
lsWorld.SceneType = sceneType;
memoryBuffer.Seek(0, SeekOrigin.Begin);
return lsWorld;
}
private static void SaveLSWorld(this Room self)
{
int frame = self.LSWorld.Frame;
MemoryBuffer memoryBuffer = self.FrameBuffer.Snapshot(frame);
memoryBuffer.Seek(0, SeekOrigin.Begin);
memoryBuffer.SetLength(0);
MongoHelper.Serialize(self.LSWorld, memoryBuffer);
memoryBuffer.Seek(0, SeekOrigin.Begin);
long hash = memoryBuffer.GetBuffer().Hash(0, (int) memoryBuffer.Length);
self.FrameBuffer.SetHash(frame, hash);
}
// 记录需要存档的数据
public static void Record(this Room self, int frame)
{
if (frame > self.AuthorityFrame)
{
return;
}
OneFrameInputs oneFrameInputs = self.FrameBuffer.FrameInputs(frame);
OneFrameInputs saveInput = new();
oneFrameInputs.CopyTo(saveInput);
self.Replay.FrameInputs.Add(saveInput);
if (frame % LSConstValue.SaveLSWorldFrameCount == 0)
{
MemoryBuffer memoryBuffer = self.FrameBuffer.Snapshot(frame);
byte[] bytes = memoryBuffer.ToArray();
self.Replay.Snapshots.Add(bytes);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a0ef11394d28492caa3959412027a17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: