Beispiel #1
0
        [TestCase(-1, -1, -1, -1)] // out of bounds
        public void Insert_Overlap_CorrectCells(int minX, int minY, int maxX, int maxY)
        {
            var bin = new Bin2D <object>(9, 9, 1, 1);
            var val = new object();

            var rect = GetRectInsideCells(minX, minY, maxX, maxY, 1, 1);

            bin.Insert(val, rect);

            for (var x = 0; x < bin.Width; x++)
            {
                for (var y = 0; y < bin.Height; y++)
                {
                    if (x >= minX && y >= minY &&
                        x <= maxX && y <= maxY)
                    {
                        Assert.IsNotNull(bin[x, y]);
                        Assert.IsTrue(bin[x, y].Contains(val));
                    }
                    else
                    {
                        Assert.IsNull(bin[x, y]);
                    }
                }
            }
        }
Beispiel #2
0
        [TestCase(-1, -1, -1, -1)] // out of bounds
        public void Insert_WithOffsetOrigin_CorrectCells(int minX, int minY, int maxX, int maxY)
        {
            var origin = new Vector2(-4.5f, -4.5f);

            var bin = new Bin2D <object>(9, 9, 1, 1, origin);
            var val = new object();

            var rect = GetRectInsideCells(minX, minY, maxX, maxY, 1, 1);

            rect.x += origin.x;
            rect.y += origin.y;

            bin.Insert(val, rect);

            for (var x = 0; x < bin.Width; x++)
            {
                for (var y = 0; y < bin.Height; y++)
                {
                    if (x >= minX && y >= minY &&
                        x <= maxX && y <= maxY)
                    {
                        Assert.IsNotNull(bin[x, y]);
                        Assert.IsTrue(bin[x, y].Contains(val));
                    }
                    else
                    {
                        Assert.IsNull(bin[x, y]);
                    }
                }
            }
        }
Beispiel #3
0
        public void Constructor_CorrectSize()
        {
            var bin = new Bin2D <string>(9, 18, 1, 2);

            Assert.AreEqual(9, bin.Width);
            Assert.AreEqual(18, bin.Height);
            Assert.AreEqual(1, bin.CellWidth, 0.001f);
            Assert.AreEqual(2, bin.CellHeight, 0.001f);
        }
Beispiel #4
0
        public void Retrieve_Empty_NoResults()
        {
            var bin     = new Bin2D <object>(9, 9, 1, 1);
            var rect    = GetRectInsideCells(-1, -1, bin.Width, bin.Height, bin.CellWidth, bin.CellHeight);
            var results = new HashSet <object>();

            bin.Retrieve(rect, results);

            Assert.IsEmpty(results);
        }
Beispiel #5
0
        public void Clear_AllCellsEmpty()
        {
            var bin        = new Bin2D <object>(9, 9, 1, 1);
            var results    = new HashSet <object>();
            var fullBounds = GetRectInsideCells(-1, -1, bin.Width, bin.Height, bin.CellWidth, bin.CellHeight);

            bin.Retrieve(fullBounds, results);

            Assert.AreEqual(0, results.Count);
        }
        // private int ownerIdIndex;
        // private int positionIndex;

        protected EntitasGameContext(Context <TEntity> context, Type[] componentTypes, Bin2D <IGameEntity> bin)
        {
            this.bin                         = bin;
            entitasContext                   = context;
            indexLookUp                      = new GameComponentIndexLookUp <TEntity>(componentTypes);
            context.OnEntityCreated         += ContextOnOnEntityCreated;
            context.OnEntityWillBeDestroyed += ContextOnOnEntityDestroyed;
            onOnComponentAddedCache          = OnOnComponentAdded;
            onOnComponentRemovedCache        = OnOnComponentRemoved;
            onOnComponentReplacedCache       = OnOnComponentReplaced;
        }
Beispiel #7
0
        public void Retrieve_CorrectResults(int minX, int minY, int maxX, int maxY)
        {
            var bin     = new Bin2D <object>(9, 9, 1, 1);
            var results = new HashSet <object>();
            var val     = new object();
            var bounds  = GetRectInsideCells(minX, minY, maxX, maxY, bin.CellWidth, bin.CellHeight);

            bin.Insert(val, bounds);
            bin.Retrieve(bounds, results);

            Assert.True(results.Contains(val));
        }
Beispiel #8
0
        public void Remove_RemovedFromCells()
        {
            var bin     = new Bin2D <object>(9, 9, 1, 1);
            var results = new HashSet <object>();
            var val     = new object();
            var bounds  = GetRectInsideCells(3, 6, 7, 8, bin.CellWidth, bin.CellHeight);

            bin.Insert(val, bounds);
            bin.Remove(val, bounds);
            bin.Retrieve(bounds, results);

            Assert.False(results.Contains(val));
        }
Beispiel #9
0
        public void Insert_OutOfBounds_NotAdded(int cellX, int cellY)
        {
            var bin = new Bin2D <object>(9, 9, 1, 1);
            var val = new object();

            bin.Insert(val, GetRectInsideCell(cellX, cellY, 1, 1));

            for (var x = 0; x < bin.Width; x++)
            {
                for (var y = 0; y < bin.Height; y++)
                {
                    Assert.IsNull(bin[x, y]);
                }
            }
        }
Beispiel #10
0
        public void Insert_InsideCell_CorrectCell(int expectedX, int expectedY)
        {
            var bin = new Bin2D <object>(9, 9, 1, 1);
            var val = new object();

            bin.Insert(val, GetRectInsideCell(expectedX, expectedY, 1, 1));

            for (var x = 0; x < bin.Width; x++)
            {
                for (var y = 0; y < bin.Height; y++)
                {
                    if (x == expectedX && y == expectedY)
                    {
                        continue;
                    }

                    Assert.IsNull(bin[x, y]);
                }
            }

            Assert.IsNotNull(bin[expectedX, expectedY]);
            Assert.IsTrue(bin[expectedX, expectedY].Contains(val));
        }
Beispiel #11
0
        protected EntitasGameContext(Context <TEntity> context, Type[] componentTypes, Bin2D <IGameEntity> bin)
        {
            _bin            = bin;
            _context        = context;
            _indexLookUp    = new ComponentIndexLookUp <TEntity>(componentTypes);
            _entityKeyIndex = _indexLookUp.GetComponentIndex <EntityKeyComponent>();
            _ownerIdIndex   = _indexLookUp.GetComponentIndex <OwnerIdComponent>();
            _positionIndex  = _indexLookUp.GetComponentIndex <PositionComponent>();
            _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <PositionComponent>());
            _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <EntityKeyComponent>());
            _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <OwnerIdComponent>());
            _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagCompensationComponent>());
            _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagDestroyComponent>());

            _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagSelfComponent>());
            _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagSyncSelfComponent>());
            _needChangeCacheIndexs.Add(_indexLookUp.GetComponentIndex <FlagSyncNonSelfComponent>());

            _context.OnEntityCreated         += ContextOnOnEntityCreated;
            _context.OnEntityWillBeDestroyed += ContextOnOnEntityDestroyed;
            _onOnComponentAddedCache          = OnOnComponentAdded;
            _onOnComponentRemovedCache        = OnOnComponentRemoved;
            _onOnComponentReplacedCache       = OnOnComponentReplaced;
        }
 public WeaponGameContext(WeaponContext context, Bin2D <IGameEntity> bin) : base(context, WeaponComponentsLookup.componentTypes, bin)
 {
 }
Beispiel #13
0
 public SoundGameContext(SoundContext context, Bin2D <IGameEntity> bin) : base(context, SoundComponentsLookup.componentTypes, bin)
 {
     _context = context;
 }
 public FreeMoveGameContext(FreeMoveContext context, Bin2D <IGameEntity> bin) : base(context, FreeMoveComponentsLookup.componentTypes, bin)
 {
     _context = context;
 }
 public BulletGameContext(BulletContext context, Bin2D <IGameEntity> bin) : base(context, BulletComponentsLookup.componentTypes, bin)
 {
 }
 public ThrowingGameContext(ThrowingContext context, Bin2D <IGameEntity> bin) : base(context, ThrowingComponentsLookup.componentTypes, bin)
 {
 }
Beispiel #17
0
 public VehicleGameContext(VehicleContext context, Bin2D <IGameEntity> bin) : base(context, VehicleComponentsLookup.componentTypes, bin)
 {
     _context = context;
 }
Beispiel #18
0
 public ClientEffectGameContext(ClientEffectContext context, Bin2D <IGameEntity> bin) : base(context, ClientEffectComponentsLookup.componentTypes, bin)
 {
 }
Beispiel #19
0
 public PlayerGameContext(PlayerContext context, Bin2D <IGameEntity> bin) : base(context, PlayerComponentsLookup.componentTypes, bin)
 {
 }
 public SceneObjectGameContext(SceneObjectContext context, Bin2D <IGameEntity> bin) : base(context, SceneObjectComponentsLookup.componentTypes, bin)
 {
     _context = context;
 }
Beispiel #21
0
 public MapObjectGameContext(Context <MapObjectEntity> context, Bin2D <IGameEntity> bin) : base(context, MapObjectComponentsLookup.componentTypes, bin)
 {
 }