Exemplo n.º 1
0
        public void TestOverriddenChildInfo()
        {
            DomNodeType childType = new DomNodeType("foo");
            ChildInfo   info      = new ChildInfo("foo", childType);
            DomNodeType test      = new DomNodeType(
                "test",
                null,
                EmptyEnumerable <AttributeInfo> .Instance,
                new ChildInfo[] { info },
                EmptyEnumerable <ExtensionInfo> .Instance);

            ChildInfo   overridden = new ChildInfo("foo", childType);
            DomNodeType child      = new DomNodeType("child", test,
                                                     EmptyEnumerable <AttributeInfo> .Instance,
                                                     new ChildInfo[] { overridden },
                                                     EmptyEnumerable <ExtensionInfo> .Instance);

            Assert.AreSame(child.GetChildInfo("foo"), overridden);
            Assert.AreEqual(overridden.OwningType, child);
            Assert.AreEqual(overridden.DefiningType, test);

            Assert.True(info.Equivalent(overridden));
            Assert.True(overridden.Equivalent(info));

            Assert.True(test.IsValid(overridden));
            Assert.True(child.IsValid(info));
        }
Exemplo n.º 2
0
        public void TestCustomChildInfo()
        {
            DomNodeType type = new DomNodeType("foo");
            ChildInfo   info = new ChildInfo("foo", type);
            DomNodeType test = new DomNodeType(
                "test",
                null,
                EmptyEnumerable <AttributeInfo> .Instance,
                new ChildInfo[] { info },
                EmptyEnumerable <ExtensionInfo> .Instance);

            Utilities.TestSequenceEqual(test.Children, info);
            Assert.True(test.IsValid(info));
            Assert.AreSame(test.GetChildInfo("foo"), info);
            // check that type is now frozen
            Assert.Throws <InvalidOperationException>(delegate { test.Define(new ChildInfo("notFoo", type)); });

            Assert.AreEqual(info.OwningType, test);
            Assert.AreEqual(info.DefiningType, test);
            Assert.Null(test.GetChildInfo("bar"));
        }
Exemplo n.º 3
0
        public void TestCorrectSubstitutionsExist()
        {
            var loader = GetSchemaLoader();

            DomNodeType containerType = loader.GetNodeType("test:containerType");
            var         subRule       =
                containerType.GetChildInfo("basic").Rules.OfType <SubstitutionGroupChildRule>().SingleOrDefault();

            Assert.NotNull(subRule, "No SubstitutionGroupChildRule was generated.");
            Assert.AreEqual(3, subRule.Substitutions.Count(), "Wrong number of substitutions for rule.");
            Assert.NotNull(subRule.Substitutions.SingleOrDefault(s => s.Type.Name == "test:containerType"), "Missing containerType substitution in rule.");
            Assert.NotNull(subRule.Substitutions.SingleOrDefault(s => s.Type.Name == "test:middleType"), "Missing middleType substitution in rule.");
            Assert.NotNull(subRule.Substitutions.SingleOrDefault(s => s.Type.Name == "test:descendantType"), "Missing descendantType substitution in rule.");
        }
Exemplo n.º 4
0
        public void TestInheritedChildInfo()
        {
            ChildInfo   info = new ChildInfo("foo", new DomNodeType("foo"));
            DomNodeType test = new DomNodeType(
                "test",
                null,
                EmptyEnumerable <AttributeInfo> .Instance,
                new ChildInfo[] { info },
                EmptyEnumerable <ExtensionInfo> .Instance);

            DomNodeType child = new DomNodeType("child");

            child.BaseType = test;

            ChildInfo inherited = child.GetChildInfo("foo");

            Assert.AreEqual(inherited.OwningType, test);
            Assert.AreEqual(inherited.DefiningType, test);

            Assert.True(inherited.Equivalent(info));
            Assert.True(info.Equivalent(inherited));
        }
Exemplo n.º 5
0
        public void Test()
        {
            XmlSchemaTypeLoader loader = new XmlSchemaTypeLoader();

            loader.SchemaResolver = new ResourceStreamResolver(
                Assembly.GetExecutingAssembly(),
                "UnitTests.Atf/Resources");
            loader.Load("testComplexTypes.xsd");

            DomNodeType abstractType = loader.GetNodeType("test:abstractType");

            Assert.IsTrue(abstractType != null);
            Assert.IsTrue(abstractType.IsAbstract);

            DomNodeType complexType1 = loader.GetNodeType("test:complexType1");

            Assert.IsTrue(complexType1 != null);
            Assert.IsTrue(!complexType1.IsAbstract);
            Assert.IsTrue(complexType1.BaseType == abstractType);
            //Assert.IsTrue(complexType1.FindAnnotation("annotation") != null);
            //Assert.IsTrue(complexType1.FindAnnotation("annotation", "attr1") != null);

            DomNodeType complexType2 = loader.GetNodeType("test:complexType2");

            Assert.IsTrue(complexType2 != null);
            Assert.IsTrue(!complexType2.IsAbstract);
            AttributeInfo attr1 = complexType2.GetAttributeInfo("attr1");

            Assert.IsTrue(attr1 != null);
            Assert.IsTrue(attr1.DefaultValue.Equals(1));
            //Assert.IsTrue(attr1.FindAnnotation("annotation") != null);
            AttributeInfo attr2 = complexType2.GetAttributeInfo("attr2");

            Assert.IsTrue(attr2 != null);
            Assert.IsTrue(attr2.DefaultValue.Equals(2));

            DomNodeType complexType3 = loader.GetNodeType("test:complexType3");

            Assert.IsTrue(complexType3 != null);
            Assert.IsTrue(!complexType3.IsAbstract);
            Assert.IsTrue(complexType3.BaseType == complexType2);
            AttributeInfo attr3 = complexType3.GetAttributeInfo("attr3");

            Assert.IsTrue(attr3 != null);
            ChildInfo elem1 = complexType3.GetChildInfo("elem1");

            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == complexType1);
            //Assert.IsTrue(elem1.FindAnnotation("annotation") != null);
            ChildInfo elem2 = complexType3.GetChildInfo("elem2");

            Assert.IsTrue(elem2 != null);
            Assert.IsTrue(elem2.Type == complexType1);
            Assert.IsTrue(MinMaxCheck(elem2, 1, 3));
            ChildInfo elem3 = complexType3.GetChildInfo("elem3");

            Assert.IsTrue(elem3 != null); //because a sequence of simple types becomes a sequence of child DomNodes
            attr3 = complexType3.GetAttributeInfo("elem3");
            Assert.IsTrue(attr3 == null); //because a sequence of simple types becomes a sequence of child DomNodes
            DomNode       node3                   = new DomNode(complexType3);
            DomNode       elem3Child1             = new DomNode(elem3.Type);
            AttributeInfo elem3ValueAttributeInfo = elem3.Type.GetAttributeInfo(string.Empty);

            elem3Child1.SetAttribute(elem3ValueAttributeInfo, 1);
            DomNode elem3Child2 = new DomNode(elem3.Type);

            elem3Child2.SetAttribute(elem3ValueAttributeInfo, 1);
            DomNode elem3Child3 = new DomNode(elem3.Type);

            elem3Child3.SetAttribute(elem3ValueAttributeInfo, 1);
            node3.GetChildList(elem3).Add(elem3Child1);
            node3.GetChildList(elem3).Add(elem3Child2);
            node3.GetChildList(elem3).Add(elem3Child3);

            IList <DomNode> node3Children = node3.GetChildList(elem3);

            Assert.IsTrue((int)node3Children[0].GetAttribute(elem3ValueAttributeInfo) == 1);
            Assert.IsTrue((int)node3Children[1].GetAttribute(elem3ValueAttributeInfo) == 1);
            Assert.IsTrue((int)node3Children[2].GetAttribute(elem3ValueAttributeInfo) == 1);

            // Update on 8/16/2011. DomXmlReader would not be able to handle a sequence of elements
            //  of a simple type like this. When reading, each subsequent element's value would be
            //  used to set the attribute on the DomNode, overwriting the previous one. So, since
            //  this behavior of converting more than one element of a simple type into an attribute
            //  array was broken, I want to change this unit test that I wrote and make sequences of
            //  elements of simple types into a sequence of DomNode children with a value attribute.
            //  (A value attribute means an attribute whose name is "".) --Ron
            //ChildInfo elem3 = complexType3.GetChildInfo("elem3");
            //Assert.IsTrue(elem3 == null); //because a sequence of simple types becomes an attribute
            //attr3 = complexType3.GetAttributeInfo("elem3");
            //Assert.IsTrue(attr3 != null); //because a sequence of simple types becomes an attribute
            //DomNode node3 = new DomNode(complexType3);
            //object attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int &&
            //    (int)attr3Obj == 0); //the default integer
            //node3.SetAttribute(attr3, 1);
            //attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int &&
            //    (int)attr3Obj == 1);
            //node3.SetAttribute(attr3, new int[] { 1, 2, 3 });
            //attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int[] &&
            //    ((int[])attr3Obj)[2]==3);

            DomNodeType complexType4 = loader.GetNodeType("test:complexType4");

            Assert.IsTrue(complexType4 != null);
            Assert.IsTrue(!complexType4.IsAbstract);
            attr1 = complexType4.GetAttributeInfo("attr1");
            Assert.IsTrue(attr1 != null);
            elem1 = complexType4.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == complexType3);
            Assert.IsTrue(MinMaxCheck(elem1, 1, 1));

            DomNodeType complexType5 = loader.GetNodeType("test:complexType5");

            Assert.IsTrue(complexType5 != null);
            Assert.IsTrue(!complexType5.IsAbstract);
            elem1 = complexType5.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == abstractType);
            Assert.IsTrue(MinMaxCheck(elem1, 1, Int32.MaxValue));

            DomNode node5 = new DomNode(complexType5);

            elem2 = complexType5.GetChildInfo("elem2");
            DomNode node2 = new DomNode(complexType2);

            node5.SetChild(elem2, node2);
            node5.SetChild(elem2, null);
            node3 = new DomNode(complexType3);
            elem3 = complexType5.GetChildInfo("elem3");
            node5.SetChild(elem3, node3);
            //The following should violate xs:choice, but we don't fully support this checking yet.
            //ExceptionTester.CheckThrow<InvalidOperationException>(delegate { node5.AddChild(elem2, node2); });

            DomNodeType complexType6 = loader.GetNodeType("test:complexType6");

            Assert.IsTrue(complexType6 != null);
            Assert.IsTrue(!complexType6.IsAbstract);
            elem1 = complexType6.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == abstractType);
            Assert.IsTrue(MinMaxCheck(elem1, 1, Int32.MaxValue));
            elem2 = complexType6.GetChildInfo("elem2");
            Assert.IsTrue(elem2 != null);
            Assert.IsTrue(elem2.Type == complexType2);
            Assert.IsTrue(MinMaxCheck(elem2, 1, Int32.MaxValue));

            //DomNodeType complexType7 = loader.GetNodeType("test:complexType7");
            //Assert.IsTrue(complexType7 != null);
            //Assert.IsTrue(!complexType7.IsAbstract);
            //AttributeInfo attrSimpleSequence = complexType7.GetAttributeInfo("elemSimpleSequence");
            //Assert.IsTrue(attrSimpleSequence == null); //because a sequence of simple types becomes a sequence of child DomNodes
            //ChildInfo elemSimpleSequence = complexType7.GetChildInfo("elemSimpleSequence");
            //Assert.IsTrue(elemSimpleSequence != null); //because a sequence of simple types becomes a sequence of child DomNodes
            //DomNode node7 = new DomNode(complexType7);
            //object attrObj7 = node7.GetAttribute(attrSimpleSequence);
            //Assert.IsTrue(
            //    attrObj7 is float[] &&
            //    ((float[])attrObj7)[0] == 0 &&
            //    ((float[])attrObj7)[1] == 0 &&
            //    ((float[])attrObj7)[2] == 0); //the default vector
            //float[][] newSequence =
            //{
            //    new float[] {1, 2, 3},
            //    new float[] {4, 5, 6},
            //    new float[] {7, 8, 9}
            //};
            //node7.SetAttribute(attrSimpleSequence, newSequence);
            //attrObj7 = node7.GetAttribute(attrSimpleSequence);
            //Assert.IsTrue(ArraysEqual(attrObj7, newSequence));
        }
Exemplo n.º 6
0
        public void TestOverriddenChildInfo()
        {
            DomNodeType childType = new DomNodeType("foo");
            ChildInfo info = new ChildInfo("foo", childType);
            DomNodeType test = new DomNodeType(
                "test",
                null,
                EmptyEnumerable<AttributeInfo>.Instance,
                new ChildInfo[] { info },
                EmptyEnumerable<ExtensionInfo>.Instance);

            ChildInfo overridden = new ChildInfo("foo", childType);
            DomNodeType child = new DomNodeType("child", test,
                EmptyEnumerable<AttributeInfo>.Instance,
                new ChildInfo[] { overridden },
                EmptyEnumerable<ExtensionInfo>.Instance);

            Assert.AreSame(child.GetChildInfo("foo"), overridden);
            Assert.AreEqual(overridden.OwningType, child);
            Assert.AreEqual(overridden.DefiningType, test);

            Assert.True(info.Equivalent(overridden));
            Assert.True(overridden.Equivalent(info));

            Assert.True(test.IsValid(overridden));
            Assert.True(child.IsValid(info));
        }
Exemplo n.º 7
0
        public void TestInheritedChildInfo()
        {
            ChildInfo info = new ChildInfo("foo", new DomNodeType("foo"));
            DomNodeType test = new DomNodeType(
                "test",
                null,
                EmptyEnumerable<AttributeInfo>.Instance,
                new ChildInfo[] { info },
                EmptyEnumerable<ExtensionInfo>.Instance);

            DomNodeType child = new DomNodeType("child");
            child.BaseType = test;

            ChildInfo inherited = child.GetChildInfo("foo");
            Assert.AreEqual(inherited.OwningType, test);
            Assert.AreEqual(inherited.DefiningType, test);

            Assert.True(inherited.Equivalent(info));
            Assert.True(info.Equivalent(inherited));
        }
Exemplo n.º 8
0
        public void TestCustomChildInfo()
        {
            DomNodeType type = new DomNodeType("foo");
            ChildInfo info = new ChildInfo("foo", type);
            DomNodeType test = new DomNodeType(
                "test",
                null,
                EmptyEnumerable<AttributeInfo>.Instance,
                new ChildInfo[] { info },
                EmptyEnumerable<ExtensionInfo>.Instance);

            Utilities.TestSequenceEqual(test.Children, info);
            Assert.True(test.IsValid(info));
            Assert.AreSame(test.GetChildInfo("foo"), info);
            // check that type is now frozen
            Assert.Throws<InvalidOperationException>(delegate { test.Define(new ChildInfo("notFoo", type)); });

            Assert.AreEqual(info.OwningType, test);
            Assert.AreEqual(info.DefiningType, test);
            Assert.Null(test.GetChildInfo("bar"));
        }
Exemplo n.º 9
0
        void IInitializable.Initialize()
        {
            m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent);
            m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this);

            Application.ApplicationExit += delegate
            {
                Util3D.Shutdown();
                GameEngine.Shutdown();
            };

            GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews();

            m_gameDocumentRegistry.DocumentAdded   += m_gameDocumentRegistry_DocumentAdded;
            m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved;

            string ns = m_schemaLoader.NameSpace;

            // register GridRenderer on grid child.
            DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType");

            gridType.Define(new ExtensionInfo <GridRenderer>());

            // register NativeGameWorldAdapter on game type.
            m_schemaLoader.GameType.Define(new ExtensionInfo <NativeDocumentAdapter>());

            // parse schema annotation.
            foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes())
            {
                var topLevelAnnotations = domType.GetTagLocal <IEnumerable <XmlNode> >();
                if (topLevelAnnotations == null)
                {
                    continue;
                }

                // First, go through and interpret the annotations that are not inherited
                List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>();
                foreach (XmlNode annot in topLevelAnnotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == NativeAnnotations.NativeType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeObjectAdapter>());
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeDocumentType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeDocumentType, GameEngine.GetDocumentTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeDocumentAdapter>());
                        }
                    }
                }

                if (domType.GetTag(NativeAnnotations.NativeType) == null)
                {
                    continue;
                }
                uint typeId          = (uint)domType.GetTag(NativeAnnotations.NativeType);
                bool isBoundableType = false;

                // Now, go through and interpret annotations that can be inheritted from base clases.
                // Sometimes a native property can be inheritted from a base class. In this model, we
                // will create a separate "property id" for each concrete class. When a property is
                // inheritted, the "property ids" for each type in the inheritance chain will be different
                // and unrelated.

                foreach (var inherittedType in domType.Lineage)
                {
                    var annotations = inherittedType.GetTagLocal <IEnumerable <XmlNode> >();
                    if (annotations == null)
                    {
                        continue;
                    }

                    foreach (XmlNode annot in annotations)
                    {
                        XmlElement elm = annot as XmlElement;
                        if (elm.LocalName == NativeAnnotations.NativeProperty)
                        {
                            // find a prop name and added to the attribute.
                            string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName);
                            string attribName     = elm.GetAttribute(NativeAnnotations.Name);
                            uint   propId         = GameEngine.GetObjectPropertyId(typeId, nativePropName);
                            if (!string.IsNullOrEmpty(attribName))
                            {
                                AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name));
                                attribInfo.SetTag(NativeAnnotations.NativeProperty, propId);
                            }
                            else
                            {
                                NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId);
                                nativeAttribs.Add(attribInfo);
                            }

                            if (nativePropName == "Bounds" || nativePropName == "LocalBounds")
                            {
                                isBoundableType = true;
                            }
                        }
                        else if (elm.LocalName == NativeAnnotations.NativeElement)
                        {
                            ChildInfo info = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name));
                            string    name = elm.GetAttribute(NativeAnnotations.NativeName);
                            info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name));
                        }
                        else if (elm.LocalName == NativeAnnotations.NativeVis)
                        {
                            using (var transfer = new NativeObjectAdapter.NativePropertyTransfer())
                            {
                                using (var stream = transfer.CreateStream())
                                    foreach (var a in elm.Attributes)
                                    {
                                        var attrib = a as XmlAttribute;
                                        if (attrib.Name == "geo")
                                        {
                                            NativeObjectAdapter.PushAttribute(
                                                0,
                                                typeof(string), 1,
                                                attrib.Value,
                                                transfer.Properties, stream);
                                        }
                                    }

                                GameEngine.SetTypeAnnotation(typeId, "vis", transfer.Properties);
                            }
                        }
                    }
                }

                if (nativeAttribs.Count > 0)
                {
                    domType.SetTag(nativeAttribs.ToArray());
                }

                if (isBoundableType && domType.IsAbstract == false)
                {
                    domType.Define(new ExtensionInfo <BoundableObject>());
                }
            }


            // register BoundableObject
            m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>());   // doesn't have a bound native attributes -- is this really intended?s

            #region code to handle gameObjectFolder

            {
                // This code is fragile and need to be updated whenever
                // any relevant part of the schema changes.
                // purpose:
                // gameObjectFolderType does not exist in C++
                // this code will map gameObjectFolderType to gameObjectGroupType.
                DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType;
                DomNodeType groupType     = m_schemaLoader.GameObjectGroupType;

                // map native bound attrib from gameObject to GobFolder
                NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>();
                foreach (var attrib in nativeAttribs)
                {
                    if (attrib.Name == "Bounds")
                    {
                        gobFolderType.SetTag(new NativeAttributeInfo[] { attrib });
                        break;
                    }
                }

                // map type.
                //      XLE --> Separate GameObjectFolder type from GameObjectGroup type
                // gobFolderType.Define(new ExtensionInfo<NativeObjectAdapter>());
                // gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType));

                // map all native attributes of gameObjectGroup to gameFolder
                foreach (AttributeInfo srcAttrib in groupType.Attributes)
                {
                    object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty);
                    if (nativeIdObject == null)
                    {
                        continue;
                    }
                    AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name);
                    if (destAttrib == null)
                    {
                        continue;
                    }
                    destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject);
                    destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib);
                }

                // map native element from gameObjectGroupType to gameObjectFolderType.
                object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement);
                foreach (ChildInfo srcChildInfo in gobFolderType.Children)
                {
                    if (srcChildInfo.IsList)
                    {
                        srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId);
                    }
                }

                m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId);
            }

            #endregion

            // set up scripting bindings
            if (m_scriptingService != null)
            {
                m_scriptingService.SetVariable("cv", new GUILayer.TweakableBridge());
            }
        }
Exemplo n.º 10
0
        private RenderState CreateRenderStateFromProfileCOMMON()
        {
            RenderState rs = null;

            DomNode profile_COMMON = this.DomNode.GetChild(Schema.effect.profile_COMMONChild);

            if (profile_COMMON == null)
            {
                return(rs);
            }

            // Get technique
            DomNode technique_COMMON = profile_COMMON.GetChild(Schema.profile_COMMON.techniqueChild);

            if (technique_COMMON == null)
            {
                return(rs);
            }

            // Get shading profile
            DomNode shader =
                technique_COMMON.GetChild(Schema.profile_COMMON_technique.blinnChild) ??
                technique_COMMON.GetChild(Schema.profile_COMMON_technique.constantChild) ??
                technique_COMMON.GetChild(Schema.profile_COMMON_technique.lambertChild) ??
                technique_COMMON.GetChild(Schema.profile_COMMON_technique.phongChild);

            if (shader == null)
            {
                return(rs);
            }

            rs = CreateRenderStateDefault();



            //<xs:sequence>
            //  <xs:element name="emission" type="common_color_or_texture_type" minOccurs="0"/>
            //  <xs:element name="ambient" type="common_color_or_texture_type" minOccurs="0"/>
            //  <xs:element name="diffuse" type="common_color_or_texture_type" minOccurs="0"/>
            //  <xs:element name="specular" type="common_color_or_texture_type" minOccurs="0"/>
            //  <xs:element name="shininess" type="common_float_or_param_type" minOccurs="0"/>
            //  <xs:element name="reflective" type="common_color_or_texture_type" minOccurs="0"/>
            //  <xs:element name="reflectivity" type="common_float_or_param_type" minOccurs="0"/>
            //  <xs:element name="transparent" type="common_transparent_type" minOccurs="0"/>
            //  <xs:element name="transparency" type="common_float_or_param_type" minOccurs="0"/>
            //  <xs:element name="index_of_refraction" type="common_float_or_param_type" minOccurs="0"/>
            //</xs:sequence>



            DomNodeType shaderType = shader.Type;
            ChildInfo   emission   = shaderType.GetChildInfo("emission");
            ChildInfo   ambient    = shaderType.GetChildInfo("ambient");
            ChildInfo   diffuse    = shaderType.GetChildInfo("diffuse");
            ChildInfo   specular   = shaderType.GetChildInfo("specular");
            ChildInfo   shininess  = shaderType.GetChildInfo("shininess");

            shaderType.GetChildInfo("reflective");
            shaderType.GetChildInfo("reflectivity");
            shaderType.GetChildInfo("transparent");
            ChildInfo transparency = shaderType.GetChildInfo("transparency");

            shaderType.GetChildInfo("index_of_refrac");


            if (emission != null)
            {
                float[] emissionColor = Tools.GetColor(shader.GetChild(emission));
                if (emissionColor != null)
                {
                    rs.EmissionColor = new Vec4F(emissionColor);
                }
            }

            if (ambient != null)
            {
                // Surface properties
                float[] ambientColor = Tools.GetColor(shader.GetChild(ambient));
                if (ambientColor != null)
                {
                    rs.AmbientColor = new Vec4F(ambientColor);
                }
            }

            float transparencyVal = -1.0f;

            if (transparency != null)
            {
                transparencyVal = Tools.GetFloat(shader.GetChild(transparency));
            }

            if (diffuse != null)
            {
                float[] diffuseColor = Tools.GetColor(shader.GetChild(diffuse));
                if (diffuseColor != null)
                {
                    if (transparencyVal >= 0.0f)
                    {
                        diffuseColor[3] = transparencyVal;
                        if (transparencyVal < 1.0f)
                        {
                            rs.RenderMode |= RenderMode.Alpha;
                        }
                    }
                    rs.DiffuseColor = new Vec4F(diffuseColor);
                }
            }


            if (specular != null)
            {
                float[] specularColor = Tools.GetColor(shader.GetChild(specular));
                if (specularColor != null)
                {
                    rs.SpecularColor = new Vec4F(specularColor);
                }

                if (shininess != null)
                {
                    float shine = Tools.GetFloat(shader.GetChild(shininess));
                    rs.Shininess = shine;
                }
            }

            if (diffuse == null)
            {
                return(rs);
            }

            DomNode diffuseChild = shader.GetChild(diffuse);
            DomNode textureChild = diffuseChild.GetChild(Schema.common_color_or_texture_type.textureChild);

            if (textureChild == null)
            {
                return(rs);
            }


            string strTexture = (string)textureChild.GetAttribute(Schema.common_color_or_texture_type_texture.textureAttribute);

            if (string.IsNullOrEmpty(strTexture))
            {
                return(rs);
            }


            IList <DomNode> newParams = profile_COMMON.GetChildList(Schema.profile_COMMON.newparamChild);
            DomNode         sampler   = null;

            foreach (DomNode newParam in newParams)
            {
                string sid = newParam.GetAttribute(Schema.common_newparam_type.sidAttribute) as string;
                if (strTexture == sid)
                {
                    sampler = newParam;
                    break;
                }
            }

            if (sampler == null)
            {
                return(rs);
            }

            // sampler2D
            DomNode sampler2D = sampler.GetChild(Schema.common_newparam_type.sampler2DChild);

            if (sampler2D == null)
            {
                return(rs);
            }

            string source = sampler2D.GetAttribute(Schema.fx_sampler2D_common.sourceAttribute) as string;

            DomNode surfaceParam = null;

            foreach (DomNode newParam in newParams)
            {
                string sid = newParam.GetAttribute(Schema.common_newparam_type.sidAttribute) as string;
                if (source == sid)
                {
                    surfaceParam = newParam;
                    break;
                }
            }
            if (surfaceParam == null)
            {
                return(rs);
            }

            DomNode surface = surfaceParam.GetChild(Schema.common_newparam_type.surfaceChild);

            if (surface == null)
            {
                return(rs);
            }

            // init_from
            //string id = (string)surface.GetAttribute(Schema.fx_surface_common.init_fromAttribute);
            IList <DomNode> init_fromList = surface.GetChildList(Schema.fx_surface_common.init_fromChild);

            if (init_fromList.Count > 0)
            {
                DomNode init_from = init_fromList[0];
                DomNode image     = (DomNode)init_from.GetAttribute(Schema.fx_surface_init_from_common.Attribute);

                Uri uri = (Uri)image.GetAttribute(Schema.image.init_fromAttribute);
                BindTexture(uri, rs);
            }

            return(rs);
        }
Exemplo n.º 11
0
        void IInitializable.Initialize()
        {
            m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent);
            m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this);

            Application.ApplicationExit += delegate
            {
                Util3D.Shutdown();
                GameEngine.Shutdown();
            };

            GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews();

            m_gameDocumentRegistry.DocumentAdded   += m_gameDocumentRegistry_DocumentAdded;
            m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved;

            string ns = m_schemaLoader.NameSpace;

            // register GridRenderer on grid child.
            DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType");

            gridType.Define(new ExtensionInfo <GridRenderer>());

            // register NativeGameWorldAdapter on game type.
            m_schemaLoader.GameType.Define(new ExtensionInfo <NativeGameWorldAdapter>());

            // parse schema annotation.
            foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes())
            {
                IEnumerable <XmlNode> annotations = domType.GetTagLocal <IEnumerable <XmlNode> >();
                if (annotations == null)
                {
                    continue;
                }


                // collect all the properties that only exist in native side.
                List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>();

                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == NativeAnnotations.NativeType)
                    {
                        string typeName = elm.GetAttribute(NativeAnnotations.NativeName);
                        domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName));
                        if (domType.IsAbstract == false)
                        {
                            domType.Define(new ExtensionInfo <NativeObjectAdapter>());
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeProperty)
                    {
                        // find a prop name and added to the attribute.


                        string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName);
                        string attribName     = elm.GetAttribute(NativeAnnotations.Name);
                        uint   typeId         = (uint)domType.GetTag(NativeAnnotations.NativeType);
                        uint   propId         = GameEngine.GetObjectPropertyId(typeId, nativePropName);
                        if (!string.IsNullOrEmpty(attribName))
                        {
                            AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name));
                            attribInfo.SetTag(NativeAnnotations.NativeProperty, propId);
                        }
                        else
                        {
                            NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId);
                            nativeAttribs.Add(attribInfo);
                        }
                    }
                    else if (elm.LocalName == NativeAnnotations.NativeElement)
                    {
                        ChildInfo info   = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name));
                        uint      typeId = (uint)domType.GetTag(NativeAnnotations.NativeType);
                        string    name   = elm.GetAttribute(NativeAnnotations.NativeName);
                        info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name));
                    }
                }

                if (nativeAttribs.Count > 0)
                {
                    domType.SetTag(nativeAttribs.ToArray());
                }
            }


            // register BoundableObject
            m_schemaLoader.GameObjectType.Define(new ExtensionInfo <BoundableObject>());
            m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>());

            #region code to handle gameObjectFolder

            {
                // This code is fragile and need to be updated whenever
                // any relevant part of the schema changes.
                // purpose:
                // gameObjectFolderType does not exist in C++
                // this code will map gameObjectFolderType to gameObjectGroupType.
                DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType;
                DomNodeType groupType     = m_schemaLoader.GameObjectGroupType;

                // map native bound attrib from gameObject to GobFolder
                NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>();
                foreach (var attrib in nativeAttribs)
                {
                    if (attrib.Name == "Bounds")
                    {
                        gobFolderType.SetTag(new NativeAttributeInfo[] { attrib });
                        break;
                    }
                }

                // map type.
                gobFolderType.Define(new ExtensionInfo <NativeObjectAdapter>());
                gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType));

                // map all native attributes of gameObjectGroup to gameFolder
                foreach (AttributeInfo srcAttrib in groupType.Attributes)
                {
                    object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty);
                    if (nativeIdObject == null)
                    {
                        continue;
                    }
                    AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name);
                    if (destAttrib == null)
                    {
                        continue;
                    }
                    destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject);
                    destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib);
                }

                // map native element from gameObjectGroupType to gameObjectFolderType.
                object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement);
                foreach (ChildInfo srcChildInfo in gobFolderType.Children)
                {
                    if (srcChildInfo.IsList)
                    {
                        srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId);
                    }
                }

                m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId);
            }

            #endregion
        }
Exemplo n.º 12
0
        /// <summary>
        /// Performs initialization when the adapter's node is set.
        /// This method is called each time the adapter is connected to its underlying node.
        /// Typically overridden by creators of DOM adapters.</summary>
        protected override void OnNodeSet()
        {
            base.OnNodeSet();
            Visible = true;
            DomNodeType domtype        = this.DomNode.Type;
            ChildInfo   inputChildInfo = domtype.GetChildInfo("input");
            Mesh        mesh           = GetParentAs <Mesh>();

            int maxoffset = -1;

            // get input child info.
            foreach (DomNode inputNode in DomNode.GetChildList(inputChildInfo))
            {
                PrimInput pinput = new PrimInput(inputNode, mesh);
                if (pinput.Offset > maxoffset)
                {
                    maxoffset = pinput.Offset;
                }
                if (pinput.Semantic == "VERTEX")
                {
                    foreach (PrimInput vinput in mesh.VertexInputs)
                    {
                        PrimInput input = new PrimInput(vinput, pinput.Offset);
                        m_inputs.Add(input);
                    }
                }
                else
                {
                    m_inputs.Add(pinput);
                }
            }

            m_bindingCount = maxoffset + 1;

            // prim type
            string type = DomNode.ToString();

            m_primitiveType = type.Substring(type.LastIndexOf(':') + 1).ToUpper();
            if (m_primitiveType == "POLYLIST")
            {
                m_primitiveType = "POLYGONS";
            }

            // indices
            AttributeInfo pattrib = DomNode.Type.GetAttributeInfo("p");

            m_indices = Tools.ULongToInt(GetAttribute <ulong[]>(pattrib));

            // material
            AttributeInfo mtrlAttrib = DomNode.Type.GetAttributeInfo("material");
            string        mtrl       = GetAttribute <string>(mtrlAttrib);
            Geometry      geom       = DomNode.Parent.Parent.Cast <Geometry>();

            m_effect = geom.Effects[mtrl];

            // vcount, element sizes
            AttributeInfo vcountAttrib = DomNode.Type.GetAttributeInfo("vcount");

            if (vcountAttrib != null)
            {
                m_sizes = Tools.ULongToInt(GetAttribute <ulong[]>(vcountAttrib));
            }
            else
            {
                m_sizes = new int[] { 3 }
            };

            //count
            AttributeInfo countAttrib = DomNode.Type.GetAttributeInfo("count");

            m_count = (int)GetAttribute <ulong>(countAttrib);

            // name
            AttributeInfo nameAttrib = DomNode.Type.GetAttributeInfo("name");

            m_name = GetAttribute <string>(nameAttrib);
        }