Beispiel #1
0
			public bool MoveNext()
			{
				while ( true )
				{
					if ( m_Enumerator.MoveNext() )
					{
						object o;

						try
						{
							o = m_Enumerator.Current;
						}
						catch
						{
							continue;
						}

						if ( o is Mobile )
						{
							Mobile m = (Mobile) o;

							if ( !m.Deleted && m_Bounds.Contains( m.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
						else if ( o is Item )
						{
							Item item = (Item) o;

							if ( !item.Deleted && item.Parent == null && m_Bounds.Contains( item.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
						else if ( o is NetState )
						{
							Mobile m = ( (NetState) o ).Mobile;

							if ( m != null && !m.Deleted && m_Bounds.Contains( m.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
					}
					else
					{
						m_Current = null;

						m_Enumerator.Free();
						m_Enumerator = null;

						return false;
					}
				}
			}
Beispiel #2
0
			public bool MoveNext()
			{
				while ( true )
				{
					if ( m_Enumerator.MoveNext() )
					{
						object o;

						try
						{
							o = m_Enumerator.Current;
						}
						catch
						{
							continue;
						}

						if ( o is Mobile )
						{
							Mobile m = (Mobile) o;

							if ( m_Bounds.Contains( m.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
						else if ( o is Item )
						{
							Item item = (Item) o;

							if ( item.Parent == null && m_Bounds.Contains( item.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
					}
					else if ( m_Stage == 0 )
					{
						m_Enumerator.Free();
						m_Enumerator = SectorEnumerator.Instantiate( m_Map, m_Bounds, SectorEnumeratorType.Mobiles );

						m_Current = null;
						m_Stage = 1;
					}
					else
					{
						m_Enumerator.Free();
						m_Enumerator = null;

						m_Current = null;
						m_Stage = -1;

						return false;
					}
				}
			}
    public void IterateSingleTileInMiddle()
    {
        var e = new SectorEnumerator(new Rectangle(10, 10, 1, 1), false);

        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(new PartialSector(new SectorLoc(0, 0), false, new Rectangle(10, 10, 1, 1),
                                                    default));
        e.MoveNext().IsSameOrEqualTo(false);
    }
Beispiel #4
0
			public void Reset()
			{
				m_Current = null;

				if ( m_Enumerator != null )
					m_Enumerator.Free();

				m_Enumerator = SectorEnumerator.Instantiate( m_Map, m_Bounds, m_Type );//new SectorEnumerator( m_Map, m_Origin, m_Type, m_Range );
			}
    public void IterateOneFullSector()
    {
        var e = new SectorEnumerator(new Rectangle(64, 64, 64, 64), false);

        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(
            new PartialSector(new SectorLoc(1, 1), true, new Rectangle(0, 0, 64, 64), default));
        e.MoveNext().IsSameOrEqualTo(false);
    }
Beispiel #6
0
			public void Reset()
			{
				m_Stage = 0;

				m_Current = null;

				if ( m_Enumerator != null )
					m_Enumerator.Free();

				m_Enumerator = SectorEnumerator.Instantiate( m_Map, m_Bounds, SectorEnumeratorType.Items );
			}
Beispiel #7
0
			public void Free()
			{
				if ( m_Map == null )
					return;

				m_InstancePool.Enqueue( this );

				m_Map = null;

				if ( m_Enumerator != null )
				{
					m_Enumerator.Free();
					m_Enumerator = null;
				}

				if ( m_Enumerable != null )
					m_Enumerable.Free();
			}
    public void IterateFourTilesSpanningFourSectors()
    {
        var e = new SectorEnumerator(new Rectangle(63, 63, 2, 2), false);

        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(new PartialSector(new SectorLoc(0, 0), false, new Rectangle(63, 63, 1, 1),
                                                    default));
        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(
            new PartialSector(new SectorLoc(1, 0), false, new Rectangle(0, 63, 1, 1), default));
        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(new PartialSector(new SectorLoc(0, 1), false, new Rectangle(63, 63, 1, 1),
                                                    default));
        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(new PartialSector(new SectorLoc(1, 1), false, new Rectangle(63, 63, 1, 1),
                                                    default));
        e.MoveNext().IsSameOrEqualTo(false);
    }
Beispiel #9
0
			public static SectorEnumerator Instantiate( Map map, Rectangle2D bounds, SectorEnumeratorType type )
			{
				SectorEnumerator e;

				if ( m_InstancePool.Count > 0 )
				{
					e = m_InstancePool.Dequeue();

					e.m_Map = map;
					e.m_Bounds = bounds;
					e.m_Type = type;

					e.Reset();
				}
				else
				{
					e = new SectorEnumerator( map, bounds, type );
				}

				return e;
			}
    public void IterateThreeByThreeSectorsWithOneTileBorder()
    {
        var e = new SectorEnumerator(new Rectangle(1, 1, 64 * 3 - 2, 64 * 3 - 2), false);

        // First Row of 3x3
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(0, 0));
        e.Current.TileRectangle.Should().Be(new Rectangle(1, 1, 63, 63));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(1, 0));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 1, 64, 63));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(2, 0));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 1, 63, 63));

        // Second Row of 3x3
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(0, 1));
        e.Current.TileRectangle.Should().Be(new Rectangle(1, 0, 63, 64));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(1, 1));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 0, 64, 64));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(2, 1));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 0, 63, 64));

        // Third Row of 3x3
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(0, 2));
        e.Current.TileRectangle.Should().Be(new Rectangle(1, 0, 63, 63));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(1, 2));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 0, 64, 63));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(2, 2));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 0, 63, 63));

        e.MoveNext().Should().BeFalse();
    }
Beispiel #11
0
            public void Free()
            {
                if ( m_Map == null )
                    return;

                m_InstancePool.Enqueue( this );

                m_Map = null;

                if ( m_Enumerator != null )
                {
                    m_Enumerator.Free();
                    m_Enumerator = null;
                }

                if ( m_Enumerable != null )
                    m_Enumerable.Free();
            }
Beispiel #12
0
            public static SectorEnumerator Instantiate( Map map, Rectangle2D bounds, SectorEnumeratorType type )
            {
                SectorEnumerator e;

                if ( m_InstancePool.Count > 0 )
                {
                    e = (SectorEnumerator)m_InstancePool.Dequeue();

                    e.m_Map = map;
                    e.m_Bounds = bounds;
                    e.m_Type = type;

                    e.Reset();
                }
                else
                {
                    e = new SectorEnumerator( map, bounds, type );
                }

                return e;
            }
Beispiel #13
0
            public void Reset()
            {
                m_Stage = 0;

                m_Current = null;

                if ( m_Enumerator != null )
                    m_Enumerator.Free();

                m_Enumerator = SectorEnumerator.Instantiate( m_Map, m_Bounds, SectorEnumeratorType.Items );
            }
Beispiel #14
0
            public bool MoveNext()
            {
                while ( true )
                {
                    if ( m_Enumerator.MoveNext() )
                    {
                        object o = m_Enumerator.Current;

                        if ( o is Mobile )
                        {
                            Mobile m = (Mobile)o;

                            if ( m_Bounds.Contains( m.Location ) )
                            {
                                m_Current = o;
                                return true;
                            }
                        }
                        else if ( o is Item )
                        {
                            Item item = (Item)o;

                            if ( item.Parent == null && m_Bounds.Contains( item.Location ) )
                            {
                                m_Current = o;
                                return true;
                            }
                        }
                    }
                    else if ( m_Stage == 0 )
                    {
                        m_Enumerator.Free();
                        m_Enumerator = SectorEnumerator.Instantiate( m_Map, m_Bounds, SectorEnumeratorType.Mobiles );

                        m_Current = null;
                        m_Stage = 1;
                    }
                    else
                    {
                        m_Enumerator.Free();
                        m_Enumerator = null;

                        m_Current = null;
                        m_Stage = -1;

                        return false;
                    }
                }
            }
Beispiel #15
0
            public bool MoveNext()
            {
                while ( true )
                {
                    if ( m_Enumerator.MoveNext() )
                    {
                        object o = m_Enumerator.Current;

                        if ( o is Mobile )
                        {
                            Mobile m = (Mobile)o;

                            if ( !m.Deleted && m_Bounds.Contains( m.Location ) )
                            {
                                m_Current = o;
                                return true;
                            }
                        }
                        else if ( o is Item )
                        {
                            Item item = (Item)o;

                            if ( !item.Deleted && item.Parent == null && m_Bounds.Contains( item.Location ) )
                            {
                                m_Current = o;
                                return true;
                            }
                        }
                        else if ( o is NetState )
                        {
                            Mobile m = ((NetState)o).Mobile;

                            if ( m != null && !m.Deleted && m_Bounds.Contains( m.Location ) )
                            {
                                m_Current = o;
                                return true;
                            }
                        }
                    }
                    else
                    {
                        m_Current = null;

                        m_Enumerator.Free();
                        m_Enumerator = null;

                        return false;
                    }
                }
            }
Beispiel #16
0
            public void Reset()
            {
                m_Current = null;

                if ( m_Enumerator != null )
                    m_Enumerator.Free();

                m_Enumerator = SectorEnumerator.Instantiate( m_Map, m_Bounds, m_Type );//new SectorEnumerator( m_Map, m_Origin, m_Type, m_Range );
            }
    public void IterateEmpty()
    {
        SectorEnumerator e = default;

        e.MoveNext().IsSameOrEqualTo(false);
    }