Exemplo n.º 1
0
        public override Boolean Loop(Genie.Yuk.Event _event)
        {
            WinUtility        win   = Service.Resolve <WinUtility>();
            GameGraphics      gg    = Service.Resolve <GameGraphics>();
            CancellationToken token = Service.Resolve <CancellationToken>();

            if (_event != null)
            {
                if (_event.GetType() == typeof(StartEvent))
                {
                    Action myAction0 = (Action)(() =>
                    {
                        gg.Start();
                    });

                    Task taskA = Task.Run(myAction0);
                    taskA.Wait();

                    Action myAction1 = (Action)(() =>
                    {
                        while (!token.IsCancellationRequested)
                        {
                            gg.AlwaysRun();
                        }
                    });

                    win.OnUiThread(myAction1);

                    EventQueueClient.Enqueue(new GraphicsEvent());
                }
                else if (_event.GetType() == typeof(GraphicsEvent))
                {
                    lock (WriteServer.balanceLock)
                    {
                        ComponentManager.Update();
                        gg.Run(token);

                        System.Console.WriteLine("Draw Client");
                    }

                    EventQueueClient.Enqueue(new GraphicsEvent());
                }
                else if (_event.GetType() == typeof(JobEvent))
                {
                    JobEvent job = (JobEvent)_event;

                    Boolean doLoop = true;

                    while (doLoop)
                    {
                        try
                        {
                            Genie.Yuk.Event tmpEvent = job.Dequeue();
                            Loop(tmpEvent);
                        }
                        catch (InvalidOperationException e)
                        {
                            doLoop = false;
                        }
                    }
                }
                else if (_event.GetType() == typeof(StopEvent))
                {
                    System.Console.WriteLine("Stop");
                    return(false);
                }
            }

            return(true);
        }