private void OnOpenReceived()
 {
     coroutineRunner.Run(() =>
     {
         OnOpen?.Invoke();
     });
 }
        public IEnumerator SendRequests_WithValidUrls_AllCompleted()
        {
            var worker            = new UnityHttpWorker();
            int serverErrorCount  = 0;
            int networkErrorCount = 0;

            worker.ServerErrorOccured  += req => serverErrorCount++;
            worker.NetworkErrorOccured += req => networkErrorCount++;
            var runner = new CoroutineRunner();

            IHttpResponse[] responses = new IHttpResponse[15];

            for (int i = 0; i < responses.Length; i++)
            {
                int index = i;

                var request = HttpRequestBuilder.CreateGet(string.Format("http://www.example.com/?id={0}", i))
                              .GetResult();

                runner.Run(worker.SendRequest(request, rsp => responses[index] = rsp));
            }

            yield return(new WaitUntil(() => responses.All(req => req != null)));

            TestHelper.Assert.That(serverErrorCount, Is.EqualTo(0));
            TestHelper.Assert.That(networkErrorCount, Is.EqualTo(0));
            Assert.That(responses.Count(req => req != null), Is.EqualTo(15));
        }
Exemple #3
0
        public MobileARSupportProvider()
        {
            var currentARSessionState = Observable
                                        .FromEvent <ARSessionStateChangedEventArgs>(
                h => ARSession.stateChanged += h,
                h => ARSession.stateChanged -= h)
                                        .Select(args => args.state)
                                        .ToReadOnlyReactiveProperty(ARSession.state);

            ARIsCheckedAndSupported = currentARSessionState
                                      .Select(state =>
                                              !(state == ARSessionState.None || state == ARSessionState.CheckingAvailability || state == ARSessionState.Unsupported))
                                      .ToReadOnlyReactiveProperty();

            ARIsReady = currentARSessionState
                        .Select(state =>
                                state == ARSessionState.Ready || state == ARSessionState.SessionInitializing || state == ARSessionState.SessionTracking)
                        .ToReadOnlyReactiveProperty();

            NeedInstall = currentARSessionState
                          .Select(state => state == ARSessionState.NeedsInstall)
                          .ToReadOnlyReactiveProperty();

            IsInstalling = currentARSessionState
                           .Select(state => state == ARSessionState.Installing)
                           .ToReadOnlyReactiveProperty();

            AddDisposable(currentARSessionState);

            CoroutineRunner.Run(CheckAvailability());
        }
Exemple #4
0
        public ConstantChangeDetection(Func <bool> changeCondition, Action <bool> action, Func <bool> activeAction)
        {
            _condition    = changeCondition;
            _action       = action;
            _activeAction = activeAction;

            _coroutine = CoroutineRunner.Run(Update());
        }
        public ChangeDetection(Func <bool> changeCondition, Action <bool> detectAction, Func <bool> activeCondition = null, Func <float> delay = null)
        {
            _changeCondition = changeCondition;
            _delay           = delay;
            _detectAction    = detectAction;
            _activeCondition = activeCondition;

            _coroutine = CoroutineRunner.Run(Update());
        }
        public void UpdateTickSource()
        {
            m_RuntimeUpdateDisposable?.Dispose();
            EditorUpdateInvokerBridge.Update -= Tick;

            if (Application.isPlaying)
            {
                m_RuntimeUpdateDisposable = CoroutineRunner.Run(UpdateCoroutine());
            }
            else
            {
                EditorUpdateInvokerBridge.Update += Tick;
            }
        }
        /// <summary>
        /// Enqueue Game Server to Joinable Session Queue.
        /// this will make this server joinable by other parties while already in a session.
        /// </summary>
        /// <param name="body">the session's data (get this data from QuerySessionStatus)</param>
        /// <param name="callback">the result of this operation</param>
        public void EnqueueJoinableSession(MatchmakingResult body, ResultCallback callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (!this.serverSession.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);
                return;
            }

            coroutineRunner.Run(api.EnqueueJoinableSession(this.@namespace, serverSession.AuthorizationToken, body, callback));
        }
        /// <summary>
        /// Retrieve all active latest policies based on a namespace.
        /// The country will be read from user token.
        /// </summary>
        /// <param name="namespace">Filter the responded policy by namespace</param>
        /// <param name="agreementPolicyType">Filter the responded policy by policy type. Choose the AgreementPolicyType.EMPTY if you want to be responded with all policy type.</param>
        /// <param name="defaultOnEmpty">Specify with true if you want to be responded with default country-specific policy if your requested country is not exist.</param>
        /// <param name="callback">Returns a Result that contains an array of public policy via callback when completed</param>
        public void GetLegalPolicies(string namespace_, AgreementPolicyType agreementPolicyType, string[] tags, bool defaultOnEmpty, ResultCallback <PublicPolicy[]> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);

            if (session == null || session.AuthorizationToken == null)
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);
                return;
            }

            coroutineRunner.Run(
                api.GetLegalPolicies(namespace_, agreementPolicyType, tags, defaultOnEmpty, session.AuthorizationToken, callback));
        }
Exemple #9
0
        public IEnumerable <Vector3Int> RunProgressive()
        {
            while (true)
            {
                if (!Observe(out var chunkPos))
                {
                    yield break;
                }

                // PropagateProgressive();
                CoroutineRunner.Run(PropagateProgressive().GetEnumerator());
                // foreach (var t in PropagateProgressive())
                // {
                //     yield return chunkPos;
                // }

                yield return(chunkPos);
            }
        }
Exemple #10
0
    public void ReceivePackets(UdpSocket udpSocket, SenderPacketInfo senderPacketSet, Material material, RingBuffer ringBuffer)
    {
        videoMessageAssembler.Assemble(udpSocket,
                                       senderPacketSet.VideoPackets,
                                       senderPacketSet.ParityPackets,
                                       textureSetUpdater.lastFrameId,
                                       VideoMessages);

        if (textureSetUpdater.State == PrepareState.Unprepared && VideoMessages.Count > 0)
        {
            foreach (var videoMessage in VideoMessages.Values)
            {
                CoroutineRunner.Run(textureSetUpdater.Prepare(material, videoMessage));
                break;
            }
        }

        audioReceiver.Receive(senderPacketSet.AudioPackets, ringBuffer);

        if (senderPacketSet.ReceivedAny)
        {
            receivedAnyStopWatch = Stopwatch.StartNew();
        }
    }
Exemple #11
0
        public void SetBoundaryPattern(Pattern <T> boundPattern)
        {
            var bounds = new BoundsInt(Vector3Int.zero, Size);

            for (var idx = 0; idx < NeighborOffset.Length; idx++)
            {
                var offset      = NeighborOffset[idx];
                var contraryIdx = NeighborOffset.IndexOf(-offset);
                foreach (var pos in bounds.BoundaryIter(offset))
                {
                    var chunk = ChunkStates[pos.x, pos.y, pos.z];
                    var count = chunk.Compatibles.Count;
                    // chunk.Compatibles.RemoveWhere(p => !p.Neighbors[idx].Contains(boundPattern));
                    chunk.UpdateCompatibleFrom(boundPattern.Neighbors[contraryIdx]);

                    if (count != chunk.Compatibles.Count)
                    {
                        _propagationStack.Push(pos);
                    }
                }
            }

            CoroutineRunner.Run(PropagateProgressive().GetEnumerator());
        }
Exemple #12
0
        public static void Main(string[] args)
        {
            //Timer variables to run the update loop at 10 fps
            var         watch       = Stopwatch.StartNew();
            const float updateRate  = 1f / 10f;
            var         prevTime    = watch.ElapsedMilliseconds / 1000f;
            var         accumulator = 0f;

            //The little @ character's position
            var px = 0;
            var py = 0;

            //Routine to move horizontally
            IEnumerator <object?> MoveX(int amount, float stepTime)
            {
                var dir = amount > 0 ? 1 : -1;

                while (amount != 0)
                {
                    yield return(stepTime);

                    px     += dir;
                    amount -= dir;
                }
            }

            //Routine to move vertically
            IEnumerator <object?> MoveY(int amount, float stepTime)
            {
                var dir = amount > 0 ? 1 : -1;

                while (amount != 0)
                {
                    yield return(stepTime);

                    py     += dir;
                    amount -= dir;
                }
            }

            //Walk the little @ character on a path
            IEnumerator <object?> Movement()
            {
                //Walk normally
                yield return(MoveX(5, 0.25f));

                yield return(MoveY(5, 0.25f));

                //Walk slowly
                yield return(MoveX(2, 0.5f));

                yield return(MoveY(2, 0.5f));

                yield return(MoveX(-2, 0.5f));

                yield return(MoveY(-2, 0.5f));

                //Run fast
                yield return(MoveX(5, 0.1f));

                yield return(MoveY(5, 0.1f));
            }

            //Render a little map with the @ character in the console
            void DrawMap()
            {
                Console.Clear();
                for (var y = 0; y < 16; ++y)
                {
                    for (var x = 0; x < 16; ++x)
                    {
                        if (x == px && y == py)
                        {
                            Console.Write('@');
                        }
                        else
                        {
                            Console.Write('.');
                        }
                    }
                    Console.WriteLine();
                }
            }

            //Run the coroutine
            var runner = new CoroutineRunner();
            var moving = runner.Run(Movement());

            //Run the update loop until we've finished moving
            while (moving.IsRunning)
            {
                //Track time
                var currTime = watch.ElapsedMilliseconds / 1000f;
                accumulator += currTime - prevTime;
                prevTime     = currTime;

                //Update at our requested rate (10 fps)
                if (accumulator > updateRate)
                {
                    accumulator -= updateRate;
                    runner.Update(updateRate);
                    DrawMap();
                }
            }
        }
 private void StartTelemetryScheduler()
 {
     telemetryCoroutine    = coroutineRunner.Run(RunPeriodicTelemetry());
     isTelemetryJobStarted = true;
 }
 public EnemyController()
 {
     EventBroker.Register <SpawnEvent>(OnSpawned);
     runner.Run(Spawner());
 }
Exemple #15
0
 public async void Run()
 {
     currentTask = _runner.Run(_run());
 }
Exemple #16
0
 public void Send(string method, string json = "{}", Action <ErrorCode, string> cb = null)
 {
     CoroutineRunner.Run(InternalSend(method, json, cb));
 }
        public IEnumerator SendRequests_WithSomeTimeout_AllCompleted()
        {
            int serverErrorCount  = 0;
            int networkErrorCount = 0;
            var worker            = new UnityHttpWorker();

            worker.ServerErrorOccured  += req => serverErrorCount++;
            worker.NetworkErrorOccured += req => networkErrorCount++;
            var otherWorker = new UnityHttpWorker();

            otherWorker.ServerErrorOccured  += req => serverErrorCount++;
            otherWorker.NetworkErrorOccured += req => networkErrorCount++;
            var runner = new CoroutineRunner();

            IHttpResponse[] responses = new IHttpResponse[15];

            for (int i = 0; i < 15; i++)
            {
                IHttpRequest request;
                int          index = i;


                switch (i % 5)
                {
                case 0:
                    request = HttpRequestBuilder.CreateGet(string.Format("http://www.example.com/?id={0}", i)).GetResult();
                    runner.Run(worker.SendRequest(request, req => responses[index] = req));

                    break;

                case 1:
                    request = HttpRequestBuilder.CreateGet(string.Format("http://accelbyte.example/?id={0}", i)).GetResult();
                    runner.Run(worker.SendRequest(request, req => responses[index] = req));

                    break;

                case 2:
                    request = HttpRequestBuilder.CreateGet(
                        string.Format("http://www.mocky.io/v2/5c38bc153100006c00a991ed?mocky-delay=10s&id={0}", i)).GetResult();
                    runner.Run(worker.SendRequest(request, req => responses[index] = req));

                    break;

                case 3:
                    request = HttpRequestBuilder.CreateGet(
                        string.Format("http://www.mocky.io/v2/5c38bc153100006c00a991ed?mocky-delay=10s&id={0}", i)).GetResult();
                    otherWorker.SetRetryParameters(5000);
                    runner.Run(otherWorker.SendRequest(request, req => responses[index] = req));

                    break;

                case 4:
                    request = HttpRequestBuilder.CreateGet(
                        string.Format("http://www.mocky.io/v2/5c37fc0330000054001f659d?mocky-delay=15s&id={0}", i)).GetResult();
                    runner.Run(worker.SendRequest(request, req => responses[index] = req));

                    break;
                }
            }

            yield return(new WaitForSeconds(3));

            Assert.That(responses.Count(req => req != null), Is.EqualTo(6));

            yield return(new WaitForSeconds(5));

            Assert.That(responses.Count(req => req != null), Is.EqualTo(9));

            yield return(new WaitForSeconds(5));

            Assert.That(responses.Count(req => req != null), Is.EqualTo(12));

            yield return(new WaitForSeconds(5));

            Assert.That(responses.Count(req => req != null), Is.EqualTo(15));

            Assert.That(serverErrorCount, Is.EqualTo(0));
            Assert.That(networkErrorCount, Is.EqualTo(6));
        }
Exemple #18
0
 public void InstallARSoftware()
 {
     CoroutineRunner.Run(ARSession.Install());
 }