protected override void OnCreate() { 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 UdpNetworkDriver(netParams, simulatorParams, reliabilityParams); UnityEngine.Debug.Log($"Using simulator with latency={m_ClientPacketDelay} packet drop={m_ClientPacketDrop}"); #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 = World.GetOrCreateSystem <RpcSystem>().GetRpcQueue <RpcSetNetworkId>(); m_NetworkStreamConnectionQuery = EntityManager.CreateEntityQuery(typeof(NetworkStreamConnection)); #if UNITY_EDITOR || DEVELOPMENT_BUILD m_NetStats = new NativeArray <uint>(1, Allocator.Persistent); m_GhostStatsCollectionSystem = World.GetOrCreateSystem <GhostStatsCollectionSystem>(); #endif }
protected override void OnCreate() { #if UNITY_EDITOR || DEVELOPMENT_BUILD m_GhostStatsCollectionSystem = World.GetOrCreateSystem <GhostStatsCollectionSystem>(); m_NetStats = new NativeArray <uint>(2, Allocator.Persistent); #endif serverSimulationSystemGroup = World.GetExistingSystem <ServerSimulationSystemGroup>(); m_CompressionModel = new NetworkCompressionModel(Allocator.Persistent); RequireForUpdate(EntityManager.CreateEntityQuery( ComponentType.ReadOnly <NetworkStreamInGame>(), ComponentType.ReadOnly <IncomingCommandDataStreamBufferComponent>(), ComponentType.ReadOnly <NetworkSnapshotAckComponent>(), ComponentType.ReadOnly <CommandTargetComponent>(), ComponentType.Exclude <NetworkStreamDisconnected>())); if (typeof(TCommandData) != typeof(NullCommandData)) { RequireForUpdate(EntityManager.CreateEntityQuery(ComponentType.ReadWrite <TCommandData>())); } }
protected override void OnCreate() { if (World.GetExistingSystem <ServerSimulationSystemGroup>() != null) { DriverConstructor.CreateServerDriver(World, out m_Driver, out m_UnreliablePipeline, out m_ReliablePipeline); } else { DriverConstructor.CreateClientDriver(World, out m_Driver, out m_UnreliablePipeline, out m_ReliablePipeline); } m_ConcurrentDriver = m_Driver.ToConcurrent(); 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)); #if UNITY_EDITOR || DEVELOPMENT_BUILD m_NetStats = new NativeArray <uint>(1, Allocator.Persistent); m_GhostStatsCollectionSystem = World.GetOrCreateSystem <GhostStatsCollectionSystem>(); #endif }