public void SpatialMapMove() { var mySpatialMap = new SpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); mySpatialMap.Add(myId1, (1, 2)); mySpatialMap.Add(myId2, (2, 3)); bool retVal = mySpatialMap.Move(myId1, (5, 6)); Assert.AreEqual(true, retVal); Assert.AreEqual(new Coord(5, 6), mySpatialMap.GetPosition(myId1)); retVal = mySpatialMap.Contains((5, 6)); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Contains((1, 2)); Assert.AreEqual(false, retVal); retVal = mySpatialMap.Contains((2, 3)); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Move(myId2, (5, 6)); Assert.AreEqual(false, retVal); Assert.AreEqual(true, mySpatialMap.Contains((2, 3))); Assert.AreEqual(true, mySpatialMap.Contains((5, 6))); }
public void SpatialMapMove() { var mySpatialMap = new SpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); mySpatialMap.Add(myId1, (1, 2)); mySpatialMap.Add(myId2, (2, 3)); mySpatialMap.Move(myId1, (5, 6)); Assert.Equal(new Point(5, 6), mySpatialMap.GetPositionOf(myId1)); var retVal = mySpatialMap.Contains((5, 6)); Assert.True(retVal); retVal = mySpatialMap.Contains((1, 2)); Assert.False(retVal); retVal = mySpatialMap.Contains((2, 3)); Assert.True(retVal); Assert.Throws <ArgumentException>(() => mySpatialMap.Move(myId2, (5, 6))); Assert.True(mySpatialMap.Contains((2, 3))); Assert.True(mySpatialMap.Contains((5, 6))); }
public void SpatialMapCreate() { var mySpatialMap = new SpatialMap <MyIDImpl>(); Assert.AreEqual(0, mySpatialMap.Count); bool retVal = mySpatialMap.Remove(new MyIDImpl(0)); Assert.AreEqual(false, retVal); retVal = false; foreach (var item in mySpatialMap.Remove((1, 2))) { retVal = true; } Assert.AreEqual(false, retVal); retVal = false; foreach (var item in mySpatialMap.Items) { retVal = true; } Assert.AreEqual(false, retVal); retVal = mySpatialMap.Move(new MyIDImpl(0), (5, 6)); Assert.AreEqual(false, retVal); retVal = false; foreach (var item in mySpatialMap.Move((1, 2), (5, 6))) { retVal = true; } Assert.AreEqual(false, retVal); }
public void SpatialMapAdd() { var mySpatialMap = new SpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); mySpatialMap.Add(myId1, (1, 2)); Assert.Equal(1, mySpatialMap.Count); var retVal = mySpatialMap.Contains((1, 2)); Assert.True(retVal); retVal = mySpatialMap.Contains(myId1); Assert.True(retVal); retVal = mySpatialMap.Contains((2, 3)); Assert.False(retVal); retVal = mySpatialMap.Contains(myId2); Assert.False(retVal); Assert.Single(mySpatialMap.GetItemsAt((1, 2))); Assert.Empty(mySpatialMap.GetItemsAt((2, 3))); Assert.Throws <ArgumentException>(() => mySpatialMap.Add(myId2, (1, 2))); Assert.Single(mySpatialMap.GetItemsAt((1, 2))); }
public void SpatialMapRemove() { var mySpatialMap = new SpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); var myId3 = new MyIDImpl(2); mySpatialMap.Add(myId1, (1, 2)); mySpatialMap.Add(myId2, (2, 3)); mySpatialMap.Add(myId3, (3, 4)); mySpatialMap.Remove(myId1); var retVal = mySpatialMap.Contains(myId1); Assert.False(retVal); retVal = mySpatialMap.Contains((1, 2)); Assert.False(retVal); Assert.Single(mySpatialMap.Remove((2, 3))); Assert.False(mySpatialMap.Contains((2, 3))); Assert.False(mySpatialMap.Contains(myId2)); Assert.Throws <ArgumentException>(() => mySpatialMap.Remove(myId1)); Assert.Empty(mySpatialMap.Remove((5, 6))); }
public void SpatialMapCreate() { var mySpatialMap = new SpatialMap <MyIDImpl>(); Assert.Equal(0, mySpatialMap.Count); Assert.Throws <ArgumentException>(() => mySpatialMap.Remove(new MyIDImpl(0))); Assert.Empty(mySpatialMap.Remove((1, 2))); Assert.Empty(mySpatialMap.Items); }
public void ManualPrintSpatialMap() { SpatialMap <MyIDImpl> sm = new SpatialMap <MyIDImpl>(); sm.Add(new MyIDImpl(1), 1, 2); sm.Add(new MyIDImpl(2), 1, 3); sm.Add(new MyIDImpl(3), 4, 5); Console.WriteLine(sm); }
public GameMap(int width, int height) { TerrainTiles = new Terrain[width, height]; Width = width; Height = height; MapActors = new SpatialMap <GameEntity>(); Rooms = new List <Room>(); }
public void SpatialMapAdd() { var mySpatialMap = new SpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); mySpatialMap.Add(myId1, (1, 2)); Assert.AreEqual(1, mySpatialMap.Count); bool retVal = mySpatialMap.Contains((1, 2)); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Contains(myId1); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Contains((2, 3)); Assert.AreEqual(false, retVal); retVal = mySpatialMap.Contains(myId2); Assert.AreEqual(false, retVal); int count = 0; foreach (var item in mySpatialMap.GetItems((1, 2))) { count++; } Assert.AreEqual(1, count); count = 0; foreach (var item in mySpatialMap.GetItems((2, 3))) { count++; } Assert.AreEqual(0, count); retVal = mySpatialMap.Add(myId2, (1, 2)); Assert.AreEqual(false, retVal); count = 0; foreach (var item in mySpatialMap.GetItems((1, 2))) { count++; } Assert.AreEqual(1, count); }
public void InsertAndGet() { var map = new SpatialMap <int>(1); var entry = map.Add(1, new AABB(0, 0, 1, 1)); SequenceEqual(new int[] { 1 }, map.Region(new AABB(-1, -1, 2, 2))); map.Update(ref entry, new AABB(3, 3, 4, 4)); SequenceEqual(new int[] {}, map.Region(new AABB(-1, -1, 2, 2))); SequenceEqual(new int[] { 1 }, map.Region(new AABB(2, 2, 3.5f, 3.5f))); map.Remove(entry); SequenceEqual(new int[] {}, map.Region(new AABB(-1, -1, 5, 5))); }
public void Cells() { var map = new SpatialMap <int>(10); Assert.Empty(map.Cells(new AABB(0, 0, 1, 1))); // Realize the cells first so all the cell "seeding" occurs. var newCells = map.Cells(new AABB(0, 0, 1, 1), true).ToList(); var existingCells = map.Cells(new AABB(0, 0, 1, 1)).ToList(); SequenceEqual(newCells, existingCells); Assert.Equal(4, new SpatialMap <int>(10).Cells(new AABB(-1, -1, 2, 2), true).Count()); Assert.Equal(4, new SpatialMap <int>(1).Cells(new AABB(-0.5f, 0.5f, 3, 1), true).Count()); }
public void NegativeUpdate() { var map = new SpatialMap <int>(1); var entry = map.Add(1, new AABB(0.25f, 0.25f, 0.75f, 0.75f)); var otherEntry = map.Add(2, new AABB(0.25f, 0.25f, 0.75f, 0.75f)); SequenceEqual(new int[] { 1, 2 }, map.Region(new AABB(0, 0, 1, 1))); map.Update(ref entry, new AABB(-0.75f, 0.25f, -0.25f, 0.75f)); SequenceEqual(new int[] { 2 }, map.Region(new AABB(0, 0, 1, 1))); SequenceEqual(new int[] { 1 }, map.Region(new AABB(-1, 0, 0, 1))); map.Update(ref entry, new AABB(-9.5f, 1f, -8.5f, 2f)); SequenceEqual(new int[] { 1 }, map.Region(new AABB(-10, -8, 0, 3))); }
protected override void LoadContent() { RenderHelper.Init(GraphicsDevice); _camera = new Camera(); _grid = new GridOverlay(); _spotMap = new SpatialMap <WireSpot>(80); _grid.Size = new Vector2(_spotMap.CellSize); _wireRenderer = new WireRenderer(); WireGenerator.DefaultSpotDensity = 10; //_wire = WireGenerator.MakeCircle(new Vector2(350, 250), 200); _wire = WireGenerator.MakeRandomPath(new Vector2(50, 200), 0, 500, 50, 0, .5f); _player = new Player(_wire); base.LoadContent(); }
public void SpatialMapMoveEvent() { var mySpatialMap = new SpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); var myId3 = new MyIDImpl(2); mySpatialMap.Add(myId1, (1, 2)); mySpatialMap.Add(myId2, (2, 3)); mySpatialMap.Add(myId3, (3, 4)); mySpatialMap.ItemMoved += onItemMoved; oldPos = (1, 2); newPos = (5, 6); mySpatialMap.Move(myId1, (5, 6)); mySpatialMap.ItemMoved -= onItemMoved; }
public void SpatialMapRemove() { var mySpatialMap = new SpatialMap <MyIDImpl>(); var myId1 = new MyIDImpl(0); var myId2 = new MyIDImpl(1); var myId3 = new MyIDImpl(2); mySpatialMap.Add(myId1, (1, 2)); mySpatialMap.Add(myId2, (2, 3)); mySpatialMap.Add(myId3, (3, 4)); bool retVal = mySpatialMap.Remove(myId1); Assert.AreEqual(true, retVal); retVal = mySpatialMap.Contains(myId1); Assert.AreEqual(false, retVal); retVal = mySpatialMap.Contains((1, 2)); Assert.AreEqual(false, retVal); int count = 0; foreach (var i in mySpatialMap.Remove((2, 3))) { count++; } Assert.AreEqual(1, count); Assert.AreEqual(false, mySpatialMap.Contains((2, 3))); Assert.AreEqual(false, mySpatialMap.Contains(myId2)); retVal = mySpatialMap.Remove(myId1); Assert.AreEqual(false, retVal); count = 0; foreach (var i in mySpatialMap.Remove((5, 6))) { count++; } Assert.AreEqual(0, count); }
protected override void OnUpdate() { var spatialGrid = SpatialMap.Instance.spatialGrid; spatialGrid.Clear(); var steeringDataCaptured = steeringData.data; var boidQuery = GetEntityQuery( ComponentType.ReadOnly(typeof(BoidTag)), ComponentType.ReadOnly(typeof(Translation)), ComponentType.ReadOnly(typeof(PhysicsVelocity)) ); int valuesCount = boidQuery.CalculateEntityCount() * 27; // each value gets written in 27 cells if (spatialGrid.Capacity < valuesCount) { spatialGrid.Capacity = valuesCount * 2; // Debug.Log($"Resizing map to {spatialGrid.Capacity}"); } var spatialGridWriter = spatialGrid.AsParallelWriter(); Entities.ForEach((in BoidTag tag, in Translation translation, in Entity entity, in PhysicsVelocity velocity) => { var key = SpatialMap.GetSpatialHash(translation.Value, steeringDataCaptured.senseRange); // Debug.Log($"Hashmap Write {entity} to {key} and around"); for (var x = -1; x <= 1; x++) { for (var y = -1; y <= 1; y++) { for (var z = -1; z <= 1; z++) { var writeKey = key + new int3(x, y, z); var v = new SpatialMapSingleValue() { Translation = translation.Value, Velocity = velocity.Linear }; spatialGridWriter.Add(writeKey, v); } } } }).ScheduleParallel();