Optimization: FindHull spatial hashing, itemcomponent sounds in a dictionary, got rid of Item.Updated, rendering fixes, disposing shadow vertex buffers
This commit is contained in:
@@ -14,6 +14,7 @@ namespace Barotrauma
|
||||
class Hull : MapEntity
|
||||
{
|
||||
public static List<Hull> hullList = new List<Hull>();
|
||||
private static EntityGrid entityGrid;
|
||||
|
||||
public static bool EditWater, EditFire;
|
||||
|
||||
@@ -165,9 +166,21 @@ namespace Barotrauma
|
||||
|
||||
Volume = 0.0f;
|
||||
|
||||
|
||||
InsertToList();
|
||||
}
|
||||
|
||||
public override void OnMapLoaded()
|
||||
{
|
||||
|
||||
if (entityGrid == null)
|
||||
{
|
||||
entityGrid = new EntityGrid(Submarine.Borders, 200.0f);
|
||||
}
|
||||
|
||||
entityGrid.InsertEntity(this);
|
||||
}
|
||||
|
||||
public override bool Contains(Vector2 position)
|
||||
{
|
||||
return (Submarine.RectContains(WorldRect, position) &&
|
||||
@@ -210,6 +223,8 @@ namespace Barotrauma
|
||||
|
||||
//renderer.Dispose();
|
||||
|
||||
entityGrid.RemoveEntity(this);
|
||||
|
||||
hullList.Remove(this);
|
||||
}
|
||||
|
||||
@@ -481,10 +496,30 @@ namespace Barotrauma
|
||||
//returns the water block which contains the point (or null if it isn't inside any)
|
||||
public static Hull FindHull(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
|
||||
{
|
||||
return FindHull(position, hullList, guess, useWorldCoordinates);
|
||||
if (entityGrid == null) return null;
|
||||
|
||||
if (guess != null)
|
||||
{
|
||||
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position)) return guess;
|
||||
}
|
||||
|
||||
var entities = entityGrid.GetEntities(useWorldCoordinates ? position-Submarine.Loaded.Position : position);
|
||||
|
||||
foreach (Hull hull in entities)
|
||||
{
|
||||
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position)) return hull;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Hull FindHull(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true)
|
||||
//returns the water block which contains the point (or null if it isn't inside any)
|
||||
public static Hull FindHullOld(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
|
||||
{
|
||||
return FindHullOld(position, hullList, guess, useWorldCoordinates);
|
||||
}
|
||||
|
||||
public static Hull FindHullOld(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true)
|
||||
{
|
||||
if (guess != null && hulls.Contains(guess))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user