Ejemplo n.º 1
0
 public WaitForSeconds(Coroutine coroutine, double seconds)
 {
     this.coroutine = coroutine;
     TimeoutEvent e = new TimeoutEvent { Key = this };
     token = Flow.Bind(e, OnTimeout);
     TimeFlow.Default.Reserve(e, seconds);
 }
Ejemplo n.º 2
0
        protected WaitForMultipleEvents(Coroutine coroutine, Event[] requests,
            double seconds, params Event[] e)
        {
            this.coroutine = coroutine;

            if (!Object.ReferenceEquals(requests, null))
            {
                waitHandle = WaitHandlePool.Acquire();
                for (int i = 0, count = requests.Length; i < count; ++i)
                {
                    requests[i]._WaitHandle = waitHandle;
                }
                for (int i = 0, count = e.Length; i < count; ++i)
                {
                    e[i]._WaitHandle = waitHandle;
                }
            }

            expected = e;
            actual = new Event[expected.Length];

            handlerTokens = new Binder.Token[expected.Length];
            for (int i = 0; i < expected.Length; ++i)
            {
                handlerTokens[i] = Flow.Bind(expected[i], OnEvent);
            }

            if (seconds > 0)
            {
                TimeoutEvent timeoutEvent = new TimeoutEvent { Key = this };
                timeoutToken = Flow.Bind(timeoutEvent, OnTimeout);
                timerToken = TimeFlow.Default.Reserve(timeoutEvent, seconds);
            }
        }
Ejemplo n.º 3
0
 public WaitForNothing(Coroutine coroutine, object result)
 {
     this.coroutine = coroutine;
     this.result = result;
     TimeoutEvent e = new TimeoutEvent { Key = this };
     token = Flow.Bind(e, OnTimeout);
     Hub.Post(e);
 }
Ejemplo n.º 4
0
 public WaitForSingleEvent(Coroutine coroutine, Event e, double seconds)
 {
     this.coroutine = coroutine;
     handlerToken = Flow.Bind(e, OnEvent);
     if (seconds >= 0)
     {
         TimeoutEvent timeoutEvent = new TimeoutEvent { Key = this };
         timeoutToken = Flow.Bind(timeoutEvent, OnTimeout);
         timerToken = TimeFlow.Default.Reserve(timeoutEvent, seconds);
     }
 }
Ejemplo n.º 5
0
        protected WaitForSingleEvent(Coroutine coroutine, Event request, Event e, double seconds)
        {
            this.coroutine = coroutine;

            if (!Object.ReferenceEquals(request, null))
            {
                int waitHandle = WaitHandlePool.Acquire();
                request._WaitHandle = waitHandle;
                e._WaitHandle = waitHandle;
            }

            handlerToken = Flow.Bind(e, OnEvent);
            if (seconds > 0)
            {
                TimeoutEvent timeoutEvent = new TimeoutEvent { Key = this };
                timeoutToken = Flow.Bind(timeoutEvent, OnTimeout);
                timerToken = TimeFlow.Default.Reserve(timeoutEvent, seconds);
            }
        }
Ejemplo n.º 6
0
        void OnEvent(Event e)
        {
            for (int i = 0; i < expected.Length; ++i)
            {
                if (actual[i] == null && expected[i].Equivalent(e))
                {
                    Flow.Unbind(handlerTokens[i]);
                    handlerTokens[i] = new Binder.Token();
                    actual[i] = e;
                    ++count;
                    break;
                }
            }

            if (count >= expected.Length)
            {
                if (timerToken.HasValue)
                {
                    TimeFlow.Default.Cancel(timerToken.Value);
                    Flow.Unbind(timeoutToken);
                }

                if (waitHandle != 0)
                {
                    WaitHandlePool.Release(waitHandle);
                }

                coroutine.Result = actual;
                coroutine.Continue();
            }
        }