예제 #1
0
        public override bool Sync()
        {
            IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate();
            if (IsChanged)
            {
                Length = FNodeIn.SliceCount;
                using (var writer = GetWriter())
                {
                    object usI;
                    FNodeIn.GetUpstreamInterface(out usI);
                    var upstreamInterface = usI as IGenericIO;

                    for (int i = 0; i < Length; i++)
                    {
                        int usS;
                        var result = default(T);
                        if (upstreamInterface != null)
                        {
                            FNodeIn.GetUpsreamSlice(i, out usS);
                            result = (T)upstreamInterface.GetSlice(usS);
                        }
                        writer.Write(result);
                    }
                }
            }
            return(base.Sync());
        }
예제 #2
0
        public override bool Sync()
        {
            IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate();
            if (IsChanged)
            {
                Length = FNodeIn.SliceCount;
                using (var writer = GetWriter())
                {
                    object usI;
                    FNodeIn.GetUpstreamInterface(out usI);
                    var upstreamInterface = usI as IGenericIO;

                    for (int i = 0; i < Length; i++)
                    {
                        int usS;
                        T   result = new T();
                        if (upstreamInterface != null)
                        {
                            FNodeIn.GetUpsreamSlice(i, out usS);
                            IDX11ResourceDataProvider res = (IDX11ResourceDataProvider)upstreamInterface.GetSlice(usS);

                            if (result == null)
                            {
                                res = new T();
                            }
                            result.Assign(res);
                        }
                        writer.Write(result);
                    }
                }
            }
            return(base.Sync());
        }
예제 #3
0
        public override bool Sync()
        {
            var nodeConnectionChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate();

            if (nodeConnectionChanged)
            {
                Length = FNodeIn.SliceCount;

                FSubscriptions.ResizeAndDispose(
                    Length,
                    slice =>
                {
                    return(new Subscription <Keyboard, KeyNotification>(
                               keyboard => keyboard.KeyNotifications,
                               (keyboard, n) =>
                    {
                        var keyboardState = this.Buffer[slice];
                        IEnumerable <Keys> keys;
                        switch (n.Kind)
                        {
                        case KeyNotificationKind.KeyDown:
                            var downNotification = n as KeyDownNotification;
                            keys = keyboardState.KeyCodes.Concat(new [] { downNotification.KeyCode });
                            keyboardState = new KeyboardState(keys, keyboard.CapsLock, keyboardState.Time + 1);
                            break;

                        case KeyNotificationKind.KeyUp:
                            var upNotification = n as KeyUpNotification;
                            keys = keyboardState.KeyCodes.Except(new[] { upNotification.KeyCode });
                            keyboardState = new KeyboardState(keys, keyboardState.CapsLock, keyboardState.Time + 1);
                            break;
                        }
                        SetKeyboardState(slice, keyboardState);
                    }
                               ));
                }
                    );

                object usI;
                FNodeIn.GetUpstreamInterface(out usI);
                var stream = usI as MemoryIOStream <Keyboard>;

                for (int i = 0; i < Length; i++)
                {
                    int usS;
                    var keyboard = Keyboard.Empty;
                    if (stream != null)
                    {
                        FNodeIn.GetUpsreamSlice(i, out usS);
                        keyboard = stream[usS];
                    }
                    if (FSubscriptions[i].Update(keyboard))
                    {
                        SetKeyboardState(i, KeyboardState.Empty);
                    }
                }
            }
            return(base.Sync());
        }
예제 #4
0
        public override bool Sync()
        {
            IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate();
            if (IsChanged)
            {
                Length = FNodeIn.SliceCount;

                FSubscriptions.ResizeAndDispose(
                    Length,
                    slice =>
                {
                    return(new Subscription <Keyboard, KeyNotification>(
                               keyboard => keyboard.KeyNotifications,
                               (keyboard, n) =>
                    {
                        var keyboardState = this.Buffer[slice];
                        IEnumerable <Keys> keys;
                        switch (n.Kind)
                        {
                        case KeyNotificationKind.KeyDown:
                            var downNotification = n as KeyDownNotification;
                            keys = keyboardState.KeyCodes.Concat(new [] { downNotification.KeyCode });
                            keyboardState = new KeyboardState(keys, keyboard.CapsLock, keyboardState.Time + 1);
                            break;

                        case KeyNotificationKind.KeyUp:
                            var upNotification = n as KeyUpNotification;
                            keys = keyboardState.KeyCodes.Except(new[] { upNotification.KeyCode });
                            keyboardState = new KeyboardState(keys, keyboardState.CapsLock, keyboardState.Time + 1);
                            break;
                        }
                        this.Buffer[slice] = keyboardState;
                    }
                               ));
                }
                    );

                using (var writer = GetWriter())
                {
                    object usI;
                    FNodeIn.GetUpstreamInterface(out usI);
                    var upstreamInterface = usI as IGenericIO;

                    for (int i = 0; i < Length; i++)
                    {
                        int usS;
                        var keyboard = Keyboard.Empty;
                        if (upstreamInterface != null)
                        {
                            FNodeIn.GetUpsreamSlice(i, out usS);
                            keyboard = (Keyboard)upstreamInterface.GetSlice(usS);
                        }
                        writer.Write(KeyboardState.Empty);
                        FSubscriptions[i].Update(keyboard);
                    }
                }
            }
            return(base.Sync());
        }
예제 #5
0
        public bool Sync()
        {
            IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate();
            if (IsChanged)
            {
                object usI;
                FNodeIn.GetUpstreamInterface(out usI);

                FNodeIn.GetUpStreamSlices(out FLength, out FUpStreamSlices);
                // Check fastest way first: TUpstream == T
                var wrapper = usI as DynamicTypeWrapper;
                if (wrapper != null)
                {
                    usI = wrapper.Value;
                }

                FUpstreamStream = usI as MemoryIOStream <T>;
                if (FUpstreamStream == null)
                {
                    // TUpstream is a subtype of T
                    // Copy the upstream stream through the covariant IEnumerable interface
                    var enumerable = usI as IEnumerable <T>;
                    if (enumerable != null)
                    {
                        FUpstreamStream = enumerable.ToStream();
                    }
                    if (FUpstreamStream == null)
                    {
                        // TUpstream to T needs explicit cast
                        // For example TUpstream is a value type and T is a reference type
                        var objects = usI as IEnumerable;
                        if (objects != null)
                        {
                            FUpstreamStream = objects.Cast <T>().ToStream();
                        }
                        else
                        {
                            // Not connected
                            FUpstreamStream        = FNullStream;
                            FUpstreamStream.Length = FLength;
                            using (var writer = FUpstreamStream.GetWriter())
                                while (!writer.Eos)
                                {
                                    writer.Write(FDefaultValue);
                                }
                        }
                    }
                }
            }
            return(IsChanged);
        }
예제 #6
0
 public bool Sync()
 {
     IsChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate();
     if (IsChanged)
     {
         object usI;
         FNodeIn.GetUpstreamInterface(out usI);
         // Check fastest way first: TUpstream == T
         FUpstreamStream = usI as MemoryIOStream <T>;
         if (FUpstreamStream != null)
         {
             FNodeIn.GetUpStreamSlices(out FLength, out FUpStreamSlices);
         }
         else
         {
             FLength = FNodeIn.SliceCount;
             // TUpstream is a subtype of T
             var enumerable = usI as IEnumerable <T>;
             if (enumerable != null)
             {
                 FUpstreamStream        = new MemoryIOStream <T>(FLength);
                 FUpstreamStream.Length = FLength;
                 using (var writer = FUpstreamStream.GetWriter())
                     foreach (var item in enumerable)
                     {
                         writer.Write(item);
                     }
             }
             else
             {
                 // Not connected
                 FUpstreamStream        = FNullStream;
                 FUpstreamStream.Length = FLength;
             }
         }
     }
     return(IsChanged);
 }
예제 #7
0
        public override bool Sync()
        {
            var nodeConnectionChanged = FAutoValidate ? FNodeIn.PinIsChanged : FNodeIn.Validate();

            if (nodeConnectionChanged)
            {
                Length = FNodeIn.SliceCount;

                FRawMouseWheels.SliceCount = Length;
                FSubscriptions.ResizeAndDispose(
                    Length,
                    slice =>
                {
                    return(new Subscription <Mouse, MouseNotification>(
                               mouse => mouse.MouseNotifications,
                               (mouse, n) =>
                    {
                        var position = new Vector2D(n.Position.X, n.Position.Y);
                        var clientArea = new Vector2D(n.ClientArea.Width - 1, n.ClientArea.Height - 1);
                        var normalizedPosition = VMath.Map(position, Vector2D.Zero, clientArea, new Vector2D(-1, 1), new Vector2D(1, -1), TMapMode.Float);

                        var mouseState = this.Buffer[slice];
                        switch (n.Kind)
                        {
                        case MouseNotificationKind.MouseDown:
                            var downNotification = n as MouseButtonNotification;
                            mouseState = new MouseState(normalizedPosition.x, normalizedPosition.y, mouseState.Buttons | downNotification.Buttons, mouseState.MouseWheel);
                            break;

                        case MouseNotificationKind.MouseUp:
                            var upNotification = n as MouseButtonNotification;
                            mouseState = new MouseState(normalizedPosition.x, normalizedPosition.y, mouseState.Buttons & ~upNotification.Buttons, mouseState.MouseWheel);
                            break;

                        case MouseNotificationKind.MouseMove:
                            mouseState = new MouseState(normalizedPosition.x, normalizedPosition.y, mouseState.Buttons, mouseState.MouseWheel);
                            break;

                        case MouseNotificationKind.MouseWheel:
                            var wheelNotification = n as MouseWheelNotification;
                            FRawMouseWheels[slice] += wheelNotification.WheelDelta;
                            var wheel = (int)Math.Round((float)FRawMouseWheels[slice] / Const.WHEEL_DELTA);
                            mouseState = new MouseState(normalizedPosition.x, normalizedPosition.y, mouseState.Buttons, wheel);
                            break;
                        }
                        SetMouseState(slice, ref mouseState);
                    }
                               ));
                }
                    );

                object usI;
                FNodeIn.GetUpstreamInterface(out usI);
                var upstreamInterface = usI as IGenericIO;

                var emptyMouseState = new MouseState();
                for (int i = 0; i < Length; i++)
                {
                    int usS;
                    var mouse = Mouse.Empty;
                    if (upstreamInterface != null)
                    {
                        FNodeIn.GetUpsreamSlice(i, out usS);
                        mouse = (Mouse)upstreamInterface.GetSlice(usS);
                    }
                    SetMouseState(i, ref emptyMouseState);
                    FSubscriptions[i].Update(mouse);
                }
            }
            return(base.Sync());
        }