示例#1
0
        unsafe internal void UpdateSecondaryNativeProperties(
            IList <PropertyInitializer> properties,
            System.IO.UnmanagedMemoryStream stream)
        {
            if (_localToWorldAttribute != null)
            {
                // we have to build a "local to world" transform, and push that through.
                var trans = DomNode.As <ITransformable>();
                if (trans != null)
                {
                    var localToWorld = trans.LocalToWorld;
                    properties.Add(
                        GameEngine.CreateInitializer(
                            _localToWorldAttribute.PropertyId, stream.PositionPointer,
                            typeof(float), 16, false));
                    for (int c = 0; c < 16; ++c)
                    {
                        ((float *)stream.PositionPointer)[c] = localToWorld[c];
                    }
                    stream.Position += sizeof(float) * 16;
                }
            }

            if (_visibleHierarchyAttribute != null)
            {
                var visible = DomNode.As <IVisible>();
                if (visible != null)
                {
                    uint d = Convert.ToUInt32(visible.Visible);
                    SetBasicProperty(_visibleHierarchyAttribute.PropertyId, d, properties, stream);
                    *(uint *)stream.PositionPointer = d;
                    stream.Position += sizeof(uint);
                }
            }
        }
示例#2
0
 unsafe private static void SetBasicProperty <T>(
     uint propId, T obj,
     IList <PropertyInitializer> properties,
     System.IO.UnmanagedMemoryStream stream)
 {
     properties.Add(GameEngine.CreateInitializer(
                        propId, stream.PositionPointer,
                        typeof(T), 1, false));
 }
示例#3
0
        unsafe private static void SetStringProperty(
            uint propId, string str,
            IList <PropertyInitializer> properties,
            System.IO.UnmanagedMemoryStream stream)
        {
            var length = str.Length;

            properties.Add(GameEngine.CreateInitializer(
                               propId, stream.PositionPointer,
                               typeof(char), (uint)length, true));

            // copy in string data with no string formatting or changes to encoding
            fixed(char *raw = str)
            for (uint c = 0; c < length; ++c)
            {
                ((char *)stream.PositionPointer)[c] = raw[c];
            }

            // just advance the stream position over what we've just written
            stream.Position += sizeof(char) * length;
        }
示例#4
0
        unsafe internal static void PushAttribute(
            uint propertyId,
            Type clrType, int arrayLength,
            object data,
            IList <PropertyInitializer> properties,
            System.IO.UnmanagedMemoryStream stream)
        {
            Type elmentType = clrType.GetElementType();

            if (clrType.IsArray && elmentType.IsPrimitive)
            {
                if (elmentType == typeof(float))
                {
                    var count = Math.Min(arrayLength, ((float[])data).Length);
                    properties.Add(GameEngine.CreateInitializer(
                                       propertyId, stream.PositionPointer,
                                       elmentType, (uint)count, false));

                    fixed(float *d = (float[])data)
                    for (uint c = 0; c < count; ++c)
                    {
                        ((float *)stream.PositionPointer)[c] = d[c];
                    }
                    stream.Position += sizeof(float) * count;
                }
                else if (elmentType == typeof(int))
                {
                    var count = Math.Min(arrayLength, ((int[])data).Length);
                    properties.Add(GameEngine.CreateInitializer(
                                       propertyId, stream.PositionPointer,
                                       elmentType, (uint)count, false));

                    fixed(int *d = (int[])data)
                    for (uint c = 0; c < count; ++c)
                    {
                        ((int *)stream.PositionPointer)[c] = d[c];
                    }
                    stream.Position += sizeof(int) * count;
                }

                else if (elmentType == typeof(uint))
                {
                    var count = Math.Min(arrayLength, ((uint[])data).Length);
                    properties.Add(GameEngine.CreateInitializer(
                                       propertyId, stream.PositionPointer,
                                       elmentType, (uint)count, false));

                    fixed(uint *d = (uint[])data)
                    for (uint c = 0; c < count; ++c)
                    {
                        ((uint *)stream.PositionPointer)[c] = d[c];
                    }
                    stream.Position += sizeof(int) * count;
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false);
                }
            }
            else
            {
                if (clrType == typeof(string))
                {
                    SetStringProperty(propertyId, (string)data, properties, stream);
                }

                else if (clrType == typeof(bool))
                {
                    uint d = Convert.ToUInt32((bool)data);
                    SetBasicProperty(propertyId, d, properties, stream);
                    *(uint *)stream.PositionPointer = d;
                    stream.Position += sizeof(uint);
                }

                else if (clrType == typeof(byte))
                {
                    SetBasicProperty(propertyId, (byte)data, properties, stream);
                    *(byte *)stream.PositionPointer = (byte)data;
                    stream.Position += sizeof(byte);
                }

                else if (clrType == typeof(sbyte))
                {
                    SetBasicProperty(propertyId, (sbyte)data, properties, stream);
                    *(sbyte *)stream.PositionPointer = (sbyte)data;
                    stream.Position += sizeof(sbyte);
                }

                else if (clrType == typeof(short))
                {
                    SetBasicProperty(propertyId, (short)data, properties, stream);
                    *(short *)stream.PositionPointer = (short)data;
                    stream.Position += sizeof(short);
                }

                else if (clrType == typeof(ushort))
                {
                    SetBasicProperty(propertyId, (ushort)data, properties, stream);
                    *(ushort *)stream.PositionPointer = (ushort)data;
                    stream.Position += sizeof(ushort);
                }

                else if (clrType == typeof(int))
                {
                    SetBasicProperty(propertyId, (int)data, properties, stream);
                    *(int *)stream.PositionPointer = (int)data;
                    stream.Position += sizeof(int);
                }

                else if (clrType == typeof(uint))
                {
                    SetBasicProperty(propertyId, (uint)data, properties, stream);
                    *(uint *)stream.PositionPointer = (uint)data;
                    stream.Position += sizeof(uint);
                }

                else if (clrType == typeof(long))
                {
                    SetBasicProperty(propertyId, (long)data, properties, stream);
                    *(long *)stream.PositionPointer = (long)data;
                    stream.Position += sizeof(long);
                }

                else if (clrType == typeof(ulong))
                {
                    SetBasicProperty(propertyId, (ulong)data, properties, stream);
                    *(ulong *)stream.PositionPointer = (ulong)data;
                    stream.Position += sizeof(ulong);
                }

                else if (clrType == typeof(float))
                {
                    SetBasicProperty(propertyId, (float)data, properties, stream);
                    *(float *)stream.PositionPointer = (float)data;
                    stream.Position += sizeof(float);
                }

                else if (clrType == typeof(double))
                {
                    SetBasicProperty(propertyId, (double)data, properties, stream);
                    *(double *)stream.PositionPointer = (double)data;
                    stream.Position += sizeof(double);
                }

                else if (clrType == typeof(System.Uri))
                {
                    if (data != null)
                    {
                        string assetName = AsAssetName((Uri)data);
                        if (!string.IsNullOrWhiteSpace(assetName))
                        {
                            SetStringProperty(propertyId, assetName, properties, stream);
                        }
                    }
                }

                else if (clrType == typeof(DomNode))
                {
                    // this is a 'reference' to an object
                    DomNode             refNode   = (DomNode)data;
                    NativeObjectAdapter nativeGob = refNode.As <NativeObjectAdapter>();
                    if (nativeGob != null)
                    {
                        SetBasicProperty(propertyId, (ulong)nativeGob.InstanceId, properties, stream);
                        *(ulong *)stream.PositionPointer = (ulong)nativeGob.InstanceId;
                        stream.Position += sizeof(ulong);
                    }
                }
            }
        }