Пример #1
0
        public SpacetimePanel(int w, int h, SpaceTime time = null)
        {
            this.Width  = w;
            this.Height = h;
            Background  = ConsoleColor.White;
            renderers   = new Dictionary <SpacialElement, SpacialElementRenderer>();
            thingBinder = new SpacialElementBinder();

            this.SpaceTime = time ?? new SpaceTime(w, h, increment: TimeSpan.FromSeconds(.05));
            this.SpaceTime.QueueAction(() =>
            {
                RealTimeViewing = new RealTimeViewingFunction(this.SpaceTime)
                {
                    Enabled = true
                };
                this.SpaceTime.ChangeTrackingEnabled = true;
                this.SpaceTime.AfterTick.SubscribeForLifetime(() => UpdateView(false), this.LifetimeManager);

                RealTimeViewing.Behind.SubscribeForLifetime((isBehind) =>
                {
                    Application?.QueueAction(() =>
                    {
                        Background = isBehind ? ConsoleColor.DarkYellow : ConsoleColor.White;
                    });
                }, LifetimeManager);
            });

            this.AddedToVisualTree.SubscribeForLifetime(() =>
            {
                LifetimeManager.Manage(Application.SetInterval(() =>
                {
                    RealTimeViewing?.Evaluate();
                }, TimeSpan.FromSeconds(.1)));
            }, this.LifetimeManager);

            this.SpaceTime.UnhandledException.SubscribeForLifetime((ex) =>
            {
                Application?.QueueAction(() =>
                {
                    throw new AggregateException(ex);
                });
            }, this.LifetimeManager);

            this.SubscribeForLifetime(nameof(Bounds), () => { resizedSinceLastRender = false; }, this.LifetimeManager);
        }
Пример #2
0
        public SpaceTimePanel(int w, int h, SpaceTime time = null)
        {
            this.Width  = w;
            this.Height = h;
            Background  = ConsoleColor.White;
            renderers   = new Dictionary <SpacialElement, SpacialElementRenderer>();
            thingBinder = new SpacialElementBinder();
            resetHandle = new AutoResetEvent(false);

            this.SpaceTime = time;
            if (this.SpaceTime == null)
            {
                this.SpaceTime = new SpaceTime(w, h, increment: TimeSpan.FromSeconds(.05));
                this.OnDisposed(() =>
                {
                    if (this.SpaceTime.IsRunning)
                    {
                        this.SpaceTime.Stop();
                    }
                    this.SpaceTime = null;
                });
            }

            this.SpaceTime.Invoke(() =>
            {
                RealTimeViewing = new RealTimeViewingFunction(this.SpaceTime)
                {
                    Enabled = true
                };
                this.SpaceTime.EndOfCycle.SubscribeForLifetime(() => UpdateViewInternal(), this);
            });

            this.AddedToVisualTree.SubscribeForLifetime(() =>
            {
                this.OnDisposed(() => resetHandle.Set());
            }, this);


            this.SubscribeForLifetime(nameof(Bounds), () => { resizedSinceLastRender = false; }, this);
        }
Пример #3
0
        public SpacetimePanel(int w, int h, SpaceTime time = null)
        {
            this.Width     = w;
            this.Height    = h;
            Background     = ConsoleColor.White;
            renderers      = new Dictionary <SpacialElement, SpacialElementRenderer>();
            thingBinder    = new SpacialElementBinder();
            resetHandle    = new AutoResetEvent(false);
            this.SpaceTime = time ?? new SpaceTime(w, h, increment: TimeSpan.FromSeconds(.05));
            this.SpaceTime.QueueAction(() =>
            {
                RealTimeViewing = new RealTimeViewingFunction(this.SpaceTime)
                {
                    Enabled = true
                };
                this.SpaceTime.ChangeTrackingEnabled = true;
                this.SpaceTime.AfterTick.SubscribeForLifetime(() => UpdateViewInternal(), this);
            });

            this.AddedToVisualTree.SubscribeForLifetime(() =>
            {
                this.SpaceTime.Application = this.Application;
                this.OnDisposed(() => resetHandle.Set());
            }, this);

            this.SpaceTime.UnhandledException.SubscribeForLifetime((ex) =>
            {
                resetHandle.Set();
                Application?.QueueAction(() =>
                {
                    throw new AggregateException(ex);
                });
            }, this);

            this.SubscribeForLifetime(nameof(Bounds), () => { resizedSinceLastRender = false; }, this);
        }