Exemplo n.º 1
0
        public static void Create( object source, ContextMenuArgs e )
        {
            EntityCreationProperties buildproperties = new EntityCreationProperties( e.MouseX, e.MouseY );

            FractalSplineBox newentity = new FractalSplineBox();
            buildproperties.WriteToEntity( newentity, "Box" );

            MetaverseClient.GetInstance().worldstorage.AddEntity(newentity);
        }
Exemplo n.º 2
0
        public static void Create(object source, ContextMenuArgs e)
        {
            EntityCreationProperties buildproperties = new EntityCreationProperties(e.MouseX, e.MouseY);

            FractalSplineBox newentity = new FractalSplineBox();

            buildproperties.WriteToEntity(newentity, "Box");

            MetaverseClient.GetInstance().worldstorage.AddEntity(newentity);
        }
Exemplo n.º 3
0
        // need to add a publisher/subscriber to this ;-)
        public void Restore(string filename)
        {
            WorldModel worldmodel = MetaverseClient.GetInstance().worldstorage;

            //// note to self: should make these types a publisher/subscriber thing
            //XmlSerializer serializer = new XmlSerializer( worldmodel.entities.GetType(), new Type[]{
            //   typeof( Avatar ),
            //  typeof( FractalSplineCylinder ),
            //  //typeof( FractalSplineRing ),
            //  typeof( FractalSplineBox )
            // } );
            //FileStream filestream = new FileStream( filename, FileMode.Open );
            //worldmodel.entities = (EntityArrayList)serializer.Deserialize( filestream );

/*
 *          <type val="0" />
 * <position x="5.25000047684" y="7.75" z="8.75" />
 * <rotation x="0.707107126713" y="-0.707106411457" z="-1.1520197063e-007" s="6.65917468723e-007" />
 * <size x="4.75" y="10.0" z="0.10000000149" />
 * <cut x="0.0" y="1.0" />
 * <dimple x="0.0" y="1.0" />
 * <advancedcut x="0.0" y="1.0" />
 * <hollow val="0" />
 * <twist x="0" y="0" />
 * <topsize x="1.0" y="1.0" />
 * <holesize x="1.0" y="0.5" />
 * <topshear x="0.0" y="0.0" />
 * <taper x="0.0" y="0.0" />
 * <revolutions val="1.0" />
 * <radiusoffset val="0.0" />
 * <skew val="0.0" />
 * <material val="3" />
 * <hollowshape val="0" />
 */

            worldmodel.entities.Clear();
            XmlDocument primsdom = XmlHelper.OpenDom(filename);

            foreach (XmlElement primitiveelement in primsdom.DocumentElement.SelectNodes("primitive"))
            {
                FractalSplineBox newbox            = new FractalSplineBox();
                XmlElement       propertieselement = primitiveelement.SelectSingleNode("properties") as XmlElement;
                newbox.pos    = new Vector3(primitiveelement.SelectSingleNode("properties/position") as XmlElement);
                newbox.rot    = new Rot(primitiveelement.SelectSingleNode("properties/rotation") as XmlElement);
                newbox.scale  = new Vector3(primitiveelement.SelectSingleNode("properties/size") as XmlElement);
                newbox.Hollow = Convert.ToInt32((propertieselement.SelectSingleNode("hollow") as XmlElement).GetAttribute("val").ToString());
                // newbox.Twist = Convert.ToInt32( propertieselement.SelectSingleNode( "twist" ) as XmlElement ).GetAttribute("x" ).ToString() );
                newbox.TopSizeX = Convert.ToDouble((propertieselement.SelectSingleNode("topsize") as XmlElement).GetAttribute("x").ToString());
                newbox.TopSizeY = Convert.ToDouble((propertieselement.SelectSingleNode("topsize") as XmlElement).GetAttribute("y").ToString());
                newbox.CutStart = (int)(Convert.ToDouble((propertieselement.SelectSingleNode("cut") as XmlElement).GetAttribute("x").ToString()) * 200);
                newbox.CutEnd   = (int)(Convert.ToDouble((propertieselement.SelectSingleNode("cut") as XmlElement).GetAttribute("y").ToString()) * 200);
                worldmodel.entities.Add(newbox);
            }
        }
Exemplo n.º 4
0
        public void TestGeneralBinaryPackerFunctionality()
        {
            byte[] bytearray = new byte[1024];
                    int position = 0;
               TestClass testclass = new TestClass();
            testclass.booleanvaluetrue = true;
               testclass.charvalue = 'C';
            testclass.doublevalue = 123.4567890;
            testclass.intvalue = 1234567890;
            testclass.Country = "Spain";
            testclass.name = "Test class name";
            testclass.indexes = new int[] { 5, 1, 4, 2, 3 };
            testclass.childclass = new ChildClass();
            testclass.childclass.name = "name inside child class";

            BinaryPacker bp = new BinaryPacker();

            //Write several objects into the buffer
            bp.WriteValueToBuffer(bytearray, ref position, testclass);
            bp.WriteValueToBuffer(bytearray, ref position, "The quick brown fox.");
            bp.WriteValueToBuffer(bytearray, ref position, "Rain in Spain.");

            bp.PackObjectUsingSpecifiedAttributes(bytearray, ref position, testclass, new Type[] { typeof(AttributePack) });

            byte[] bytearraytowrite = Encoding.UTF8.GetBytes("Hello world");
            bp.WriteValueToBuffer(bytearray, ref position, bytearraytowrite);

            FractalSplineBox box = new FractalSplineBox();

            box.name = "Test box";

            box.pos = new Vector3(1, 123.123, 150.150);

            bp.PackObjectUsingSpecifiedAttributes(bytearray, ref position, box, new Type[] { typeof(Replicate) });

            position = 0;

            //verify all the items we put in
            TestClass outputobject = (TestClass)new BinaryPacker().ReadValueFromBuffer(bytearray, ref position, typeof(TestClass));

            string error = "Trouble unpacking TestClass from BinaryPacker";
            Assert.AreEqual( true, outputobject.booleanvaluetrue, error );
            Assert.AreEqual( 'C', outputobject.charvalue,  error );
            Assert.AreEqual( 123.4567890, outputobject.doublevalue,   error );
            Assert.AreEqual( 1234567890 , outputobject.intvalue,  error);
            Assert.AreEqual( "Spain" , outputobject.Country,  error);
            Assert.AreEqual( "Test class name", outputobject.name,  error);
            Assert.AreEqual( 5, outputobject.indexes.Length, error);
            Assert.AreEqual( 5, outputobject.indexes[0], error);
            Assert.AreEqual( 1, outputobject.indexes[1], error);
            Assert.AreEqual( 4, outputobject.indexes[2],  error);
            Assert.AreEqual( 2, outputobject.indexes[3],  error);
            Assert.AreEqual( 3, outputobject.indexes[4],  error);
            Assert.AreEqual( "name inside child class", outputobject.childclass.name,  error);

            string sout = (string)new BinaryPacker().ReadValueFromBuffer(bytearray, ref position, typeof(string));
                Assert.AreEqual( "The quick brown fox.", sout, "Could not unpack string");

            sout = (string)new BinaryPacker().ReadValueFromBuffer(bytearray, ref position, typeof(string));
            Assert.AreEqual( "Rain in Spain.", sout, "Could not unpack second string");

            outputobject = new TestClass();
            bp.UnpackIntoObjectUsingSpecifiedAttributes(bytearray, ref position, outputobject, new Type[] { typeof(AttributePack) });
            Assert.AreEqual( null, outputobject.name, "Error in value of unset value in attribute packing"); // should be blank, because name member has a AttributePack attribute
            Assert.AreEqual( "Spain", outputobject.Country, "Error in value of set value in attribute packing" ); //Country does have an AttributePack attribute

            bytearraytowrite = (byte[])new BinaryPacker().ReadValueFromBuffer(bytearray, ref position, typeof(byte[]));
            Assert.AreEqual( "Hello world", Encoding.UTF8.GetString(bytearraytowrite), "Error in unpacking UTF8"  );
            FractalSplineBox boxobject = new FractalSplineBox();
            new BinaryPacker().UnpackIntoObjectUsingSpecifiedAttributes(bytearray, ref position, boxobject, new Type[] { typeof(Replicate) });
            Assert.AreEqual( "Test box", boxobject.name, "Error in unpacking FractelSplineBox name" );
            Assert.AreEqual( new Vector3(1,123.123, 150.150),  box.pos, "Error in unpacking FractelSplineBox position" );
        }
        // need to add a publisher/subscriber to this ;-)
        public void Restore( string filename )
        {
            WorldModel worldmodel = MetaverseClient.GetInstance().worldstorage;

            //// note to self: should make these types a publisher/subscriber thing
            //XmlSerializer serializer = new XmlSerializer( worldmodel.entities.GetType(), new Type[]{
             //   typeof( Avatar ),
              //  typeof( FractalSplineCylinder ),
              //  //typeof( FractalSplineRing ),
              //  typeof( FractalSplineBox )
               // } );
            //FileStream filestream = new FileStream( filename, FileMode.Open );
            //worldmodel.entities = (EntityArrayList)serializer.Deserialize( filestream );
            /*
            <type val="0" />
            <position x="5.25000047684" y="7.75" z="8.75" />
            <rotation x="0.707107126713" y="-0.707106411457" z="-1.1520197063e-007" s="6.65917468723e-007" />
            <size x="4.75" y="10.0" z="0.10000000149" />
            <cut x="0.0" y="1.0" />
            <dimple x="0.0" y="1.0" />
            <advancedcut x="0.0" y="1.0" />
            <hollow val="0" />
            <twist x="0" y="0" />
            <topsize x="1.0" y="1.0" />
            <holesize x="1.0" y="0.5" />
            <topshear x="0.0" y="0.0" />
            <taper x="0.0" y="0.0" />
            <revolutions val="1.0" />
            <radiusoffset val="0.0" />
            <skew val="0.0" />
            <material val="3" />
            <hollowshape val="0" />
            */

            worldmodel.entities.Clear();
            XmlDocument primsdom = XmlHelper.OpenDom( filename );
            foreach( XmlElement primitiveelement in primsdom.DocumentElement.SelectNodes( "primitive" ) )
            {
                FractalSplineBox newbox = new FractalSplineBox();
                XmlElement propertieselement = primitiveelement.SelectSingleNode("properties" ) as XmlElement;
                newbox.pos = new Vector3( primitiveelement.SelectSingleNode("properties/position" ) as XmlElement );
                newbox.rot = new Rot( primitiveelement.SelectSingleNode("properties/rotation" ) as XmlElement );
                newbox.scale = new Vector3( primitiveelement.SelectSingleNode("properties/size" ) as XmlElement );
                newbox.Hollow = Convert.ToInt32( ( propertieselement.SelectSingleNode( "hollow" ) as XmlElement ).GetAttribute("val" ).ToString() );
                // newbox.Twist = Convert.ToInt32( propertieselement.SelectSingleNode( "twist" ) as XmlElement ).GetAttribute("x" ).ToString() );
                newbox.TopSizeX = Convert.ToDouble( ( propertieselement.SelectSingleNode( "topsize" ) as XmlElement ).GetAttribute("x" ).ToString() );
                newbox.TopSizeY = Convert.ToDouble( ( propertieselement.SelectSingleNode( "topsize" ) as XmlElement ).GetAttribute("y" ).ToString() );
                newbox.CutStart = (int)( Convert.ToDouble( ( propertieselement.SelectSingleNode( "cut" ) as XmlElement ).GetAttribute("x" ).ToString() ) * 200 );
                newbox.CutEnd = (int)( Convert.ToDouble( ( propertieselement.SelectSingleNode( "cut" ) as XmlElement ).GetAttribute("y" ).ToString() ) * 200 );
                worldmodel.entities.Add( newbox );
            }
        }