コード例 #1
0
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
        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);
        }
コード例 #2
0
        public MatrixViewModel(IMatrixRepresentation matrixRepresentation, IEventStream eventStream)
        {
            this.matrixRepresentation = matrixRepresentation;
            this.eventStream          = eventStream;

            eventStream.Subscribe <MatrixSizeChanged>(OnMatrixSizeChanged);
        }
コード例 #3
0
        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
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
        public static async Task SingleMessageAsync(this IEventStream stream)
        {
            bool finished = false;
            var  waiting  = stream.Subscribe(() => { finished = true; });

            while (!finished)
            {
                await frame;
            }
        }
コード例 #6
0
        // 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
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
        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
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
 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;
     }));
 }
コード例 #9
0
        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
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
 // 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
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
 public static IEventStream WhenTrue(this IEventStream <bool> stream)
 {
     return(new AnonymousEventStream(reaction =>
     {
         return stream.Subscribe(v =>
         {
             if (v)
             {
                 reaction();
             }
         });
     }));
 }
コード例 #12
0
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
 public static IEventStream Filter(this IEventStream eventStream, Func <bool> filter)
 {
     return(new AnonymousEventStream(reaction =>
     {
         return eventStream.Subscribe(() =>
         {
             if (filter())
             {
                 reaction();
             }
         });
     }));
 }
コード例 #13
0
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
 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);
             }
         });
     }));
 }
コード例 #14
0
        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);
        }
コード例 #15
0
        // 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
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
        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
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
 public static void Subscribe <T>(this IEventStream <T> stream, IConnectionSink connectionSink, Action <T> action)
 {
     connectionSink.AddConnection(stream.Subscribe(action));
 }
コード例 #19
0
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
 public static void Subscribe(this IEventStream e, IConnectionSink connectionSink, Action action)
 {
     connectionSink.AddConnection(e.Subscribe(action));
 }
コード例 #20
0
ファイル: EventStream.cs プロジェクト: CeleriedAway/ZergRush
 // 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())); }));
 }