Submarines, items and characters that reach a depth of 300,000 units (~4000 m) are automatically disabled. Avoids the unnecessary cost of updating entities that are way too deep to be reached by anyone.
This commit is contained in:
@@ -139,12 +139,17 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (Level.Loaded != null && clampPos)
|
if (Level.Loaded != null && clampPos)
|
||||||
{
|
{
|
||||||
position.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
|
float maxY = Level.Loaded.Size.Y + 100;
|
||||||
interpolatedPosition.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
|
|
||||||
|
|
||||||
worldView.Y = Math.Min((int)Level.Loaded.Size.Y, worldView.Y);
|
position.Y -= Math.Max(worldView.Y - maxY, 0.0f);
|
||||||
|
interpolatedPosition.Y -= Math.Max(worldView.Y - maxY, 0.0f);
|
||||||
|
|
||||||
|
position.Y = Math.Max(position.Y, (int)Level.MaxCameraDepth);
|
||||||
|
interpolatedPosition.Y = Math.Max(interpolatedPosition.Y, (int)Level.MaxCameraDepth);
|
||||||
|
worldView.Y = MathHelper.Clamp(worldView.Y, (int)Level.MaxCameraDepth, (int)maxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
transform = Matrix.CreateTranslation(
|
transform = Matrix.CreateTranslation(
|
||||||
new Vector3(-interpolatedPosition.X, interpolatedPosition.Y, 0)) *
|
new Vector3(-interpolatedPosition.X, interpolatedPosition.Y, 0)) *
|
||||||
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
|
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (GameMain.DebugDraw)
|
if (GameMain.DebugDraw)
|
||||||
{
|
{
|
||||||
foreach (Submarine sub in Submarine.Loaded)
|
foreach (Submarine sub in Loaded)
|
||||||
{
|
{
|
||||||
Rectangle worldBorders = sub.Borders;
|
Rectangle worldBorders = sub.Borders;
|
||||||
worldBorders.Location += sub.WorldPosition.ToPoint();
|
worldBorders.Location += sub.WorldPosition.ToPoint();
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
cam.UpdateTransform(true);
|
cam.UpdateTransform(true, !GameMain.DebugDraw);
|
||||||
Submarine.CullEntities(cam);
|
Submarine.CullEntities(cam);
|
||||||
|
|
||||||
DrawMap(graphics, spriteBatch);
|
DrawMap(graphics, spriteBatch);
|
||||||
@@ -88,11 +88,11 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < Submarine.MainSubs.Length; i++)
|
for (int i = 0; i < Submarine.MainSubs.Length; i++)
|
||||||
{
|
{
|
||||||
if (Submarine.MainSubs[i] != null)
|
if (Submarine.MainSubs[i] == null) continue;
|
||||||
{
|
if (Level.Loaded != null && Submarine.MainSubs[i].WorldPosition.Y < Level.MaxEntityDepth) continue;
|
||||||
Color indicatorColor = i == 0 ? Color.LightBlue * 0.5f : Color.Red * 0.5f;
|
|
||||||
DrawSubmarineIndicator(spriteBatch, Submarine.MainSubs[i], indicatorColor);
|
Color indicatorColor = i == 0 ? Color.LightBlue * 0.5f : Color.Red * 0.5f;
|
||||||
}
|
DrawSubmarineIndicator(spriteBatch, Submarine.MainSubs[i], indicatorColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1333,6 +1333,14 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (!Enabled) return;
|
if (!Enabled) return;
|
||||||
|
|
||||||
|
if (Level.Loaded != null && WorldPosition.Y < Level.MaxEntityDepth ||
|
||||||
|
(Submarine != null && Submarine.WorldPosition.Y < Level.MaxEntityDepth))
|
||||||
|
{
|
||||||
|
Enabled = false;
|
||||||
|
Kill(CauseOfDeath.Pressure);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PreviousHull = CurrentHull;
|
PreviousHull = CurrentHull;
|
||||||
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull, true);
|
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull, true);
|
||||||
//if (PreviousHull != CurrentHull && Character.Controlled == this) Hull.DetectItemVisibility(this); //WIP item culling
|
//if (PreviousHull != CurrentHull && Character.Controlled == this) Hull.DetectItemVisibility(this); //WIP item culling
|
||||||
|
|||||||
@@ -779,6 +779,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public override void Update(float deltaTime, Camera cam)
|
public override void Update(float deltaTime, Camera cam)
|
||||||
{
|
{
|
||||||
|
if (Level.Loaded != null && WorldPosition.Y < Level.MaxEntityDepth)
|
||||||
|
{
|
||||||
|
Spawner.AddToRemoveQueue(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ApplyStatusEffects(ActionType.Always, deltaTime, null);
|
ApplyStatusEffects(ActionType.Always, deltaTime, null);
|
||||||
|
|
||||||
foreach (ItemComponent ic in components)
|
foreach (ItemComponent ic in components)
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
partial class Level
|
partial class Level
|
||||||
{
|
{
|
||||||
|
//all entities are disabled after they reach this depth
|
||||||
|
public const float MaxEntityDepth = -300000.0f;
|
||||||
|
public const float MaxCameraDepth = -290000.0f;
|
||||||
|
|
||||||
public const float ShaftHeight = 1000.0f;
|
public const float ShaftHeight = 1000.0f;
|
||||||
|
|
||||||
public static Level Loaded
|
public static Level Loaded
|
||||||
|
|||||||
@@ -414,15 +414,17 @@ namespace Barotrauma
|
|||||||
public static void CullEntities(Camera cam)
|
public static void CullEntities(Camera cam)
|
||||||
{
|
{
|
||||||
HashSet<Submarine> visibleSubs = new HashSet<Submarine>();
|
HashSet<Submarine> visibleSubs = new HashSet<Submarine>();
|
||||||
foreach (Submarine sub in Submarine.Loaded)
|
foreach (Submarine sub in Loaded)
|
||||||
{
|
{
|
||||||
|
if (sub.WorldPosition.Y < Level.MaxEntityDepth) continue;
|
||||||
|
|
||||||
Rectangle worldBorders = new Rectangle(
|
Rectangle worldBorders = new Rectangle(
|
||||||
sub.Borders.X + (int)sub.WorldPosition.X - 500,
|
sub.Borders.X + (int)sub.WorldPosition.X - 500,
|
||||||
sub.Borders.Y + (int)sub.WorldPosition.Y + 500,
|
sub.Borders.Y + (int)sub.WorldPosition.Y + 500,
|
||||||
sub.Borders.Width + 1000,
|
sub.Borders.Width + 1000,
|
||||||
sub.Borders.Height + 1000);
|
sub.Borders.Height + 1000);
|
||||||
|
|
||||||
if (Submarine.RectsOverlap(worldBorders, cam.WorldView))
|
if (RectsOverlap(worldBorders, cam.WorldView))
|
||||||
{
|
{
|
||||||
visibleSubs.Add(sub);
|
visibleSubs.Add(sub);
|
||||||
}
|
}
|
||||||
@@ -682,9 +684,34 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
//if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX();
|
//if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX();
|
||||||
|
|
||||||
if (Level.Loaded == null) return;
|
if (Level.Loaded == null || subBody == null) return;
|
||||||
|
|
||||||
if (subBody == null) return;
|
if (WorldPosition.Y < Level.MaxEntityDepth &&
|
||||||
|
subBody.Body.Enabled &&
|
||||||
|
(GameMain.NetworkMember?.RespawnManager == null || this != GameMain.NetworkMember.RespawnManager.RespawnShuttle))
|
||||||
|
{
|
||||||
|
subBody.Body.ResetDynamics();
|
||||||
|
subBody.Body.Enabled = false;
|
||||||
|
|
||||||
|
foreach (MapEntity e in MapEntity.mapEntityList)
|
||||||
|
{
|
||||||
|
if (e.Submarine == this)
|
||||||
|
{
|
||||||
|
Spawner.AddToRemoveQueue(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Character c in Character.CharacterList)
|
||||||
|
{
|
||||||
|
if (c.Submarine == this)
|
||||||
|
{
|
||||||
|
c.Kill(CauseOfDeath.Pressure);
|
||||||
|
c.Enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
subBody.Body.LinearVelocity = new Vector2(
|
subBody.Body.LinearVelocity = new Vector2(
|
||||||
LockX ? 0.0f : subBody.Body.LinearVelocity.X,
|
LockX ? 0.0f : subBody.Body.LinearVelocity.X,
|
||||||
@@ -695,8 +722,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
for (int i = 0; i < 2; i++ )
|
for (int i = 0; i < 2; i++ )
|
||||||
{
|
{
|
||||||
if (Submarine.MainSubs[i] == null) continue;
|
if (MainSubs[i] == null) continue;
|
||||||
if (this != Submarine.MainSubs[i] && Submarine.MainSubs[i].DockedTo.Contains(this)) return;
|
if (this != MainSubs[i] && MainSubs[i].DockedTo.Contains(this)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//send updates more frequently if moving fast
|
//send updates more frequently if moving fast
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ namespace Barotrauma
|
|||||||
class SubmarineBody
|
class SubmarineBody
|
||||||
{
|
{
|
||||||
public const float DamageDepth = -30000.0f;
|
public const float DamageDepth = -30000.0f;
|
||||||
//private const float PressureDamageMultiplier = 0.001f;
|
|
||||||
|
|
||||||
private const float DamageMultiplier = 50.0f;
|
private const float DamageMultiplier = 50.0f;
|
||||||
|
|
||||||
private const float Friction = 0.2f, Restitution = 0.0f;
|
private const float Friction = 0.2f, Restitution = 0.0f;
|
||||||
|
|||||||
@@ -117,6 +117,11 @@ namespace Barotrauma.Networking
|
|||||||
get { return null; }
|
get { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RespawnManager RespawnManager
|
||||||
|
{
|
||||||
|
get { return respawnManager; }
|
||||||
|
}
|
||||||
|
|
||||||
public NetworkMember()
|
public NetworkMember()
|
||||||
{
|
{
|
||||||
InitProjSpecific();
|
InitProjSpecific();
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private float updateReturnTimer;
|
private float updateReturnTimer;
|
||||||
|
|
||||||
|
public Submarine RespawnShuttle
|
||||||
|
{
|
||||||
|
get { return respawnShuttle; }
|
||||||
|
}
|
||||||
|
|
||||||
public RespawnManager(NetworkMember networkMember, Submarine shuttle)
|
public RespawnManager(NetworkMember networkMember, Submarine shuttle)
|
||||||
: base(shuttle)
|
: base(shuttle)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,15 +24,15 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
base.Select();
|
base.Select();
|
||||||
|
|
||||||
if (Character.Controlled!=null)
|
if (Character.Controlled != null)
|
||||||
{
|
{
|
||||||
cam.Position = Character.Controlled.WorldPosition;
|
cam.Position = Character.Controlled.WorldPosition;
|
||||||
cam.UpdateTransform();
|
cam.UpdateTransform(true, !GameMain.DebugDraw);
|
||||||
}
|
}
|
||||||
else if (Submarine.MainSub != null)
|
else if (Submarine.MainSub != null)
|
||||||
{
|
{
|
||||||
cam.Position = Submarine.MainSub.WorldPosition;
|
cam.Position = Submarine.MainSub.WorldPosition;
|
||||||
cam.UpdateTransform();
|
cam.UpdateTransform(true, !GameMain.DebugDraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (MapEntity entity in MapEntity.mapEntityList)
|
foreach (MapEntity entity in MapEntity.mapEntityList)
|
||||||
|
|||||||
Reference in New Issue
Block a user