dmgn
This commit is contained in:
@@ -17,10 +17,10 @@ namespace Barotrauma
|
||||
this.limits = limits;
|
||||
this.cellSize = cellSize;
|
||||
|
||||
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++)
|
||||
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++)
|
||||
{
|
||||
for (int y=0; y<entities.GetLength(1); y++)
|
||||
for (int y = 0; y < entities.GetLength(1); y++)
|
||||
{
|
||||
entities[x, y] = new List<MapEntity>();
|
||||
}
|
||||
@@ -32,29 +32,29 @@ namespace Barotrauma
|
||||
Rectangle rect = entity.Rect;
|
||||
//if (Submarine.Loaded != null) rect.Offset(-Submarine.HiddenSubPosition);
|
||||
Rectangle indices = GetIndices(rect);
|
||||
if (indices.X<0 || indices.Width>=entities.GetLength(0) ||
|
||||
indices.Y<0 || indices.Height>=entities.GetLength(1))
|
||||
if (indices.X < 0 || indices.Width >= entities.GetLength(0) ||
|
||||
indices.Y < 0 || indices.Height >= entities.GetLength(1))
|
||||
{
|
||||
DebugConsole.ThrowError("Error in EntityGrid.InsertEntity: "+entity+" is outside the grid");
|
||||
DebugConsole.ThrowError("Error in EntityGrid.InsertEntity: " + entity + " is outside the grid");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int x=indices.X; x<=indices.Width; x++)
|
||||
for (int x = indices.X; x <= indices.Width; x++)
|
||||
{
|
||||
for (int y = indices.Y; y<=indices.Height; y++)
|
||||
for (int y = indices.Y; y <= indices.Height; y++)
|
||||
{
|
||||
entities[x, y].Add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RemoveEntity(MapEntity entity)
|
||||
{
|
||||
for (int x = 0; x < entities.GetLength(0); x++)
|
||||
{
|
||||
for (int y = 0; y < entities.GetLength(1); y++)
|
||||
{
|
||||
if (entities[x,y].Contains(entity)) entities[x, y].Remove(entity);
|
||||
if (entities[x, y].Contains(entity)) entities[x, y].Remove(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,14 +76,13 @@ namespace Barotrauma
|
||||
|
||||
if (Submarine.Loaded != null) position -= Submarine.HiddenSubPosition;
|
||||
|
||||
if (position.X < limits.X || position.Y > limits.Y ||
|
||||
position.X > limits.Right || position.Y < limits.Y - limits.Height)
|
||||
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>();
|
||||
}
|
||||
|
||||
Point indices = GetIndices(position);
|
||||
|
||||
return entities[indices.X, indices.Y];
|
||||
}
|
||||
|
||||
@@ -91,10 +90,10 @@ namespace Barotrauma
|
||||
{
|
||||
Rectangle indices = Rectangle.Empty;
|
||||
indices.X = (int)Math.Floor((rect.X - limits.X) / cellSize);
|
||||
indices.Y = (int)Math.Floor((limits.Y - rect.Y)/cellSize);
|
||||
indices.Y = (int)Math.Floor((limits.Y - rect.Y) / cellSize);
|
||||
|
||||
indices.Width = (int)Math.Floor((rect.Right - limits.X) / cellSize);
|
||||
indices.Height = (int)Math.Floor((limits.Y - (rect.Y-rect.Height)) / cellSize);
|
||||
indices.Height = (int)Math.Floor((limits.Y - (rect.Y - rect.Height)) / cellSize);
|
||||
|
||||
return indices;
|
||||
}
|
||||
@@ -103,7 +102,7 @@ namespace Barotrauma
|
||||
{
|
||||
return new Point(
|
||||
(int)Math.Floor((position.X - limits.X) / cellSize),
|
||||
(int)Math.Floor((limits.Y - position.Y) / cellSize));
|
||||
(int)Math.Floor((limits.Y - position.Y) / cellSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user