예제 #1
0
        public static IDisposable ListenWhile <T>(this IEventStream <T> stream, ICell <bool> listenCondition, Action <T> act)
        {
            var disp = new DoubleDisposable();

            disp.first = listenCondition.Bind(val =>
            {
                if (val)
                {
                    if (disp.disposed)
                    {
                        return;
                    }
                    if (disp.second != null)
                    {
                        throw new ZergRushException();
                    }
                    disp.second = stream.Subscribe(act);
                }
                else if (disp.second != null)
                {
                    disp.second.Dispose();
                    disp.second = null;
                }
            });
            return(disp);
        }
        public MatrixViewModel(IMatrixRepresentation matrixRepresentation, IEventStream eventStream)
        {
            this.matrixRepresentation = matrixRepresentation;
            this.eventStream          = eventStream;

            eventStream.Subscribe <MatrixSizeChanged>(OnMatrixSizeChanged);
        }
        public static ICell <Vector3> GaussFilter(this ICell <Vector3> value,
                                                  IEventStream sampler, int samples, IConnectionSink connectionSink, bool prefill = false)
        {
            var filter = prefill ? new GaussFilteredVector(samples, value.value) : new GaussFilteredVector(samples);

            connectionSink.AddConnection(sampler.Subscribe(() => { filter.PushValue(value.value); }));
            return(filter);
        }
예제 #4
0
        public ShellViewModel(
            IMatrixViewModel matrix,
            IMatrixSettingsViewModel matrixSettings,
            IEventStream eventStream)
        {
            this.Matrix         = matrix;
            this.MatrixSettings = matrixSettings;

            eventStream.Subscribe <MatrixChanged>(OnMatrixChanged);
        }
예제 #5
0
        public static async Task SingleMessageAsync(this IEventStream stream)
        {
            bool finished = false;
            var  waiting  = stream.Subscribe(() => { finished = true; });

            while (!finished)
            {
                await frame;
            }
        }
        // On each event it makes |\____|\_______|\_____....
        public static ICell <float> SignalTrigger(this IEventStream e, float decayTime, IConnectionSink connectionSink)
        {
            TriggerCell cell = new TriggerCell {
                decay = decayTime
            };

            connectionSink.AddConnection(UnityExecutor.Instance.AddUpdatable(cell));
            connectionSink.AddConnection(e.Subscribe(cell.Reset));
            return(cell);
        }
예제 #7
0
        public static async Task <T> SingleMessageAsync <T>(this IEventStream <T> stream)
        {
            T    result   = default(T);
            bool finished = false;
            var  waiting  = stream.Subscribe(res => { result = res; finished = true; });

            while (!finished)
            {
                await frame;
            }
            return(result);
        }
예제 #8
0
 public static IEventStream Once(this IEventStream stream)
 {
     return(new AnonymousEventStream((Action reaction) =>
     {
         var disp = new SingleDisposable();
         disp.Disposable = stream.Subscribe(() =>
         {
             reaction();
             disp.Dispose();
         });
         return disp;
     }));
 }
        public static ICell <float> DecayingPush(this IEventStream <float> e, float ampPerPush, float asymptote,
                                                 IConnectionSink sink)
        {
            Cell <float> value = new Cell <float>();

            sink.AddConnection(e.Subscribe(val =>
            {
                value.value = Mathf.Atan((value.value + ampPerPush * val) / asymptote) / (Mathf.PI / 4) * asymptote;
            }));
            sink.AddConnection(
                UnityExecutor.Instance.AddUpdatable(new AnonymousUpdatable(dt => { value.value /= 1.1f; })));
            return(value);
        }
예제 #10
0
 // Result stream is called only once, then the connection is disposed.
 public static IEventStream <T> Once <T>(this IEventStream <T> eventStream)
 {
     return(new AnonymousEventStream <T>((Action <T> reaction) =>
     {
         var disp = new SingleDisposable();
         disp.Disposable = eventStream.Subscribe(val =>
         {
             reaction(val);
             disp.Dispose();
         });
         return disp;
     }));
 }
예제 #11
0
 public static IEventStream WhenTrue(this IEventStream <bool> stream)
 {
     return(new AnonymousEventStream(reaction =>
     {
         return stream.Subscribe(v =>
         {
             if (v)
             {
                 reaction();
             }
         });
     }));
 }
예제 #12
0
 public static IEventStream Filter(this IEventStream eventStream, Func <bool> filter)
 {
     return(new AnonymousEventStream(reaction =>
     {
         return eventStream.Subscribe(() =>
         {
             if (filter())
             {
                 reaction();
             }
         });
     }));
 }
예제 #13
0
 public static IEventStream <T> Filter <T>(this IEventStream <T> eventStream, Func <T, bool> filter)
 {
     return(new AnonymousEventStream <T>(reaction =>
     {
         return eventStream.Subscribe(val =>
         {
             if (filter(val))
             {
                 reaction(val);
             }
         });
     }));
 }
        public static CellOfSin SignalSin(this IEventStream reset, float scale, float speed, float resetVal,
                                          IConnectionSink connectionSink)
        {
            CellOfSin cell = new CellOfSin {
                scale = scale, speed = speed
            };

            connectionSink.AddConnection(UnityExecutor.Instance.AddUpdatable(cell));
            if (reset != null)
            {
                connectionSink.AddConnection(reset.Subscribe(() => cell.Reset(resetVal)));
            }
            return(cell);
        }
        // On each event it makes /--\____/--\________....
        public static ICell <float> SignalSpike(this IEventStream e, float attack, float plato, float decay,
                                                IConnectionSink connectionSink)
        {
            SpikeCell cell = new SpikeCell
            {
                attackPoint = attack,
                platoPoint  = attack + plato,
                decayPoint  = attack + plato + decay
            };

            connectionSink.AddConnection(UnityExecutor.Instance.AddUpdatable(cell));
            connectionSink.AddConnection(e.Subscribe(cell.Reset));
            return(cell);
        }
예제 #16
0
 public WaitForEvent(IEventStream stream, float timeout = -1)
 {
     this.timeout = timeout;
     connection   = stream.Subscribe(() =>
     {
         connection.DisconnectSafe();
         ready      = true;
         connection = null;
     });
     if (ready)
     {
         connection.Dispose();
     }
 }
예제 #17
0
        public static IEventStream MergeWith(this IEventStream stream, params IEventStream[] others)
        {
            if (stream == null || others == null || others.Any(s => s == null))
            {
                throw new ArgumentException("Null streams in merge");
            }
            return(new AnonymousEventStream(reaction =>
            {
                var disp = new Connections(others.Length + 1);
                disp.Add(stream.Subscribe(reaction));
                foreach (var other in others)
                {
                    disp.Add(other.Subscribe(reaction));
                }

                return disp;
            }));
        }
예제 #18
0
 public static void Subscribe <T>(this IEventStream <T> stream, IConnectionSink connectionSink, Action <T> action)
 {
     connectionSink.AddConnection(stream.Subscribe(action));
 }
예제 #19
0
 public static void Subscribe(this IEventStream e, IConnectionSink connectionSink, Action action)
 {
     connectionSink.AddConnection(e.Subscribe(action));
 }
예제 #20
0
 // Transforms stream value with a function.
 public static IEventStream <T2> Map <T2>(this IEventStream eventStream, Func <T2> map)
 {
     return(new AnonymousEventStream <T2>(reaction => { return eventStream.Subscribe(() => reaction(map())); }));
 }