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)); }
protected override void OnCreate() { var rpcSystem = World.GetOrCreateSystem <RpcSystem>(); rpcSystem.RegisterRpc <TActionRequest>(); m_CommandBufferSystem = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>(); m_RpcQueue = rpcSystem.GetRpcQueue <TActionRequest>(); m_ConnectionsQuery = EntityManager.CreateEntityQuery(ComponentType.ReadWrite <NetworkIdComponent>(), ComponentType.Exclude <NetworkStreamDisconnected>()); }
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 }