public void CreateClientDriver(World world, out NetworkDriver driver, out NetworkPipeline unreliablePipeline, out NetworkPipeline reliablePipeline, out NetworkPipeline unreliableFragmentedPipeline) { var reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; var netParams = new NetworkConfigParameter { maxConnectAttempts = NetworkParameterConstants.MaxConnectAttempts, connectTimeoutMS = NetworkParameterConstants.ConnectTimeoutMS, disconnectTimeoutMS = NetworkParameterConstants.DisconnectTimeoutMS, maxFrameTimeMS = 100, fixedFrameTimeMS = DriverFixedTime }; var packetDelay = DriverSimulatedDelay; int networkRate = 60; // All 3 packet types every frame stored for maximum delay, doubled for safety margin int maxPackets = 2 * (networkRate * 3 * packetDelay + 999) / 1000; var fuzzFactor = 0; const int kStringLength = 10; // we name it ClientTest e.g. 10 bytes long. var worldId = int.Parse(world.Name.Substring(kStringLength, world.Name.Length - kStringLength)); if (DriverFuzzFactor?.Length >= worldId + 1) { fuzzFactor = DriverFuzzFactor[worldId]; } var simParams = new SimulatorUtility.Parameters { MaxPacketSize = NetworkParameterConstants.MTU, MaxPacketCount = maxPackets, PacketDelayMs = packetDelay, FuzzFactor = fuzzFactor, FuzzOffset = DriverFuzzOffset, RandomSeed = DriverRandomSeed }; driver = new NetworkDriver(new IPCNetworkInterface(), netParams, reliabilityParams, simParams); if (DriverSimulatedDelay + fuzzFactor > 0) { unreliablePipeline = driver.CreatePipeline( typeof(SimulatorPipelineStage), typeof(SimulatorPipelineStageInSend)); reliablePipeline = driver.CreatePipeline( typeof(SimulatorPipelineStage), typeof(ReliableSequencedPipelineStage), typeof(SimulatorPipelineStageInSend)); unreliableFragmentedPipeline = driver.CreatePipeline( typeof(SimulatorPipelineStage), typeof(FragmentationPipelineStage), typeof(SimulatorPipelineStageInSend)); } else { unreliablePipeline = driver.CreatePipeline(typeof(NullPipelineStage)); reliablePipeline = driver.CreatePipeline(typeof(ReliableSequencedPipelineStage)); unreliableFragmentedPipeline = driver.CreatePipeline(typeof(FragmentationPipelineStage)); } }
protected override void OnCreate() { var reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; #if UNITY_EDITOR m_ClientPacketDelay = UnityEditor.EditorPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_ClientDelay"); m_ClientPacketDrop = UnityEditor.EditorPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_ClientDropRate"); int networkRate = 60; // TODO: read from some better place // All 3 packet types every frame stored for maximum delay, doubled for safety margin int maxPackets = 2 * (networkRate * 3 * m_ClientPacketDelay + 999) / 1000; var simulatorParams = new SimulatorUtility.Parameters { MaxPacketSize = NetworkParameterConstants.MTU, MaxPacketCount = maxPackets, PacketDelayMs = m_ClientPacketDelay, PacketDropPercentage = m_ClientPacketDrop }; m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams); #else m_Driver = new UdpNetworkDriver(reliabilityParams); #endif m_ConcurrentDriver = m_Driver.ToConcurrent(); m_UnreliablePipeline = NetworkPipeline.Null; m_ReliablePipeline = NetworkPipeline.Null; m_DriverListening = false; m_Barrier = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); numNetworkIds = new NativeArray <int>(1, Allocator.Persistent); freeNetworkIds = new NativeQueue <int>(Allocator.Persistent); rpcQueue = InternalRpcCollection.GetRpcQueue <RpcSetNetworkId>(); }
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member protected override void OnCreateManager() #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member { var reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; if (UnityEngine.Debug.isDebugBuild) { m_ClientPacketDelay = UnityEngine.PlayerPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_ClientDelay"); m_ClientPacketDrop = UnityEngine.PlayerPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_ClientDropRate"); int networkRate = 60; // TODO: read from some better place // All 3 packet types every frame stored for maximum delay, doubled for safety margin int maxPackets = 2 * (networkRate * 3 * m_ClientPacketDelay + 999) / 1000; var simulatorParams = new SimulatorUtility.Parameters { MaxPacketSize = NetworkParameterConstants.MTU, MaxPacketCount = maxPackets, PacketDelayMs = m_ClientPacketDelay, PacketDropPercentage = m_ClientPacketDrop }; m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams); UnityEngine.Debug.Log("Using simulator with latency=" + m_ClientPacketDelay + " packet drop=" + m_ClientPacketDrop); } else { m_Driver = new UdpNetworkDriver(reliabilityParams); } m_ConcurrentDriver = m_Driver.ToConcurrent(); m_UnreliablePipeline = NetworkPipeline.Null; m_ReliablePipeline = NetworkPipeline.Null; m_DriverListening = false; m_Barrier = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); numNetworkIds = new NativeArray <int>(1, Allocator.Persistent); freeNetworkIds = new NativeQueue <int>(Allocator.Persistent); rpcQueue = InternalRpcCollection.GetRpcQueue <RpcSetNetworkId>(); }
protected void init() { // var reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; var configParameter = new NetworkConfigParameter { maxConnectAttempts = maxConnectAttempts, connectTimeoutMS = NetworkParameterConstants.ConnectTimeoutMS, disconnectTimeoutMS = disconnectTimeoutMS }; #if UNITY_EDITOR int networkRate = (int)(1f / Time.fixedDeltaTime); // TODO: read from some better place // All 3 packet types every frame stored for maximum delay, doubled for safety margin int maxPackets = 2 * (networkRate * 3 * clientPacketDelay + 999) / 1000; var simulatorParams = new SimulatorUtility.Parameters { MaxPacketSize = NetworkParameterConstants.MTU, MaxPacketCount = maxPackets, PacketDelayMs = clientPacketDelay, PacketDropPercentage = clientPacketDrop }; _driver = new UdpNetworkDriver(simulatorParams, reliabilityParams, configParameter); #else _driver = new UdpNetworkDriver(reliabilityParams, configParameter); #endif _concurrentDriver = _driver.ToConcurrent(); _unreliablePipeline = NetworkPipeline.Null; _reliablePipeline = NetworkPipeline.Null; _listening = false; }
void Start() { ReliableUtility.Parameters reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; SimulatorUtility.Parameters simulatorParams = new SimulatorUtility.Parameters { MaxPacketSize = k_PacketSize, MaxPacketCount = 30, PacketDelayMs = 100 }; m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams); m_Connections = new NativeList <NetworkConnection>(connectionCapacity, Allocator.Persistent); // first parameter is number of connections to accept m_Unreliable_Pipeline = m_Driver.CreatePipeline(typeof(UnreliableSequencedPipelineStage), typeof(SimulatorPipelineStage)); m_Reliable_Pipeline = m_Driver.CreatePipeline(typeof(UnreliableSequencedPipelineStage), typeof(SimulatorPipelineStage)); NetworkEndPoint endpoint = NetworkEndPoint.AnyIpv4; endpoint.Port = 9000; if (m_Driver.Bind(endpoint) != 0) { Debug.Log("Failed to bind to port 9000"); } else { m_Driver.Listen(); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); JobHandle serverJobHandle; //Debug.Log("server system on update"); if (!m_Driver.IsCreated) { ReliableUtility.Parameters reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; SimulatorUtility.Parameters simulatorParams = new SimulatorUtility.Parameters { MaxPacketSize = k_PacketSize, MaxPacketCount = 30, PacketDelayMs = 100 }; m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams); NetworkEndPoint endpoint = NetworkEndPoint.AnyIpv4; endpoint.Port = 9000; if (m_Driver.Bind(endpoint) != 0) { Debug.Log("Failed to bind to port 9000"); } else { m_Driver.Listen(); Debug.Log("driver listening on port 9000"); } currentId = new NativeList <int>(1, Allocator.Persistent); currentId.Add(0); } else { serverJobHandle = m_Driver.ScheduleUpdate(inputDeps); serverJobHandle = new ListenForConnectionsJob { commandBuffer = m_Barrier.CreateCommandBuffer(), driver = m_Driver, }.Schedule(serverJobHandle); serverJobHandle.Complete(); serverJobHandle = new UpdateServerJob { commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(), driver = m_Driver.ToConcurrent(), id = currentId.AsDeferredJobArray() }.Schedule(this, serverJobHandle); m_Barrier.AddJobHandleForProducer(serverJobHandle); //Debug.Log("about to listen for connections"); return(serverJobHandle); } return(inputDeps); }
protected override void OnCreate() { if (!Library.Initialized) { if (!Library.Initialize()) { throw new InvalidOperationException("Library not initialized"); } Application.quitting += Library.Deinitialize; } var reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; #if UNITY_EDITOR || DEVELOPMENT_BUILD var netParams = new NetworkConfigParameter { maxConnectAttempts = NetworkParameterConstants.MaxConnectAttempts, connectTimeoutMS = NetworkParameterConstants.ConnectTimeoutMS, disconnectTimeoutMS = NetworkParameterConstants.DisconnectTimeoutMS, maxFrameTimeMS = 100 }; m_ClientPacketDelay = ClientPacketDelayMs; var jitter = ClientPacketJitterMs; if (jitter > m_ClientPacketDelay) { jitter = m_ClientPacketDelay; } m_ClientPacketDrop = ClientPacketDropRate; int networkRate = 60; // TODO: read from some better place // All 3 packet types every frame stored for maximum delay, doubled for safety margin int maxPackets = 2 * (networkRate * 3 * m_ClientPacketDelay + 999) / 1000; var simulatorParams = new SimulatorUtility.Parameters { MaxPacketSize = NetworkParameterConstants.MTU, MaxPacketCount = maxPackets, PacketDelayMs = m_ClientPacketDelay, PacketJitterMs = jitter, PacketDropPercentage = m_ClientPacketDrop }; m_Driver = new ENetDriver(16); UnityEngine.Debug.Log($"Using simulator with latency={m_ClientPacketDelay} packet drop={m_ClientPacketDrop}"); #else m_Driver = new ENetDriver(16); #endif m_UnreliablePipeline = NetworkPipeline.Null; m_ReliablePipeline = NetworkPipeline.Null; m_DriverListening = false; m_Barrier = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); numNetworkIds = new NativeArray <int>(1, Allocator.Persistent); freeNetworkIds = new NativeQueue <int>(Allocator.Persistent); rpcQueue = World.GetOrCreateSystem <RpcSystem>().GetRpcQueue <RpcSetNetworkId>(); m_NetworkStreamConnectionQuery = EntityManager.CreateEntityQuery(typeof(NetworkStreamConnection)); }
private static void InitializeConnection(byte *staticInstanceBuffer, int staticInstanceBufferLength, byte *sendProcessBuffer, int sendProcessBufferLength, byte *recvProcessBuffer, int recvProcessBufferLength, byte *sharedProcessBuffer, int sharedProcessBufferLength) { SimulatorUtility.Parameters param = default; UnsafeUtility.MemCpy(¶m, staticInstanceBuffer, UnsafeUtility.SizeOf <SimulatorUtility.Parameters>()); if (sharedProcessBufferLength >= UnsafeUtility.SizeOf <SimulatorUtility.Parameters>()) { SimulatorUtility.InitializeContext(param, sharedProcessBuffer); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); JobHandle clientJobHandle; if (!m_Driver.IsCreated) { ReliableUtility.Parameters reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; SimulatorUtility.Parameters simulatorParams = new SimulatorUtility.Parameters { MaxPacketSize = k_PacketSize, MaxPacketCount = 30, PacketDelayMs = 100 }; m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams); m_Server_EndPoint = NetworkEndPoint.LoopbackIpv4; m_Server_EndPoint.Port = 9000; } else { clientJobHandle = m_Driver.ScheduleUpdate(inputDeps); if (m_Server_EndPoint.IsValid && m_ConnectionGroup.IsEmptyIgnoreFilter) { //Debug.Log("client job handle about to be created"); clientJobHandle = new SendConnectionRequestJob { commandBuffer = m_Barrier.CreateCommandBuffer(), driver = m_Driver, serverEndPoint = m_Server_EndPoint, }.Schedule(clientJobHandle); } clientJobHandle.Complete(); clientJobHandle = new UpdateClientJob { commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(), driver = m_Driver.ToConcurrent(), serverEndPoint = m_Server_EndPoint, }.Schedule(this, clientJobHandle); m_Barrier.AddJobHandleForProducer(clientJobHandle); return(clientJobHandle); } return(inputDeps); }
public void IPC_Setup() { IPCManager.Instance.Initialize(100); // NOTE: MaxPacketSize should be 64 for all the tests using simulator except needs to account for header size as well (one test has 2x2B headers) var simulatorParams = new SimulatorUtility.Parameters() { MaxPacketSize = 68, MaxPacketCount = 30, PacketDelayMs = 100 }; m_ServerDriver = new GenericNetworkDriver <IPCSocket, TestNetworkPipelineStageCollection>(simulatorParams); m_ServerDriver.Bind(IPCManager.Instance.CreateEndPoint()); m_ServerDriver.Listen(); m_ClientDriver = new GenericNetworkDriver <IPCSocket, TestNetworkPipelineStageCollection>(simulatorParams); m_ClientDriver2 = new GenericNetworkDriver <IPCSocket, TestNetworkPipelineStageCollection>(simulatorParams); }
void Start() { ReliableUtility.Parameters reliabilityParams = new ReliableUtility.Parameters { WindowSize = 32 }; SimulatorUtility.Parameters simulatorParams = new SimulatorUtility.Parameters { MaxPacketSize = k_PacketSize, MaxPacketCount = 30, PacketDelayMs = 100 }; m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams); m_Connection = new NativeArray <NetworkConnection>(1, Allocator.Persistent); m_Done = new NativeArray <byte>(1, Allocator.Persistent); NetworkEndPoint endpoint = NetworkEndPoint.LoopbackIpv4; endpoint.Port = 9000; m_Connection[0] = m_Driver.Connect(endpoint); }
public void IPC_Setup() { var timeoutParam = new NetworkConfigParameter { connectTimeoutMS = NetworkParameterConstants.ConnectTimeoutMS, maxConnectAttempts = NetworkParameterConstants.MaxConnectAttempts, disconnectTimeoutMS = NetworkParameterConstants.DisconnectTimeoutMS, fixedFrameTimeMS = 16 }; // NOTE: MaxPacketSize should be 64 for all the tests using simulator except needs to account for header size as well (one test has 2x2B headers) var simulatorParams = new SimulatorUtility.Parameters() { MaxPacketSize = 72, MaxPacketCount = 30, PacketDelayMs = 100 }; TestNetworkPipelineStageCollection.Register(); m_ServerDriver = TestNetworkDriver.Create(timeoutParam, simulatorParams); m_ServerDriver.Bind(NetworkEndPoint.LoopbackIpv4); m_ServerDriver.Listen(); m_ClientDriver = TestNetworkDriver.Create(timeoutParam, simulatorParams); m_ClientDriver2 = TestNetworkDriver.Create(timeoutParam, simulatorParams); }
public NetworkPipelineStage StaticInitialize(byte *staticInstanceBuffer, int staticInstanceBufferLength, INetworkParameter[] netParams) { SimulatorUtility.Parameters param = default; foreach (var netParam in netParams) { if (netParam is SimulatorUtility.Parameters) { param = (SimulatorUtility.Parameters)netParam; } } UnsafeUtility.MemCpy(staticInstanceBuffer, ¶m, UnsafeUtility.SizeOf <SimulatorUtility.Parameters>()); return(new NetworkPipelineStage( Receive: ReceiveFunctionPointer, Send: SendFunctionPointer, InitializeConnection: InitializeConnectionFunctionPointer, ReceiveCapacity: param.MaxPacketCount * (param.MaxPacketSize + UnsafeUtility.SizeOf <SimulatorUtility.DelayedPacket>()), SendCapacity: 0, HeaderCapacity: 0, SharedStateCapacity: UnsafeUtility.SizeOf <SimulatorUtility.Context>() )); }
// Setup simulation parameters which get capacity function depends on, so buffer size can be correctly allocated public void Initialize(SimulatorUtility.Parameters param) { m_SimulatorParams = param; }