38f1ddb...178a853: v0.8.9.1, removed content folder
This commit is contained in:
@@ -6,14 +6,33 @@ namespace Barotrauma
|
||||
{
|
||||
class EntityGrid
|
||||
{
|
||||
private List<MapEntity> allEntities;
|
||||
private List<MapEntity>[,] entities;
|
||||
|
||||
private Rectangle limits;
|
||||
private readonly Rectangle limits;
|
||||
|
||||
private float cellSize;
|
||||
private readonly float cellSize;
|
||||
|
||||
public readonly Submarine Submarine;
|
||||
|
||||
public Rectangle WorldRect
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Submarine == null)
|
||||
{
|
||||
return limits;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Rectangle(
|
||||
(int)(limits.X + Submarine.WorldPosition.X),
|
||||
(int)(limits.Y + Submarine.WorldPosition.Y),
|
||||
limits.Width, limits.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EntityGrid(Submarine submarine, float cellSize)
|
||||
{
|
||||
//make the grid slightly larger than the borders of the submarine,
|
||||
@@ -27,7 +46,19 @@ namespace Barotrauma
|
||||
submarine.Borders.Height + padding * 2);
|
||||
this.Submarine = submarine;
|
||||
this.cellSize = cellSize;
|
||||
InitializeGrid();
|
||||
}
|
||||
|
||||
public EntityGrid(Rectangle worldRect, float cellSize)
|
||||
{
|
||||
this.limits = worldRect;
|
||||
this.cellSize = cellSize;
|
||||
InitializeGrid();
|
||||
}
|
||||
|
||||
private void InitializeGrid()
|
||||
{
|
||||
allEntities = new List<MapEntity>();
|
||||
entities = new List<MapEntity>[(int)Math.Ceiling(limits.Width / cellSize), (int)Math.Ceiling(limits.Height / cellSize)];
|
||||
for (int x = 0; x < entities.GetLength(0); x++)
|
||||
{
|
||||
@@ -51,13 +82,14 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
for (int x = Math.Max(indices.X, 0); x <= Math.Min(indices.Width, entities.GetLength(0)-1); x++)
|
||||
for (int x = Math.Max(indices.X, 0); x <= Math.Min(indices.Width, entities.GetLength(0) - 1); x++)
|
||||
{
|
||||
for (int y = Math.Max(indices.Y,0); y <= Math.Min(indices.Height, entities.GetLength(1)-1); y++)
|
||||
for (int y = Math.Max(indices.Y, 0); y <= Math.Min(indices.Height, entities.GetLength(1) - 1); y++)
|
||||
{
|
||||
entities[x, y].Add(entity);
|
||||
}
|
||||
}
|
||||
allEntities.Add(entity);
|
||||
}
|
||||
|
||||
public void RemoveEntity(MapEntity entity)
|
||||
@@ -69,6 +101,7 @@ namespace Barotrauma
|
||||
if (entities[x, y].Contains(entity)) entities[x, y].Remove(entity);
|
||||
}
|
||||
}
|
||||
allEntities.Remove(entity);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
@@ -80,38 +113,24 @@ namespace Barotrauma
|
||||
entities[x, y].Clear();
|
||||
}
|
||||
}
|
||||
allEntities.Clear();
|
||||
}
|
||||
|
||||
public static List<MapEntity> GetEntities(List<EntityGrid> entityGrids, Vector2 position, bool useWorldCoordinates = true)
|
||||
public IEnumerable<MapEntity> GetAllEntities()
|
||||
{
|
||||
List<MapEntity> entities = new List<MapEntity>();
|
||||
foreach (EntityGrid entityGrid in entityGrids)
|
||||
{
|
||||
Vector2 transformedPosition = position;
|
||||
if (useWorldCoordinates)
|
||||
{
|
||||
transformedPosition -= entityGrid.Submarine.Position;
|
||||
}
|
||||
|
||||
entities.AddRange(entityGrid.GetEntities(transformedPosition));
|
||||
}
|
||||
|
||||
return entities;
|
||||
return allEntities;
|
||||
}
|
||||
|
||||
public List<MapEntity> GetEntities(Vector2 position)
|
||||
{
|
||||
if (!MathUtils.IsValid(position)) new List<MapEntity>();
|
||||
if (!MathUtils.IsValid(position)) return null;
|
||||
|
||||
if (Submarine != null) position -= Submarine.HiddenSubPosition;
|
||||
|
||||
Point indices = GetIndices(position);
|
||||
|
||||
if (indices.X < 0 || indices.Y < 0 || indices.X >= entities.GetLength(0) || indices.Y >= entities.GetLength(1))
|
||||
{
|
||||
return new List<MapEntity>();
|
||||
return null;
|
||||
}
|
||||
|
||||
return entities[indices.X, indices.Y];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user