diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index ec2ef9a..4cf3455 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -38,7 +38,6 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.57481617, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -104,7 +103,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,7 +116,7 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: @@ -209,13 +208,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 705507993} + serializedVersion: 2 m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} m_LocalPosition: {x: 0, y: 3, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} --- !u!1 &963194225 GameObject: @@ -258,9 +257,17 @@ Camera: m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_FocusDistance: 10 + m_FocalLength: 50 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 m_SensorSize: {x: 36, y: 24} m_LensShift: {x: 0, y: 0} - m_FocalLength: 50 m_NormalizedViewPortRect: serializedVersion: 2 x: 0 @@ -294,13 +301,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 963194225} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 1, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &963194229 MonoBehaviour: @@ -314,3 +321,56 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 694d8256118344eb2b130fceb1a11b7f, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &1936170114 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1936170116} + - component: {fileID: 1936170115} + m_Layer: 0 + m_Name: ServerMain + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1936170115 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1936170114} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1da32d64fdd4d41778db4fd91607ac27, type: 3} + m_Name: + m_EditorClassIdentifier: + address: 127.0.0.1 + driverAsset: {fileID: 11400000, guid: a8a5562854ecf4cc1a49700e8bd93c19, type: 2} +--- !u!4 &1936170116 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1936170114} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: + - {fileID: 963194228} + - {fileID: 705507995} + - {fileID: 1936170116} diff --git a/Assets/Scripts/Client.meta b/Assets/Scripts/Client.meta new file mode 100644 index 0000000..f98e469 --- /dev/null +++ b/Assets/Scripts/Client.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 48c265b50587429a9a7555df18d64661 +timeCreated: 1765786522 \ No newline at end of file diff --git a/Assets/Scripts/Client/ClientMain.cs b/Assets/Scripts/Client/ClientMain.cs new file mode 100644 index 0000000..108edc7 --- /dev/null +++ b/Assets/Scripts/Client/ClientMain.cs @@ -0,0 +1,50 @@ +using System; +using GameCore.Network; +using Unity.Collections; +using Unity.Jobs; +using Unity.Networking.Transport; +using UnityEngine; + +namespace ECSTest +{ + public class ClientMain : MonoBehaviour + { + public string address = "127.0.0.1"; + public NetworkDriverAsset driverAsset; + + private NetworkDriver driver; + private NetworkPipeline unreliablePipeline; + private NetworkPipeline reliablePipeline; + private NativeReference connection; + private JobHandle jobHandle; + + private void OnEnable() + { + driver = driverAsset.CreateClientDriver(address, out var c, out unreliablePipeline, out reliablePipeline); + connection = new NativeReference(c, Allocator.Persistent); + } + + private void OnDisable() + { + jobHandle.Complete(); + + if (connection.IsCreated) + { + driver.Disconnect(connection.Value); + driver.ScheduleUpdate().Complete(); + } + + connection.Dispose(); + driver.Dispose(); + } + + void Update() + { + jobHandle.Complete(); + + + + //TODO Render() + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Client/ClientMain.cs.meta b/Assets/Scripts/Client/ClientMain.cs.meta new file mode 100644 index 0000000..8bcdbc5 --- /dev/null +++ b/Assets/Scripts/Client/ClientMain.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d126d712307544dd89716677e730aa93 +timeCreated: 1765786534 \ No newline at end of file diff --git a/Assets/Scripts/Client/ClientUpdateJob.cs b/Assets/Scripts/Client/ClientUpdateJob.cs new file mode 100644 index 0000000..35c2b6c --- /dev/null +++ b/Assets/Scripts/Client/ClientUpdateJob.cs @@ -0,0 +1,26 @@ +using Unity.Burst; +using Unity.Collections; +using Unity.Jobs; +using Unity.Networking.Transport; + +namespace ECSTest +{ + [BurstCompile] + public struct ClientUpdateJob : IJob + { + public NetworkDriver driver; + public NetworkPipeline unreliablePipeline; + public NetworkPipeline reliablePipeline; + public NativeReference connection; + + public void Execute() + { + NetworkEvent.Type cmd; + while ((cmd = connection.Value.PopEvent(driver, out var stream, out var networkPipeline)) != + NetworkEvent.Type.Empty) + { + + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Client/ClientUpdateJob.cs.meta b/Assets/Scripts/Client/ClientUpdateJob.cs.meta new file mode 100644 index 0000000..aa5a865 --- /dev/null +++ b/Assets/Scripts/Client/ClientUpdateJob.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ffb4af76205e4a638c5343a82b13ce08 +timeCreated: 1765789910 \ No newline at end of file diff --git a/Assets/Scripts/EntityData.cs b/Assets/Scripts/EntityData.cs index df120be..5946d44 100644 --- a/Assets/Scripts/EntityData.cs +++ b/Assets/Scripts/EntityData.cs @@ -1,7 +1,7 @@ using GameCore.TinyECS; using Unity.Mathematics; -namespace GameCore.Test +namespace ECSTest { using Entity = Entity; diff --git a/Assets/Scripts/EntityType.cs b/Assets/Scripts/EntityType.cs index 0b35401..8e607cd 100644 --- a/Assets/Scripts/EntityType.cs +++ b/Assets/Scripts/EntityType.cs @@ -1,4 +1,4 @@ -namespace GameCore.Test +namespace ECSTest { public enum EntityType { diff --git a/Assets/Scripts/Main.cs b/Assets/Scripts/Main.cs index 69b4e9e..346f8e0 100644 --- a/Assets/Scripts/Main.cs +++ b/Assets/Scripts/Main.cs @@ -1,19 +1,21 @@ using System.Collections; using System.Collections.Generic; -using GameCore.Test; using UnityEngine; -public class Main : MonoBehaviour +namespace ECSTest { - // Start is called before the first frame update - void Start() + public class Main : MonoBehaviour { - TestEntityDataBlock.Run(); - } + // Start is called before the first frame update + void Start() + { + TestEntityDataBlock.Run(); + } - // Update is called once per frame - void Update() - { - + // Update is called once per frame + void Update() + { + + } } } diff --git a/Assets/Scripts/Server/ServerConnectionJob.cs b/Assets/Scripts/Server/ServerConnectionJob.cs index a7e91e2..389cb8e 100644 --- a/Assets/Scripts/Server/ServerConnectionJob.cs +++ b/Assets/Scripts/Server/ServerConnectionJob.cs @@ -1,17 +1,18 @@ +using Unity.Burst; +using Unity.Collections; +using Unity.Jobs; +using Unity.Networking.Transport; +using UnityEngine; - using Unity.Burst; - using Unity.Collections; - using Unity.Jobs; - using Unity.Networking.Transport; - using UnityEngine; - +namespace ECSTest +{ [BurstCompile] public struct ServerConnectionJob : IJob { public NetworkDriver driver; public NativeList connectionList; public NativeList disconnectIndexList; - + public void Execute() { // disconnect @@ -21,6 +22,7 @@ var index = disconnectIndexList[i]; connectionList.RemoveAtSwapBack(index); } + disconnectIndexList.Clear(); // connect @@ -28,7 +30,12 @@ while ((c = driver.Accept()) != default) { connectionList.Add(c); - Debug.Log("Accepted a connection"); + Debug.Log("[Server] Accepted a connection"); } + + if (connectionList.Length > disconnectIndexList.Capacity) + disconnectIndexList.SetCapacity(connectionList.Length); } } + +} \ No newline at end of file diff --git a/Assets/Scripts/Server/ServerMain.cs b/Assets/Scripts/Server/ServerMain.cs index fe9519f..d65755e 100644 --- a/Assets/Scripts/Server/ServerMain.cs +++ b/Assets/Scripts/Server/ServerMain.cs @@ -7,52 +7,59 @@ using Unity.Jobs; using Unity.Networking.Transport; using UnityEngine; -public class ServerMain : MonoBehaviour +namespace ECSTest { - public string address = "127.0.0.1"; - public NetworkDriverAsset driverAsset; - - private NetworkDriver driver; - private JobHandle networkJobHandle; - private NativeList connectionList; - private NativeList disconnectIndexList; - - private void OnEnable() + public class ServerMain : MonoBehaviour { - driver = driverAsset.CreateServerDriver(address); - - connectionList = new NativeList(16,Allocator.Persistent); - disconnectIndexList = new NativeList(16, Allocator.Persistent); - } + public string address = "127.0.0.1"; + public NetworkDriverAsset driverAsset; - private void OnDisable() - { - networkJobHandle.Complete(); + private NetworkDriver driver; + private NetworkPipeline unreliablePipeline; + private NetworkPipeline reliablePipeline; + private JobHandle networkJobHandle; + private NativeList connectionList; + private NativeList disconnectIndexList; - driver.Dispose(); - - connectionList.Dispose(); - disconnectIndexList.Dispose(); - } - - void Update() - { - networkJobHandle.Complete(); + private void OnEnable() + { + driver = driverAsset.CreateServerDriver(address, out unreliablePipeline, out reliablePipeline); - var concurrentDriver = driver.ToConcurrent(); + connectionList = new NativeList(16, Allocator.Persistent); + disconnectIndexList = new NativeList(16, Allocator.Persistent); + } - networkJobHandle = driver.ScheduleUpdate(); - networkJobHandle = new ServerConnectionJob() + private void OnDisable() { - driver = driver, - connectionList = connectionList, - disconnectIndexList = disconnectIndexList, - }.Schedule(networkJobHandle); - - networkJobHandle = new ServerReceiveJob() + networkJobHandle.Complete(); + + driver.Dispose(); + + connectionList.Dispose(); + disconnectIndexList.Dispose(); + } + + void Update() { - driver = concurrentDriver, - }.Schedule(connectionList, 16, networkJobHandle); + networkJobHandle.Complete(); + + var concurrentDriver = driver.ToConcurrent(); + + networkJobHandle = driver.ScheduleUpdate(); + networkJobHandle = new ServerConnectionJob() + { + driver = driver, + connectionList = connectionList, + disconnectIndexList = disconnectIndexList, + }.Schedule(networkJobHandle); + + networkJobHandle = new ServerReceiveJob() + { + driver = concurrentDriver, + connectionList = connectionList, + disconnectIndexList = disconnectIndexList.AsParallelWriter(), + }.Schedule(connectionList, 16, networkJobHandle); + } } } diff --git a/Assets/Scripts/Server/ServerReceiveJob.cs b/Assets/Scripts/Server/ServerReceiveJob.cs index 432b4c0..32961aa 100644 --- a/Assets/Scripts/Server/ServerReceiveJob.cs +++ b/Assets/Scripts/Server/ServerReceiveJob.cs @@ -1,15 +1,37 @@ +using Unity.Burst; +using Unity.Collections; +using Unity.Jobs; +using Unity.Networking.Transport; +using UnityEngine; - using Unity.Burst; - using Unity.Jobs; - using Unity.Networking.Transport; - +namespace ECSTest +{ [BurstCompile] public struct ServerReceiveJob : IJobParallelForDefer { public NetworkDriver.Concurrent driver; - + [ReadOnly] + public NativeList connectionList; + public NativeList.ParallelWriter disconnectIndexList; + public void Execute(int index) { - + var connection = connectionList[index]; + + NetworkEvent.Type cmd; + while ((cmd = driver.PopEventForConnection(connection, out var stream)) != + NetworkEvent.Type.Empty) + { + if (cmd == NetworkEvent.Type.Data) + { + //TODO + } + else if (cmd == NetworkEvent.Type.Disconnect) + { + disconnectIndexList.AddNoResize(index); + Debug.Log("[Server] Received a disconnection"); + } + } } } +} \ No newline at end of file diff --git a/Assets/Scripts/Server/ServerSendJob.cs b/Assets/Scripts/Server/ServerSendJob.cs index e76e26d..745673d 100644 --- a/Assets/Scripts/Server/ServerSendJob.cs +++ b/Assets/Scripts/Server/ServerSendJob.cs @@ -1,12 +1,13 @@ +using Unity.Burst; +using Unity.Jobs; - using Unity.Burst; - using Unity.Jobs; - +namespace ECSTest +{ [BurstCompile] public struct ServerSendJob : IJobParallelFor { public void Execute(int index) { - } } +} \ No newline at end of file diff --git a/Assets/Scripts/TestEntityDataBlock.cs b/Assets/Scripts/TestEntityDataBlock.cs index b5bb93a..cbd2fe4 100644 --- a/Assets/Scripts/TestEntityDataBlock.cs +++ b/Assets/Scripts/TestEntityDataBlock.cs @@ -1,7 +1,7 @@ using GameCore.TinyECS; using UnityEngine; -namespace GameCore.Test +namespace ECSTest { public static class TestEntityDataBlock { diff --git a/Assets/Scripts/TestJob.cs b/Assets/Scripts/TestJob.cs deleted file mode 100644 index dfcca1c..0000000 --- a/Assets/Scripts/TestJob.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using Unity.Burst; -using Unity.Collections; -using Unity.Collections.LowLevel.Unsafe; -using Unity.Jobs; -using Unity.Mathematics; -using UnityEngine; - -namespace GameCore.Test -{ - [BurstCompile] - public struct TestJob : IJobParallelFor - { - public void Execute(int index) - { - - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/TestJob.cs.meta b/Assets/Scripts/TestJob.cs.meta deleted file mode 100644 index e492340..0000000 --- a/Assets/Scripts/TestJob.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 68aafcef1265449e6b6b2dd81d7173a8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/LocalPackages/com.nimin.network/Runtime/NetworkDriverAsset.cs b/LocalPackages/com.nimin.network/Runtime/NetworkDriverAsset.cs index 6becfab..84fd8ac 100644 --- a/LocalPackages/com.nimin.network/Runtime/NetworkDriverAsset.cs +++ b/LocalPackages/com.nimin.network/Runtime/NetworkDriverAsset.cs @@ -18,12 +18,12 @@ namespace GameCore.Network public int packetJitterMs = 300; public int packetDropPercentage = 10; - private NetworkDriver CreateDriver() + private NetworkDriver CreateDriver(out NetworkPipeline unreliablePipeline, out NetworkPipeline reliablePipeline) { var settings = new NetworkSettings(Allocator.Temp); settings.WithNetworkConfigParameters(disconnectTimeoutMS: 5000); settings.WithReliableStageParameters(32); - settings.WithSimulatorStageParameters(32, NetworkParameterConstants.MaxConnectAttempts, + settings.WithSimulatorStageParameters(32, mode: ApplyMode.SentPacketsOnly, packetDelayMs: packetDelayMs, packetJitterMs: packetJitterMs, packetDropPercentage: packetDropPercentage); @@ -31,24 +31,25 @@ namespace GameCore.Network if (useSimulator) { - driver.CreatePipeline(typeof(SimulatorPipelineStageInSend)); - driver.CreatePipeline(typeof(ReliableSequencedPipelineStage), typeof(SimulatorPipelineStageInSend)); + unreliablePipeline = driver.CreatePipeline(typeof(SimulatorPipelineStage)); + reliablePipeline = driver.CreatePipeline(typeof(ReliableSequencedPipelineStage), typeof(SimulatorPipelineStage)); } else { - driver.CreatePipeline(typeof(ReliableSequencedPipelineStage)); + unreliablePipeline = NetworkPipeline.Null; + reliablePipeline = driver.CreatePipeline(typeof(ReliableSequencedPipelineStage)); } return driver; } - public NetworkDriver CreateServerDriver(string address) + public NetworkDriver CreateServerDriver(string address, out NetworkPipeline unreliablePipeline, out NetworkPipeline reliablePipeline) { - var driver = CreateDriver(); + var driver = CreateDriver(out unreliablePipeline, out reliablePipeline); var ok = false; try { - if (!NetworkEndPoint.TryParse(address, (ushort)port, out var endpoint)) + if (!NetworkEndpoint.TryParse(address, (ushort)port, out var endpoint)) { return default; } @@ -70,10 +71,10 @@ namespace GameCore.Network } } - public NetworkDriver CreateClientDriver(string address, out NetworkConnection connection) + public NetworkDriver CreateClientDriver(string address, out NetworkConnection connection, out NetworkPipeline unreliablePipeline, out NetworkPipeline reliablePipeline) { - var driver = CreateDriver(); - if (!NetworkEndPoint.TryParse(address, (ushort)port, out var endpoint)) + var driver = CreateDriver(out unreliablePipeline, out reliablePipeline); + if (!NetworkEndpoint.TryParse(address, (ushort)port, out var endpoint)) { connection = default; driver.Dispose(); diff --git a/LocalPackages/com.nimin.network/package.json b/LocalPackages/com.nimin.network/package.json index 15a4337..9e7e78c 100644 --- a/LocalPackages/com.nimin.network/package.json +++ b/LocalPackages/com.nimin.network/package.json @@ -1,14 +1,14 @@ { - "name": "com.nimin.network", - "displayName": "GameCore Network", - "version": "0.1.0", - "unity": "2021.3", - "description": "Network based on Unity Transport", - "dependencies": { - "com.unity.transport": "1.0.0" - }, - "keywords": [ - "Network", - "JobSystem" - ] + "name": "com.nimin.network", + "displayName": "GameCore Network", + "version": "0.1.0", + "unity": "2021.3", + "description": "Network based on Unity Transport", + "dependencies": { + "com.unity.transport": "2.6.0" + }, + "keywords": [ + "Network", + "JobSystem" + ] } \ No newline at end of file diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index d307fd7..3432976 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -14,7 +14,7 @@ "depth": 0, "source": "local", "dependencies": { - "com.unity.transport": "1.0.0" + "com.unity.transport": "2.6.0" } }, "com.nimin.tinyecs": { @@ -26,8 +26,8 @@ } }, "com.unity.burst": { - "version": "1.8.21", - "depth": 1, + "version": "1.8.24", + "depth": 2, "source": "registry", "dependencies": { "com.unity.mathematics": "1.2.1", @@ -36,13 +36,14 @@ "url": "https://packages.unity.com" }, "com.unity.collections": { - "version": "1.4.0", - "depth": 1, + "version": "2.2.1", + "depth": 2, "source": "registry", "dependencies": { - "com.unity.burst": "1.6.6", - "com.unity.test-framework": "1.1.31", - "com.unity.nuget.mono-cecil": "1.11.4" + "com.unity.burst": "1.8.8", + "com.unity.nuget.mono-cecil": "1.11.4", + "com.unity.modules.unityanalytics": "1.0.0", + "com.unity.test-framework.performance": "3.0.2" }, "url": "https://packages.unity.com" }, @@ -109,7 +110,7 @@ "url": "https://packages.unity.com" }, "com.unity.mathematics": { - "version": "1.2.6", + "version": "1.3.2", "depth": 2, "source": "registry", "dependencies": {}, @@ -147,6 +148,16 @@ }, "url": "https://packages.unity.com" }, + "com.unity.test-framework.performance": { + "version": "3.0.2", + "depth": 3, + "source": "registry", + "dependencies": { + "com.unity.test-framework": "1.1.31", + "com.unity.modules.jsonserialize": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.testtools.codecoverage": { "version": "1.2.6", "depth": 1, @@ -179,13 +190,13 @@ "url": "https://packages.unity.com" }, "com.unity.transport": { - "version": "1.5.0", + "version": "2.6.0", "depth": 1, "source": "registry", "dependencies": { - "com.unity.burst": "1.6.6", - "com.unity.collections": "1.2.4", - "com.unity.mathematics": "1.2.6" + "com.unity.burst": "1.8.24", + "com.unity.collections": "2.2.1", + "com.unity.mathematics": "1.3.2" }, "url": "https://packages.unity.com" },