Refactor; Optimize simulation
This commit is contained in:
parent
8581cf6fb8
commit
0ef5652cea
16 changed files with 508 additions and 651 deletions
|
|
@ -5,45 +5,22 @@ using Godot;
|
|||
public class Sector
|
||||
{
|
||||
public Vector3I Coordinates;
|
||||
public Vector3Dec GlobalStartCoordinates;
|
||||
public Vector3Dec GlobalCenterCoordinates;
|
||||
public Vector3Dec GlobalEndCoordinates;
|
||||
public Vector3 Size;
|
||||
|
||||
public FastUniqueList<GameObject> GameObjects = new();
|
||||
|
||||
public Sector(Vector3I coordinates, Vector3I offset, Vector3 size)
|
||||
public Sector(Vector3I coordinates)
|
||||
{
|
||||
Coordinates = coordinates;
|
||||
|
||||
Vector3Dec sizeDec = Vector3Dec.FromVector3(size);
|
||||
|
||||
decimal startX = (coordinates.X - offset.X) * sizeDec.X;
|
||||
decimal startY = (coordinates.Y - offset.Y) * sizeDec.Y;
|
||||
decimal startZ = (coordinates.Z - offset.Z) * sizeDec.Z;
|
||||
|
||||
GlobalStartCoordinates = new(startX, startY, startZ);
|
||||
|
||||
GlobalCenterCoordinates = new(
|
||||
startX + sizeDec.X / 2,
|
||||
startY + sizeDec.Y / 2,
|
||||
startZ + sizeDec.Z / 2
|
||||
);
|
||||
|
||||
GlobalEndCoordinates = new(
|
||||
startX + sizeDec.X,
|
||||
startY + sizeDec.Y,
|
||||
startZ + sizeDec.Z
|
||||
);
|
||||
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public void Simulate(double delta)
|
||||
public void Simulate(double delta, HashSet<GameObject> ignoreObjects = null)
|
||||
{
|
||||
GameObjects.ForEach(gameObject =>
|
||||
{
|
||||
gameObject.Simulate(delta);
|
||||
if (ignoreObjects == null || !ignoreObjects.Contains(gameObject))
|
||||
{
|
||||
gameObject.Simulate(delta);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -55,11 +32,6 @@ public class Sector
|
|||
});
|
||||
}
|
||||
|
||||
public bool IsObjectInSector(GameObject gameObject)
|
||||
{
|
||||
return Helpers.IsInsideGlobalArea(GlobalStartCoordinates, GlobalEndCoordinates, gameObject.GlobalCoordinates);
|
||||
}
|
||||
|
||||
public void AssignObject(GameObject gameObject)
|
||||
{
|
||||
QueueManager.SectorReassignQueue.Enqueue((this, gameObject));
|
||||
|
|
@ -83,6 +55,20 @@ public class Sector
|
|||
return null;
|
||||
}
|
||||
|
||||
public bool RemoveObjectById(Guid id)
|
||||
{
|
||||
foreach (GameObject gameObject in GameObjects)
|
||||
{
|
||||
if (gameObject.UUID.Equals(id))
|
||||
{
|
||||
GameObjects.Remove(gameObject);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Sector> GetNeighbouringSectors()
|
||||
{
|
||||
List<Sector> neighbours = [];
|
||||
|
|
@ -114,4 +100,15 @@ public class Sector
|
|||
|
||||
return neighbours;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
Sector sector = (Sector)obj;
|
||||
return sector.Coordinates == Coordinates;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Coordinates.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue