Exemplo n.º 1
0
 public void Inject(float energy, Vector4 color)
 {
     lock (this)
     {
         var output = Math.Max(0, -energy);
         _nextInjected += new BeamSegmentData(energy, energy * color, output, output * color);
     }
 }
Exemplo n.º 2
0
        public override void Commit(float dt)
        {
            lock (this)
            {
                _next        += _nextInjected;
                _nextInjected = new BeamSegmentData(0, Vector4.Zero, 0, Vector4.Zero);
            }

            var output      = _next.Output / Math.Max(1e-6f, dt);
            var outputColor = _next.WeightedOutputColor / Math.Max(1e-6f, dt);

            Current = new BeamSegmentData(_next.Energy,
                                          Vector4.Clamp(_next.WeightedColor, Vector4.Zero, _next.Energy * Vector4.One), output, outputColor);
            CurrentEma = CurrentEma * 0.975f + Current * 0.025f;

            RaiseStateChanged();
        }
Exemplo n.º 3
0
        protected override void PredictConnection(Connection <Segment, BeamConnectionData> con, float dt)
        {
            var opponent = con.From.Segment == this ? con.To.Segment : con.From.Segment;

            if (opponent == this)
            {
                return;
            }
            var dE = (opponent.Current.Energy - Current.Energy) / 2f;

            if (!float.IsPositiveInfinity(con.Data.MaxThroughput))
            {
                dE = Math.Sign(dE) * Math.Min(Math.Abs(dE), con.Data.MaxThroughput * dt);
            }
            if (con.From.Segment == this && !con.Data.Bidirectional)
            {
                dE = Math.Min(0, dE);
            }
            else if (con.To.Segment == this && !con.Data.Bidirectional)
            {
                dE = Math.Max(0, dE);
            }

            var     sourceColor = dE > 0 ? opponent.Current.Color : Current.Color;
            Vector4 mixColor    = sourceColor;

            mixColor *= con.Data.Filter;
            if (Math.Abs(mixColor.X) + Math.Abs(mixColor.Y) + Math.Abs(mixColor.Y) <= 1e-1f)
            {
                mixColor = new Vector4(1e-1f, 1e-1f, 1e-1f, 1) / 3;
            }

            // always subtract the source energy color, add the mixed color.
            var dColor = dE * (dE > 0 ? mixColor : sourceColor);
            var output = Math.Max(-dE, 0);

            _next += new BeamSegmentData(dE, dColor, output, output * mixColor);
        }
Exemplo n.º 4
0
 public override void Predict(float dt)
 {
     _next = new BeamSegmentData(Current.Energy, Current.WeightedColor, 0, Vector4.Zero);
     base.Predict(dt);
 }