Пример #1
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            //check if set is called at all (if not, quit early)
            if (!FInSet.Any(value => value == true))
            {
                return;
            }

            //update inputs
            {
                FInSlides.Sync();
                FInTransform.Sync();
                SpreadMax = Utils.SpreadMax(FInSlides, FInTransform, FInSet);
            }

            for (int i = 0; i < SpreadMax; i++)
            {
                if (FInSet[i])
                {
                    var slide = FInSlides[i];
                    if (slide != null)
                    {
                        slide.Transform = FInTransform[i];
                    }
                }
            }
        }
Пример #2
0
        public void Evaluate(int SpreadMax)
        {
            FOutput.Resize(SpreadMax, () => new MemoryComStream(), str => str.Dispose());
            FMmf.SliceCount = SpreadMax;
            for (int i = 0; i < SpreadMax; i++)
            {
                if (string.IsNullOrWhiteSpace(FName[i]))
                {
                    continue;
                }
                if (FOpen[i] && !_mmfs.ContainsKey(FName[i]))
                {
                    try
                    {
                        var mmf = MemoryMappedFile.OpenExisting(FName[i]);
                        _mmfs.Add(FName[i], mmf);
                    }
                    catch
                    { }
                }

                if ((FOpen[i] || FRead[i]) && _mmfs.ContainsKey(FName[i]))
                {
                    var mmf = _mmfs[FName[i]];
                    FMmf[i] = mmf;
                    if (FOutput[i] == null)
                    {
                        FOutput[i] = new MemoryComStream();
                    }
                    if (FSize[i] == 0)
                    {
                        using (var accessor = mmf.CreateViewStream())
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                    }
                    else
                    {
                        using (var accessor = mmf.CreateViewStream(FOffset[i], FSize[i]))
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                    }
                }
            }

            FOutput.Stream.IsChanged = false;
            if (FRead.Any() || FOpen.Any())
            {
                FOutput.Flush(true);
            }
        }
Пример #3
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            //check if delete is called at all (if not, quit early)
            if (!FInDelete.Any(value => value == true))
            {
                return;
            }

            //update inputs
            {
                FInSlides.Sync();
                SpreadMax = Utils.SpreadMax(FInSlides, FInDelete);
            }


            for (int i = 0; i < SpreadMax; i++)
            {
                if (FInDelete[i])
                {
                    var slide = FInSlides[i];
                    if (slide != null)
                    {
                        World world;
                        if (slide.World.TryGetTarget(out world))
                        {
                            if (world.Slides.Contains(slide))
                            {
                                world.Slides.Remove(slide);
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        public override void Evaluate(int SpreadMax)
        {
            InitDX11Graph();

            bool warnPinSafety = false;

            if (RemovePinsFirst)
            {
                warnPinSafety = !RetryConfig();
            }

            if (!FNew.Any()) // if none true
            {
                FOutput.FlushNil();
                return;
            }

            SpreadMax = FNew.CombineWith(FTopic);
            foreach (string name in FPins.Keys)
            {
                var pin = FPins[name].ToISpread();
                pin.Sync();
                SpreadMax = Math.Max(pin.SliceCount, SpreadMax);
            }

            FOutput.SliceCount = 0;
            for (int i = 0; i < SpreadMax; i++)
            {
                if (FNew[i])
                {
                    var message = new Message();

                    message.Topic = FTopic[i];
                    foreach (string name in FPins.Keys)
                    {
                        var pin = FPins[name].ToISpread();
                        if (pin.SliceCount > 0)
                        {
                            message.AssignFrom(name, pin[i] as ISpread);
                        }
                        else
                        {
                            message[name] = BinFactory.New(Formular[name].Type);  // will do empty spreads as well, but ignore faults
                        }
                    }
                    FOutput.Add(message);
                }
            }
            FOutput.Flush();

            if (warnPinSafety)
            {
                throw new PinConnectionException("Manually remove unneeded links first! [Create]. ID = [" + PluginHost.GetNodePath(false) + "]");
            }
        }
Пример #5
0
        public override void Evaluate(int SpreadMax)
        {
            // graceful fallback when being fed bad data
            if (FNew.IsAnyInvalid() || FTopic.IsAnyInvalid() || FSpreadCount.IsAnyInvalid())
            {
                FOutput.FlushNil();
                return;
            }

            if (!FNew.Any() && !ForceNewDefaults)
            {
                FOutput.FlushNil();
                return;
            }

            SpreadMax          = FFormularSelection.SliceCount; // numbers of supported Formulars
            FOutput.SliceCount = SpreadMax;

            var counter = 0;

            for (int i = 0; i < SpreadMax; i++)
            {
                var             formularName = FFormularSelection[i].Name;
                MessageFormular formular;
                try
                {
                    formular = RetrieveRegisteredFormular(formularName);
                } catch (RegistryException)
                {
                    formular = null;
                }

                if (formular == null || formular.IsDynamic)
                {
                    formular = new MessageFormular(formularName, ""); // empty fallback, in case not available or dynamic
                }
                FOutput[i].SliceCount = 0;

                var count = FSpreadCount[i];
                for (int j = 0; j < count; j++)
                {
                    if (FNew[counter] || ForceNewDefaults)
                    {
                        Message message = new Message(formular);
                        message.Topic = FTopic[counter];
                        FOutput[i].Add(message);
                    }
                    counter++;
                }
            }
            FOutput.Flush();

            ForceNewDefaults = false;
        }
Пример #6
0
        public override void Evaluate(int SpreadMax)
        {
            if (!FNew.Any()) // if none true
            {
                FOutput.FlushNil();
                if (RemovePinsFirst)
                {
                    RetryConfig();
                }
                return;
            }

            SpreadMax = FNew.CombineWith(FTopic);
            foreach (string name in FPins.Keys)
            {
                var pin = FPins[name].ToISpread();
                pin.Sync();
                SpreadMax = Math.Max(pin.SliceCount, SpreadMax);
            }

            FOutput.SliceCount = 0;
            for (int i = 0; i < SpreadMax; i++)
            {
                if (FNew[i])
                {
                    var message = new Message();

                    message.Topic = FTopic[i];
                    foreach (string name in FPins.Keys)
                    {
                        var pin = FPins[name].ToISpread();
                        if (pin.SliceCount > 0)
                        {
                            message.AssignFrom(name, pin[i] as ISpread);
                        }
                        else
                        {
                            message[name] = BinFactory.New(Formular[name].Type);  // will do empty spreads as well, but ignore faults
                        }
                    }
                    FOutput.Add(message);
                }
            }
            FOutput.Flush();

            if (RemovePinsFirst)
            {
                RetryConfig();
            }
        }
Пример #7
0
        public void Evaluate(int SpreadMax)
        {
            FOutput.Resize(FMmf.SliceCount, () => new MemoryComStream(), str => str.Dispose());
            for (int i = 0; i < FMmf.SliceCount; i++)
            {
                if (FMmf[i] != null && FRead[i])
                {
                    var mutex = MutexIn.TryGetSlice(i);

                    var mmf = FMmf[i];
                    FMmf[i] = mmf;
                    if (FOutput[i] == null)
                    {
                        FOutput[i] = new MemoryComStream();
                    }
                    if (FSize[i] == 0)
                    {
                        mutex?.WaitOne();
                        using (var accessor = mmf.CreateViewStream())
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                        mutex?.ReleaseMutex();
                    }
                    else
                    {
                        mutex?.WaitOne();
                        using (var accessor = mmf.CreateViewStream(FOffset[i], FSize[i]))
                        {
                            FOutput[i].SetLength(accessor.Length);
                            accessor.Position   = 0;
                            FOutput[i].Position = 0;
                            accessor.CopyTo(FOutput[i]);
                            FOutput[i].Position = 0;
                        }
                        mutex?.ReleaseMutex();
                    }
                }
            }

            FOutput.Stream.IsChanged = false;
            if (FRead.Any())
            {
                FOutput.Flush(true);
            }
        }
Пример #8
0
        public void Evaluate(int SpreadMax)
        {
            if (OpenIn.Any(v => v) || CloseIn.Any(v => v))
            {
                DeviceIn.Sync();
                DeviceOut.ResizeAndDispose(DeviceIn.SliceCount, () => new HidDeviceWrap());
                for (int i = 0; i < DeviceOut.SliceCount; i++)
                {
                    if (OpenIn[i])
                    {
                        if (DeviceOut[i] == null)
                        {
                            DeviceOut[i] = new HidDeviceWrap();
                        }
                        if (DeviceOut[i].Device == null)
                        {
                            DeviceOut[i].Device = DeviceIn[i];
                            DeviceOut[i].Initialize();
                        }
                        else
                        {
                            DeviceOut[i].Open();
                        }
                    }

                    if (CloseIn[i] && DeviceOut[i] != null && DeviceOut[i].Opened)
                    {
                        DeviceOut[i].Close();
                        DeviceOut[i].Dispose();
                        DeviceOut[i] = null;
                    }
                }
                DeviceOut.Stream.IsChanged = true;
                DeviceOut.Flush(true);
            }

            if (_changeRef != HidChange.GlobalChangeCounter)
            {
                _changeRef = HidChange.GlobalChangeCounter;
                DeviceOut.Stream.IsChanged = true;
                DeviceOut.Flush(true);
            }
        }
Пример #9
0
        public override void Evaluate(int SpreadMax)
        {
            // graceful fallback when being fed bad data
            if (FNew.IsAnyInvalid() || FTopic.IsAnyInvalid() || FSpreadCount.IsAnyInvalid())
            {
                FOutput.FlushNil();
                return;
            }

            if (!FNew.Any() && !ForceNewDefaults)
            {
                FOutput.FlushNil();
                return;
            }

            SpreadMax          = FFormularSelection.SliceCount; // numbers of supported Formulars
            FOutput.SliceCount = SpreadMax;

            var counter = 0;

            for (int i = 0; i < SpreadMax; i++)
            {
                var formularName = FFormularSelection[i].Name;
                var formular     = MessageFormularRegistry.Context[formularName];

                FOutput[i].SliceCount = 0;
                if (formular == null)
                {
                    continue;
                }

                var count = FSpreadCount[i];
                for (int j = 0; j < count; j++)
                {
                    if (FNew[counter] || ForceNewDefaults)
                    {
                        Message message = new Message();
                        message.Topic = FTopic[counter];
                        foreach (var field in formular.FieldNames)
                        {
                            int binsize = formular[field].DefaultSize;
                            binsize = binsize > 0 ? binsize : 1;
                            var type = formular[field].Type;

                            message[field] = BinFactory.New(type, binsize);

                            for (int slice = 0; slice < binsize; slice++)
                            {
                                message[field].Add(TypeIdentity.Instance.NewDefault(type));
                            }
                        }

                        FOutput[i].Add(message);
                    }
                    counter++;
                }
            }
            FOutput.Flush();

            ForceNewDefaults = false;
        }
Пример #10
0
// ReSharper restore UnassignedField.Global
// ReSharper restore MemberCanBePrivate.Global

        public void Evaluate(int SpreadMax)
        {
            if (ControlOut.SliceCount == SpreadMax && !TransformIn.IsChanged && !MultiLineIn.IsChanged && !EnabledIn.IsChanged && !ResetIn.Any(reset => reset))
            {
                return;
            }

            if (ControlOut.SliceCount != SpreadMax)
            {
                if (ControlOut.SliceCount > SpreadMax)
                {
                    for (var i = ControlOut.SliceCount; i > SpreadMax; i--)
                    {
                        ControlOut[i].Dispose();
                    }
                    ControlOut.SliceCount = SpreadMax;
                    ValueOut.SliceCount   = SpreadMax;
                }
                else
                {
                    var i = ControlOut.SliceCount;
                    ValueOut.SliceCount = SpreadMax;
                    for (ControlOut.SliceCount = SpreadMax; i < SpreadMax; i++)
                    {
                        ControlOut[i] = new TextBox {
                            Text = DefaultIn[i], Multiline = MultiLineIn[i], Tag = i
                        };
                        ControlOut[i].TextChanged += (sender, args) => ValueOut[(int)((TextBox)sender).Tag] = ((TextBox)sender).Text;
                        ValueOut[i] = ControlOut[i].Text;
                    }
                }
            }

            for (var i = 0; i < SpreadMax; i++)
            {
                if (ControlOut[i] == null)
                {
                    ControlOut[i] = new TextBox {
                        Text = DefaultIn[i], Multiline = MultiLineIn[i], Tag = i
                    };
                    ControlOut[i].TextChanged += (sender, args) => ValueOut[(int)(((TextBox)sender).Tag)] = ((TextBox)sender).Text;
                    ValueOut[i] = ControlOut[i].Text;
                }

                if (ControlOut[i].Parent == null || !(ControlOut[i] is TextBox))
                {
                    continue;
                }

                if (MultiLineIn.IsChanged)
                {
                    ((TextBox)ControlOut[i]).Multiline = MultiLineIn[i];
                }

                if (EnabledIn.IsChanged)
                {
                    ControlOut[i].Enabled = EnabledIn[i];
                }

                if (ResetIn[i])
                {
                    ControlOut[i].Text = DefaultIn[i];
                }

                if (TransformIn.IsChanged || MultiLineIn.IsChanged)
                {
                    Vector3D scale;
                    Vector3D rotation;
                    Vector3D translation;
                    if (TransformIn[i].Decompose(out scale, out rotation, out translation))
                    {
                        ControlOut[i].Bounds = MultiLineIn[i] ? new Rectangle((int)(translation.x * 100.0), (int)(translation.y * 100.0), (int)(scale.x * 100.0), (int)(scale.y * 100.0)) : new Rectangle((int)(translation.x * 100.0), (int)(translation.y * 100.0), (int)(scale.x * 100.0), 20);
                    }
                }
            }
        }
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (!FInWorld.PluginIO.IsConnected)
            {
                return;
            }

            //check if add is called at all (if not, quit early)
            if (!FInAdd.Any(add => add == true))
            {
                return;
            }

            //evaluate the inputs
            {
                FInPosition.Sync();
                FInRotation.Sync();
                FInScale.Sync();
                FInTags.Sync();
                FInBehavior.Sync();
                FInConstraint.Sync();
                FInDragHitTestFunction.Sync();
                FInHitEvents.Sync();

                SpreadMax = Utils.SpreadMax(FInPosition
                                            , FInRotation
                                            , FInScale
                                            , FInTags
                                            , FInBehavior
                                            , FInConstraint
                                            , FInDragHitTestFunction
                                            , FInHitEvents
                                            , FInAdd);
            }

            var world = FInWorld[0];

            for (int i = 0; i < SpreadMax; i++)
            {
                if (FInAdd[i])
                {
                    //construct the new slide
                    var newSlide = new Slide(world)
                    {
                        Index     = world.NextAvailableIndex,
                        Transform = VMath.Scale(FInScale[i].x, FInScale[i].y, 1.0)
                                    * VMath.RotateZ(FInRotation[i])
                                    * VMath.Translate(FInPosition[i].x, FInPosition[i].y, 0.0),
                        Tags                = new List <String>(FInTags[i]),
                        Behavior            = FInBehavior[i],
                        Constraint          = FInConstraint[i],
                        DragHitTestFunction = FInDragHitTestFunction[i],
                        HitEvents           = new List <HitEvent>(FInHitEvents[i])
                    };

                    //clear out any null HitEvents (e.g. if spread was empty)
                    newSlide.HitEvents.RemoveAll(hitEvent => hitEvent == null);

                    //add the new slide to the world
                    world.Slides.Add(newSlide);
                }
            }
        }
Пример #12
0
 public void Evaluate(int SpreadMax)
 {
     if (FKeyboard.IsChanged || FMouse.IsChanged)
     {
         MouseMan.SelectDevice(FMouse[0]);
         KeyMan.SelectDevice(FKeyboard[0]);
     }
     if (Camera == null)
     {
         var qrot = Quaternion.RotationYawPitchRoll((float)(FDefRot[0].y * Math.PI * 2), (float)(FDefRot[0].x * Math.PI * 2), (float)(FDefRot[0].z * Math.PI * 2));
         Camera = new ModularCam()
         {
             Default = new ModularCam()
             {
                 Translation   = FDefTrans[0],
                 Rotation      = qrot,
                 PivotDistance = FDefPivotDist[0],
                 Fov           = FDefFov[0],
                 Near          = FDefNear[0],
                 Far           = FDefFar[0]
             },
             Translation   = FDefTrans[0],
             Rotation      = qrot,
             PivotDistance = FDefPivotDist[0],
             Fov           = FDefFov[0],
             Near          = FDefNear[0],
             Far           = FDefFar[0],
             RotationSpeed = FRotSpeed[0]
         };
     }
     Camera.InputView   = FTrIn[0];
     Camera.InputAspect = FAspectIn[0];
     if (FRotSpeed.IsChanged || FResetAll[0])
     {
         Camera.RotationSpeed = FRotSpeed[0];
     }
     if (FDefTrans.IsChanged || FResetAll[0])
     {
         Camera.Translation         = FDefTrans[0];
         Camera.Default.Translation = FDefTrans[0];
     }
     if (FDefRot.IsChanged || FResetAll[0])
     {
         var qrot = Quaternion.RotationYawPitchRoll((float)(FDefRot[0].y * Math.PI * 2), (float)(FDefRot[0].x * Math.PI * 2), (float)(FDefRot[0].z * Math.PI * 2));
         Camera.Rotation         = qrot;
         Camera.Default.Rotation = qrot;
     }
     if (FDefPivotDist.IsChanged || FResetAll[0])
     {
         Camera.PivotDistance         = FDefPivotDist[0];
         Camera.Default.PivotDistance = FDefPivotDist[0];
     }
     if (FDefFov.IsChanged || FResetAll[0])
     {
         Camera.Fov         = FDefFov[0];
         Camera.Default.Fov = FDefFov[0];
     }
     if (FDefNear.IsChanged || FResetAll[0])
     {
         Camera.Near         = FDefNear[0];
         Camera.Default.Near = FDefNear[0];
     }
     if (FDefFar.IsChanged || FResetAll[0])
     {
         Camera.Far         = FDefFar[0];
         Camera.Default.Far = FDefFar[0];
     }
     if (FDeltas.SliceCount > 0 && FDeltas[0] != null)
     {
         if (FDeltas.Any(delta => delta.LockCursor))
         {
             SetCursorPos(CursorPos.X, CursorPos.Y);
         }
         else
         {
             GetCursorPos(out CursorPos);
         }
         var hoverhandle  = WindowFromPoint(CursorPos);
         var parenthandle = GetParent((IntPtr)FHandle[0]);
         for (int i = 0; i < FDeltas.SliceCount; i++)
         {
             var delta = FDeltas[i];
             delta.InputMouse      = MouseMan.Devices[0];
             delta.InputKeyboard   = KeyMan.Devices[0];
             delta.ConnectedCamera = Camera;
             if (FHandle[0] > 0)
             {
                 delta.InteractUpstream =
                     FHandle[0] == hoverhandle.ToInt32() ||
                     parenthandle == hoverhandle;
             }
             else
             {
                 delta.InteractUpstream = true;
             }
             FFrameTime[0] = FHDEHost.FrameTime - PrevFrameTime;
             Camera.Move(delta, FHDEHost.FrameTime - PrevFrameTime);
         }
     }
     FCameraOut[0]               = Camera;
     FViewOut[0]                 = Camera.View;
     FProjectionOut[0]           = Camera.Projection;
     FProjectionWithAspectOut[0] = Camera.ProjectionWithAspect;
     PrevFrameTime               = FHDEHost.FrameTime;
 }
Пример #13
0
        public void Evaluate(int SpreadMax)
        {
            var qrot = Quaternion.RotationYawPitchRoll(
                (float)(FDefRot[0].y * Math.PI * 2),
                (float)(FDefRot[0].x * Math.PI * 2),
                (float)(FDefRot[0].z * Math.PI * 2)
                );
            var defcam = new CameraProperties(
                FTrIn[0],
                FDefTrans[0],
                qrot,
                FDefPivotDist[0],
                FDefFov[0],
                FDefNear[0],
                FDefFar[0]
                );

            if (FKeyboard.IsChanged || FMouse.IsChanged)
            {
                _mouseMan.SelectDevice(FMouse[0]);
                _keyMan.SelectDevice(FKeyboard[0]);
            }
            if (_camera == null)
            {
                _camera = new ModularCam()
                {
                    Default       = defcam,
                    Properties    = defcam,
                    RotationSpeed = FRotSpeed[0]
                };
            }
            if (_resetter == null)
            {
                _resetter = new CameraDelta();
            }

            _resetter.ResetTranslation   = FDefTrans.IsChanged || FResetAll[0];
            _resetter.ResetRotation      = FDefRot.IsChanged || FResetAll[0];
            _resetter.ResetPivotDistance = FDefPivotDist.IsChanged || FResetAll[0];
            _resetter.ResetFov           = FDefFov.IsChanged || FResetAll[0];
            _resetter.ResetNear          = FDefNear.IsChanged || FResetAll[0];
            _resetter.ResetFar           = FDefFar.IsChanged || FResetAll[0];

            _camera.InputAspect = FAspectIn[0];
            if (FRotSpeed.IsChanged || FResetAll[0])
            {
                _camera.RotationSpeed = FRotSpeed[0];
            }

            _camera.Default    = defcam;
            _camera.Properties = new CameraProperties(_camera.Properties, defcam, _resetter);

            if (FDeltas.SliceCount > 0 && FDeltas[0] != null)
            {
                if (FDeltas.Any(delta => delta.LockCursor))
                {
                    SetCursorPos(_cursorPos.X, _cursorPos.Y);
                }
                else
                {
                    GetCursorPos(out _cursorPos);
                }
                var hoverhandle  = WindowFromPoint(_cursorPos);
                var parenthandle = GetParent((IntPtr)FHandle[0]);
                for (int i = 0; i < FDeltas.SliceCount; i++)
                {
                    var delta = FDeltas[i];
                    delta.InputMouse      = _mouseMan.Devices[0];
                    delta.InputKeyboard   = _keyMan.Devices[0];
                    delta.ConnectedCamera = _camera;
                    if (FHandle[0] > 0)
                    {
                        delta.InteractUpstream =
                            FHandle[0] == hoverhandle.ToInt32() ||
                            parenthandle == hoverhandle;
                    }
                    else
                    {
                        delta.InteractUpstream = true;
                    }
                    _camera.Move(delta, FHDEHost.FrameTime - _prevFrameTime);
                }
            }
            FCameraOut[0]               = _camera;
            FViewOut[0]                 = _camera.View;
            FProjectionOut[0]           = _camera.Projection;
            FProjectionWithAspectOut[0] = _camera.ProjectionWithAspect;
            _prevFrameTime              = FHDEHost.FrameTime;
        }