예제 #1
0
        /// <summary>
        /// Serializes all the tags in the given index. This serialization preserves the id's of each tag collection.
        /// </summary>
        /// <param name="stream">The target stream.</param>
        /// <param name="tagsIndex">The tags index to serialize.</param>
        public static void Serialize(Stream stream, ITagsCollectionIndex tagsIndex)
        {
            int begin = (int)stream.Position;

            // build a string index.
            ObjectTable <string> stringTable = new ObjectTable <string>(false);

            // convert tag collections to simpler objects.
            List <KeyValuePair <uint, List <KeyValuePair <uint, uint> > > > tagsIndexList = new List <KeyValuePair <uint, List <KeyValuePair <uint, uint> > > >();

            for (uint tagId = 0; tagId < tagsIndex.Max; tagId++)
            {
                TagsCollectionBase tagsCollection = tagsIndex.Get(tagId);
                if (tagsCollection != null)
                { // convert the tags collection to a list and add to the tag index.
                    List <KeyValuePair <uint, uint> > tagsList = new List <KeyValuePair <uint, uint> >();
                    foreach (Tag tag in tagsCollection)
                    {
                        uint keyId   = stringTable.Add(tag.Key);
                        uint valueId = stringTable.Add(tag.Value);

                        tagsList.Add(new KeyValuePair <uint, uint>(
                                         keyId, valueId));
                    }
                    tagsIndexList.Add(new KeyValuePair <uint, List <KeyValuePair <uint, uint> > >(tagId, tagsList));
                }
            }

            // do the serialization.
            TagIndexSerializer.Serialize(begin, stream, tagsIndexList, stringTable);

            // clear everything.
            tagsIndexList.Clear();
        }
예제 #2
0
        public void Disposing_OwnerTypeListIsRemovedWhenEmpty()
        {
            var physics = new MockPhysics();

            var material1 = new MockMaterial();
            var material2 = new MockMaterial();

            ObjectTable.Add(5, material1, physics);
            ObjectTable.Add(6, material2, physics);

            // Make sure the objects are present to begin with
            {
                var materialKey = new ObjectTableOwnershipType(physics, typeof(MockMaterial));

                Assert.IsTrue(ObjectTable.OwnerTypeLookup.ContainsKey(materialKey));
                Assert.IsNotNull(ObjectTable.OwnerTypeLookup[materialKey]);
            }

            material1.Dispose();
            material2.Dispose();

            {
                var materialKey = new ObjectTableOwnershipType(physics, typeof(MockMaterial));

                // As we have disposed both materials; the entry in the dictionary for Physics-MockMaterial should
                // be removed
                Assert.IsFalse(ObjectTable.OwnerTypeLookup.ContainsKey(materialKey));
            }
        }
예제 #3
0
        public void OwnershipDisposale()
        {
            // Create a hierarchy of objects -
            // Physics is the root
            //	Scene
            //		Actor1
            //		Actor2
            //	Material1
            //	Material2
            var physics = new MockPhysics();
            var scene   = new MockScene();
            var mat1    = new MockMaterial();
            var mat2    = new MockMaterial();
            var actor1  = new MockActor();
            var actor2  = new MockActor();

            ObjectTable.Add(1, physics, null);
            ObjectTable.Add(2, mat1, physics);
            ObjectTable.Add(3, mat2, physics);
            ObjectTable.Add(4, scene, physics);
            ObjectTable.Add(5, actor1, scene);
            ObjectTable.Add(6, actor2, scene);

            //

            // Dispose of the root object. This should dispose all object beneath it recursively
            physics.Dispose();

            Assert.IsTrue(physics.Disposed);
            Assert.IsTrue(mat1.Disposed);
            Assert.IsTrue(mat2.Disposed);
            Assert.IsTrue(scene.Disposed);
            Assert.IsTrue(actor1.Disposed);
            Assert.IsTrue(actor2.Disposed);
        }
예제 #4
0
 /// <summary>
 /// Creates a new tags collection initialized with the given existing tags.
 /// </summary>
 /// <param name="tagsTable"></param>
 /// <param name="tags"></param>
 public TagsTableCollection(ObjectTable<Tag> tagsTable, IEnumerable<Tag> tags)
 {
     _tagsTable = tagsTable;
     _tags = new List<uint>();
     foreach(Tag tag in tags)
     {
         _tags.Add(_tagsTable.Add(tag));
     }
 }
예제 #5
0
        /// <summary>
        /// Adds tags to this index.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public uint Add(TagsCollectionBase tags)
        {
            int idx = 0;

            uint[] tagsArray = new uint[tags.Count];
            foreach (Tag tag in tags)
            {
                tagsArray[idx] = _tagsTable.Add(tag);
                idx++;
            }
            var osmTags = new OsmTags(tagsArray);

            if (osmTags != null)
            {
                return(_tagsCollectionTable.Add(osmTags));
            }
            throw new ArgumentNullException("tags", "Tags dictionary cannot be null or empty!");
        }
예제 #6
0
 /// <summary>
 /// Creates a new tags collection initialized with the given existing tags.
 /// </summary>
 /// <param name="tagsTable"></param>
 /// <param name="tags"></param>
 public TagsTableCollection(ObjectTable <Tag> tagsTable, IEnumerable <Tag> tags)
 {
     _tagsTable = tagsTable;
     _tags      = new List <uint>();
     foreach (Tag tag in tags)
     {
         _tags.Add(_tagsTable.Add(tag));
     }
 }
예제 #7
0
        /// <summary>
        /// Adds tags to this index.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public uint Add(TagsCollection tags)
        {
            var osmTags = new OsmTags(tags);

            if (osmTags != null)
            {
                return(_tagsTable.Add(osmTags));
            }
            throw new ArgumentNullException("tags", "Tags dictionary cannot be null or empty!");
        }
예제 #8
0
        public void GetObjectsOfOwnerAndType()
        {
            var physics = new MockPhysics();

            // Create 2 material
            var material1 = new MockMaterial();
            var material2 = new MockMaterial();

            // Add them to the object table with the physics parent
            ObjectTable.Add(5, material1, physics);
            ObjectTable.Add(6, material2, physics);

            // Ask for the 2 material owned by the physics
            var materialsOfPhysics = ObjectTable.GetObjectsOfOwnerAndType <MockMaterial>(physics);

            Assert.IsNotNull(materialsOfPhysics);
            Assert.AreEqual(2, materialsOfPhysics.Count());
        }
예제 #9
0
        public void Disposing_RemovedFromOwnershipDictionary()
        {
            var physics = new MockPhysics();

            var material1 = new MockMaterial();
            var material2 = new MockMaterial();

            ObjectTable.Add(5, material1, physics);
            ObjectTable.Add(6, material2, physics);

            // Make sure the objects are present to begin with
            Assert.IsTrue(ObjectTable.Ownership.ContainsKey(material1));
            Assert.IsTrue(ObjectTable.Ownership.ContainsKey(material2));

            material2.Dispose();

            Assert.IsTrue(ObjectTable.Ownership.ContainsKey(material1));
            Assert.IsFalse(ObjectTable.Ownership.ContainsKey(material2));
        }
예제 #10
0
        public void EnsureUnmanagedObjectIsOnlyWrappedOnce()
        {
            var obj0 = new MockPhysics();
            var obj1 = new MockPhysics();

            // Add the object at address '5'
            ObjectTable.Add(5, obj0, null);

            // We should not be able to add the same unmanaged address
            try
            {
                ObjectTable.Add(5, obj1, null);

                Assert.Fail("The unmanaged object/address has already been wrapped and added to the ObjectTable, it can not be added again, instead it should be retrieved");
            }
            catch (InvalidOperationException)
            {
            }
        }
예제 #11
0
        public void Disposing_RemovedFromOwnerTypeDictionary()
        {
            var physics = new MockPhysics();

            var material1 = new MockMaterial();
            var material2 = new MockMaterial();

            ObjectTable.Add(5, material1, physics);
            ObjectTable.Add(6, material2, physics);

            // Make sure the objects are present to begin with
            {
                var materialKey = new ObjectTableOwnershipType(physics, typeof(MockMaterial));

                Assert.IsTrue(ObjectTable.OwnerTypeLookup.ContainsKey(materialKey));

                var materialsOwnedByPhysics = ObjectTable.GetObjectsOfOwnerAndType <MockMaterial>(physics);

                Assert.IsNotNull(materialsOwnedByPhysics);
                Assert.AreEqual(2, materialsOwnedByPhysics.Count());
                Assert.AreEqual(material1, materialsOwnedByPhysics.ElementAt(0));
                Assert.AreEqual(material2, materialsOwnedByPhysics.ElementAt(1));
            }

            material1.Dispose();

            {
                var materialKey = new ObjectTableOwnershipType(physics, typeof(MockMaterial));

                Assert.IsTrue(ObjectTable.OwnerTypeLookup.ContainsKey(materialKey));

                var materialsOwnedByPhysics = ObjectTable.GetObjectsOfOwnerAndType <MockMaterial>(physics);

                Assert.IsNotNull(materialsOwnedByPhysics);
                Assert.AreEqual(1, materialsOwnedByPhysics.Count());
                Assert.AreEqual(material2, materialsOwnedByPhysics.ElementAt(0));
            }
        }
예제 #12
0
        public void TestStringTable_AddStrings()
        {
            ObjectTable <string> table = new ObjectTable <string>(false);

            table.Add("zero");
            table.Add("one");
            table.Add("two");
            table.Add("three");
            table.Add("four");
            table.Add("five");
            table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));


            table = new ObjectTable <string>(true);
            table.Add("zero");
            table.Add("one");
            table.Add("two");
            table.Add("three");
            table.Add("four");
            table.Add("five");
            table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));
        }
예제 #13
0
        public void TestStringTable_AddStrings()
        {
            ObjectTable<string> table = new ObjectTable<string>(false);
            uint zero = table.Add("zero");
            uint one = table.Add("one");
            uint two = table.Add("two");
            uint three = table.Add("three");
            uint four = table.Add("four");
            uint five = table.Add("five");
            uint six = table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            table = new ObjectTable<string>(true);
            zero = table.Add("zero");
            one = table.Add("one");
            two = table.Add("two");
            three = table.Add("three");
            four = table.Add("four");
            five = table.Add("five");
            six = table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));
        }
예제 #14
0
 public void NullKeyIsNotAllowed()
 {
     ObjectTable.Add(0, new MockMaterial(), null);
 }
예제 #15
0
        public void TestStringTable_AddStringsTwice()
        {
            ObjectTable<string> table = new ObjectTable<string>(false);
            table.Add("zero");
            table.Add("one");
            table.Add("two");
            table.Add("three");
            table.Add("four");
            table.Add("five");
            table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            Assert.AreEqual((uint)0, table.Add("zero"));
            Assert.AreEqual((uint)1, table.Add("one"));
            Assert.AreEqual((uint)2, table.Add("two"));
            Assert.AreEqual((uint)3, table.Add("three"));
            Assert.AreEqual((uint)4, table.Add("four"));
            Assert.AreEqual((uint)5, table.Add("five"));
            Assert.AreEqual((uint)6, table.Add("six"));

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            table = new ObjectTable<string>(true);
            table.Add("zero");
            table.Add("one");
            table.Add("two");
            table.Add("three");
            table.Add("four");
            table.Add("five");
            table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            Assert.AreEqual((uint)0, table.Add("zero"));
            Assert.AreEqual((uint)1, table.Add("one"));
            Assert.AreEqual((uint)2, table.Add("two"));
            Assert.AreEqual((uint)3, table.Add("three"));
            Assert.AreEqual((uint)4, table.Add("four"));
            Assert.AreEqual((uint)5, table.Add("five"));
            Assert.AreEqual((uint)6, table.Add("six"));

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));
        }
예제 #16
0
 /// <summary>
 /// Adds a new tag to this collection.
 /// </summary>
 /// <param name="tag"></param>
 public override void Add(Tag tag)
 {
     _tags.Add(_tagsTable.Add(tag));
 }
예제 #17
0
        /// <summary>
        /// Serializes all the tags in the given index. This serialization preserves the id's of each tag collection.
        /// </summary>
        /// <param name="stream">The target stream.</param>
        /// <param name="tagsIndex">The tags index to serialize.</param>
        public static void Serialize(Stream stream, ITagsCollectionIndex tagsIndex)
        {
            int begin = (int)stream.Position;

            // build a string index.
            ObjectTable<string> stringTable = new ObjectTable<string>(false);

            // convert tag collections to simpler objects.
            List<KeyValuePair<uint, List<KeyValuePair<uint, uint>>>> tagsIndexList = new List<KeyValuePair<uint,List<KeyValuePair<uint,uint>>>>();
            for (uint tagId = 0; tagId < tagsIndex.Max; tagId++)
            {
                TagsCollectionBase tagsCollection = tagsIndex.Get(tagId);
                if (tagsCollection != null)
                { // convert the tags collection to a list and add to the tag index.
                    List<KeyValuePair<uint, uint>> tagsList = new List<KeyValuePair<uint, uint>>();
                    foreach (Tag tag in tagsCollection)
                    {
                        uint keyId = stringTable.Add(tag.Key);
                        uint valueId = stringTable.Add(tag.Value);

                        tagsList.Add(new KeyValuePair<uint, uint>(
                            keyId, valueId));
                    }
                    tagsIndexList.Add(new KeyValuePair<uint, List<KeyValuePair<uint, uint>>>(tagId, tagsList));
                }
            }

            // do the serialization.
            TagIndexSerializer.Serialize(begin, stream, tagsIndexList, stringTable);

            // clear everything.
            tagsIndexList.Clear();
        }
예제 #18
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if ( Content == null )
            Content = new ContentManager( ScreenManager.Game.Services, "Content" );

              Game game = ScreenManager.Game;

              // initialize physics
              PhysicsSpace = new PhysicsSpace();
              PhysicsSpace.Gravity = new Vector2( 0f, -8f );

              // render targets
              GraphicsDevice device = ScreenManager.GraphicsDevice;
              PostProcessor.Initialize( device, ScreenManager.SpriteBatch, Content );
              PresentationParameters pars = device.PresentationParameters;
              basicSceneRenderTarget = new RenderTarget2D( device, pars.BackBufferWidth, pars.BackBufferHeight, 1, pars.BackBufferFormat );
              maskRenderTarget = new RenderTarget2D( device, pars.BackBufferWidth, pars.BackBufferHeight, 1, SurfaceFormat.Bgr32 );

              screenRectangle = new Rectangle( 0, 0, pars.BackBufferWidth, pars.BackBufferHeight );

              // this prevents the game from pausing after the player presses start to exit the loading screen
              firstFrame = true;

              // load fonts
              gameFont = Content.Load<SpriteFont>( "Fonts/gamefont" );
              Content.Load<SpriteFont>( "Fonts/HUDNameFont" );

              // load screens ahead of time
              scoreboardMenuScreen = new ScoreboardMenuScreen( ScreenManager, initSlotInfo );
              pauseScreen = new PauseMenuScreen( ScreenManager );

              // model explosion particles
              ParticleManager = new ParticleManager( game, Content );
              ParticleManager.Initialize();
              components.Add( ParticleManager );

              // other particles
              PixieParticleSystem = new PixieParticleSystem( game, Content );
              SparkParticleSystem = new SparkParticleSystem( game, Content );
              PinkPixieParticleSystem = new PinkPixieParticleSystem( game, Content );
              components.Add( PixieParticleSystem );
              components.Add( SparkParticleSystem );
              components.Add( PinkPixieParticleSystem );

              foreach ( DrawableGameComponent component in components )
            component.Initialize();

              // pre-load
              LaserBeam.Initialize();
              Content.Load<CustomAvatarAnimationData>( "Animations/Walk" );
              Content.Load<CustomAvatarAnimationData>( "Animations/Run" );
              backgroundTexture = Content.Load<Texture2D>( "Textures/gameBackground" );
              int left = -( backgroundTexture.Width - ScreenManager.GraphicsDevice.Viewport.Width ) / 2;
              Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
              if ( left > 0 )
            backgroundRect = new Rectangle( 0, 0, viewport.Width, viewport.Height );
              else
            backgroundRect = new Rectangle( left, 0, backgroundTexture.Width, viewport.Height );

              // init game stuff
              ObjectTable = new ObjectTable<GameObject>();

              // ready, go!
              ObjectTable.Add( new ReadyGo( this, new Vector2( viewport.Width / 2, viewport.Height / 2 ) ) );

              float fov = MathHelper.ToRadians( 30f );
              float aspect = ScreenManager.GraphicsDevice.DisplayMode.AspectRatio;
              Camera = new Camera( fov, aspect, 1f, 100f, new Vector3( 0f, 0f, cameraDistance ), Vector3.Zero );

              winnerSpring = new SpringInterpolater( 1, 10, SpringInterpolater.GetCriticalDamping( 10 ) );
              winnerSpring.SetSource( 1 );
              winnerSpring.SetDest( 0 );

              FloorBlock.Initialize( this );
              Powerup.Initialize( this );

              lastRowY = rowSpacing - Player.Size * 1.5f;

              InitSafeRectangle();
              InitStage();

              CountdownTime = 0f;
              CountdownEnd = 3f;

              lastCamY = Camera.Position.Y;
              SpawnRows(); // spawn additional rows before loading screen is over

              gameClock = new GameTimer( TimeSpan.FromMinutes( 2 ) );
              ObjectTable.Add( gameClock );

              ScreenManager.Game.ResetElapsedTime();
        }
 /// <summary>
 /// Adds key-value pair of strings.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public override void Add(string key, string value)
 {
     _tagsList.Add(new TagEncoded()
     {
         Key   = _stringTable.Add(key),
         Value = _stringTable.Add(value)
     });
 }
예제 #20
0
        public void TestStringTable_AddStringsTwice()
        {
            ObjectTable <string> table = new ObjectTable <string>(false);
            uint zero  = table.Add("zero");
            uint one   = table.Add("one");
            uint two   = table.Add("two");
            uint three = table.Add("three");
            uint four  = table.Add("four");
            uint five  = table.Add("five");
            uint six   = table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            Assert.AreEqual((uint)0, table.Add("zero"));
            Assert.AreEqual((uint)1, table.Add("one"));
            Assert.AreEqual((uint)2, table.Add("two"));
            Assert.AreEqual((uint)3, table.Add("three"));
            Assert.AreEqual((uint)4, table.Add("four"));
            Assert.AreEqual((uint)5, table.Add("five"));
            Assert.AreEqual((uint)6, table.Add("six"));

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            table = new ObjectTable <string>(true);
            zero  = table.Add("zero");
            one   = table.Add("one");
            two   = table.Add("two");
            three = table.Add("three");
            four  = table.Add("four");
            five  = table.Add("five");
            six   = table.Add("six");

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));

            Assert.AreEqual((uint)0, table.Add("zero"));
            Assert.AreEqual((uint)1, table.Add("one"));
            Assert.AreEqual((uint)2, table.Add("two"));
            Assert.AreEqual((uint)3, table.Add("three"));
            Assert.AreEqual((uint)4, table.Add("four"));
            Assert.AreEqual((uint)5, table.Add("five"));
            Assert.AreEqual((uint)6, table.Add("six"));

            Assert.AreEqual("zero", table.Get(0));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual("two", table.Get(2));
            Assert.AreEqual("three", table.Get(3));
            Assert.AreEqual("four", table.Get(4));
            Assert.AreEqual("five", table.Get(5));
            Assert.AreEqual("six", table.Get(6));
        }