コード例 #1
0
        /// <summary>
        /// Add a new generic parameter.
        /// </summary>
        /// <typeparam name="T">The type of the generic.</typeparam>
        /// <param name="keyName">The name of the generic.</param>
        /// <param name="generics">The target GenericDictionary.</param>
        private void AddKey <T>(string keyName, GenericDictionary generics)
        {
            INodeParameter nodeParameter;
            var            typeT = typeof(T);

            if (typeT == typeof(string))
            {
                nodeParameter = new NodeParameter();
            }
            else if (typeT == typeof(Texture2D))
            {
                nodeParameter = new NodeParameterTexture();
            }
            else if (typeT == typeof(float))
            {
                nodeParameter = new NodeParameterFloat();
            }
            else if (typeT == typeof(int))
            {
                nodeParameter = new NodeParameterInt();
            }
            else if (typeT == typeof(Vector2))
            {
                nodeParameter = new NodeParameterFloat2();
            }
            else if (typeT == typeof(Vector3))
            {
                nodeParameter = new NodeParameterFloat3();
            }
            else if (typeT == typeof(Vector4))
            {
                nodeParameter = new NodeParameterFloat4();
            }
            else if (typeT == typeof(SamplerState))
            {
                nodeParameter = new NodeParameterSampler();
            }
            else
            {
                throw new Exception("Unsupported generic format");
            }

            if (Generics.ContainsKey(keyName))
            {
                var gen = Generics[keyName];
                if (gen == null || gen.GetType() != nodeParameter.GetType())
                {
                    generics[keyName] = nodeParameter;
                }
                else
                {
                    generics[keyName] = gen;
                }
            }
            else
            {
                generics.Add(keyName, nodeParameter);
            }
        }
コード例 #2
0
        internal bool RegisterGeneric(TypeSig t)
        {
            Debug.Assert(t != null, $"{nameof(t)} != null");

            // This is a temporary fix.
            // Type visibility should be handled in a much better way which would involved some analysis.
            var typeDef = t.ToTypeDefOrRef().ResolveTypeDef();

            if (typeDef != null && !typeDef.IsVisibleOutside())
            {
                return(false);
            }

            // Get proper type.
            t = SignatureUtils.GetLeaf(t);

            // scrambling voids leads to peverify errors, better leave them out.
            if (t.ElementType == ElementType.Void)
            {
                return(false);
            }

            if (!Generics.ContainsKey(t))
            {
                GenericParam newGenericParam;
                if (t.IsGenericMethodParameter)
                {
                    var mVar = t.ToGenericMVar();
                    Debug.Assert(mVar != null, $"{nameof(mVar)} != null");
                    newGenericParam = new GenericParamUser(GenericCount, mVar.GenericParam.Flags, $"T{GenericCount}")
                    {
                        Rid = mVar.Rid
                    };
                }
                else if (t.IsGenericTypeParameter)
                {
                    var tVar = t.ToGenericVar();
                    Debug.Assert(tVar != null, $"{nameof(tVar)} != null");
                    newGenericParam = new GenericParamUser(GenericCount, tVar.GenericParam.Flags, $"T{GenericCount}")
                    {
                        Rid = tVar.Rid
                    };
                }
                else
                {
                    newGenericParam = new GenericParamUser(GenericCount, GenericParamAttributes.NoSpecialConstraint, $"T{GenericCount}");
                }
                Generics.Add(t, newGenericParam);
                GenericCount++;
                _trueTypes.Add(t);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        protected StructureFrame UpdateOriginal(StructureFrame original)
        {
            List <string> keys;

            keys = new List <string>(original.Primitives.Numbers.Keys);
            foreach (string key in keys)
            {
                if (Primitives.Numbers.ContainsKey(key))
                {
                    original.Primitives.Numbers [key] = Primitives.Numbers [key];
                }
            }

            keys = new List <string>(original.Primitives.Booleans.Keys);
            foreach (string key in keys)
            {
                /*bool val;
                 * this.Primitives.Booleans.TryGetValue (key, out val);
                 * original.Primitives.Booleans[key] = val;*/
                if (Primitives.Booleans.ContainsKey(key))
                {
                    original.Primitives.Booleans [key] = Primitives.Booleans [key];
                }
            }

            keys = new List <string>(original.Primitives.Text.Keys);
            foreach (string key in keys)
            {
                /*string val;
                 * this.Primitives.Text.TryGetValue (key, out val);
                 * original.Primitives.Text[key] = val;*/
                if (Primitives.Text.ContainsKey(key))
                {
                    original.Primitives.Text [key] = Primitives.Text [key];
                }
            }

            keys = new List <string>(original.Generics.Keys);
            foreach (string key in keys)
            {
                if (Generics.ContainsKey(key))
                {
                    original.Generics [key] = Generics [key];
                }
            }

            keys = new List <string>(original.Functions.Keys);
            foreach (string key in keys)
            {
                if (Functions.ContainsKey(key))
                {
                    original.Functions [key] = Functions [key];
                }
            }

            return(original);
        }
コード例 #4
0
        /// <summary>
        /// Add a new generic parameter.
        /// </summary>
        /// <typeparam name="TValue">The type of the generic.</typeparam>
        /// <param name="keyName">The name of the generic.</param>
        /// <param name="generics">The target ComputeColorParameters.</param>
        public void AddKey <TValue>(string keyName, ComputeColorParameters generics)
        {
            IComputeColorParameter computeColorParameter;
            var typeT = typeof(TValue);

            if (typeT == typeof(Texture))
            {
                computeColorParameter = new ComputeColorParameterTexture();
            }
            else if (typeT == typeof(float))
            {
                computeColorParameter = new ComputeColorParameterFloat();
            }
            else if (typeT == typeof(int))
            {
                computeColorParameter = new ComputeColorParameterInt();
            }
            else if (typeT == typeof(Vector2))
            {
                computeColorParameter = new ComputeColorParameterFloat2();
            }
            else if (typeT == typeof(Vector3))
            {
                computeColorParameter = new ComputeColorParameterFloat3();
            }
            else if (typeT == typeof(Vector4))
            {
                computeColorParameter = new ComputeColorParameterFloat4();
            }
            else if (typeT == typeof(SamplerState))
            {
                computeColorParameter = new ComputeColorParameterSampler();
            }
            else
            {
                throw new Exception("Unsupported generic format");
            }

            if (Generics.ContainsKey(keyName))
            {
                var gen = Generics[keyName];
                if (gen == null || gen.GetType() != computeColorParameter.GetType())
                {
                    generics[keyName] = computeColorParameter;
                }
                else
                {
                    generics[keyName] = gen;
                }
            }
            else
            {
                generics.Add(keyName, computeColorParameter);
            }
        }
コード例 #5
0
        public override void CreateGenerics()
        {
            Generics.Clear();
            GenericCallTypes.Clear();

            foreach (TypeSig t in AssociatedTypes)
            {
                if (!Generics.ContainsKey(t.ScopeType.MDToken.Raw))
                {
                    Generics.Add(t.ScopeType.MDToken.Raw,
                                 new GenericParamUser(
                                     (ushort)(TargetType.GenericParameters.Count + Generics.Count()),
                                     GenericParamAttributes.NoSpecialConstraint, GenericParamName)); //gen name
                    GenericCallTypes.Add(t);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Devices the added.
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="res">Res.</param>
        /// <param name="sender">Sender.</param>
        /// <param name="device">Device.</param>
        void HidDeviceAdded(IntPtr context, IOReturn res, IntPtr sender, IOHIDDeviceRef deviceRef)
        {
            //IOReturn success = Native.IOHIDDeviceOpen (device, (int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone);

            if (deviceRef == IntPtr.Zero)
            {
                Debug.LogWarning("IOHIDeviceRef of Added Device equal to IntPtr.Zero");
                return;
            }



            int product_id = (int)(new Native.CFNumber(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDProductIDKey)))).ToInteger();



            int vendor_id = (int)(new Native.CFNumber(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDVendorIDKey)))).ToInteger();

            string manufacturer = (new Native.CFString(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDManufacturerKey)))).ToString();
            string description  = manufacturer + " " + (new Native.CFString(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDProductKey)))).ToString();

            int    location  = (int)(new Native.CFNumber(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDLocationIDKey)))).ToInteger();
            string transport = (new Native.CFString(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDTransportKey)))).ToString();

            string path = String.Format("{0:s}_{1,4:X}_{2,4:X}_{3:X}",
                                        transport, vendor_id, product_id, location);                  //"%s_%04hx_%04hx_%x"

            //string serial=(new Native.CFString(Native.IOHIDDeviceGetProperty(deviceRef, Native.CFSTR(Native.kIOHIDSerialNumberKey)))).ToString();

            if (Generics.ContainsKey(path))
            {
                return;
            }

            GenericHIDDevice hidDevice;
            IDevice          joyDevice = null;

            // IDevice<IAxisDetails, IButtonDetails, IDeviceExtension> joyDevice = null;


            ///loop thru specific drivers and attach the driver to device if compatible
            if (__drivers != null)
            {
                foreach (var driver in __drivers)
                {
                    hidDevice = new GenericHIDDevice(GetIndexForDeviceWithID(path), vendor_id, product_id, path, deviceRef, this, path, description);

                    if ((joyDevice = driver.ResolveDevice(hidDevice)) != null)
                    {
                        lock (syncRoot){
                            __Generics[path] = hidDevice;
                        }

                        //if (context != IntPtr.Zero) {
                        Native.IOHIDDeviceRegisterRemovalCallback(deviceRef, HandleDeviceRemoved, context);
                        //}else{
                        //	Debug.LogWarning("IOHIDDeviceRegisterRemovalCallback not registerd cos of Context IntPtr.Zero");
                        //}

                        Debug.Log("Device PID:" + joyDevice.PID + " VID:" + joyDevice.VID + "[" + joyDevice.Name + "] attached to " + driver.GetType().ToString());

                        break;
                    }
                }
            }

            if (joyDevice == null)
            {    //set default driver as resolver if no custom driver match device
                hidDevice = new GenericHIDDevice(GetIndexForDeviceWithID(path), vendor_id, product_id, path, deviceRef, this, path, description);


                if ((joyDevice = defaultDriver.ResolveDevice(hidDevice)) != null)
                {
                    lock (syncRoot){
                        __Generics[path] = hidDevice;
                    }

                    //if (context != IntPtr.Zero) {
                    Native.IOHIDDeviceRegisterRemovalCallback(deviceRef, HandleDeviceRemoved, context);
                    //}else{
                    //	Debug.LogWarning("IOHIDDeviceRegisterRemovalCallback not registerd cos of Context IntPtr.Zero");
                    //}

                    Debug.Log("Device PID:" + joyDevice.PID + " VID:" + joyDevice.VID + "[" + joyDevice.Name + "] attached to " + defaultDriver.GetType().ToString());
                }
                else
                {
                    Debug.LogWarning("Device PID:" + product_id.ToString() + " VID:" + vendor_id.ToString() + " not found compatible driver on the system.Removed!");
                }
            }

            if (joyDevice != null)
            {
                this.DeviceConnectEvent(this, new DeviceEventArgs <IDevice>(joyDevice));
            }
        }