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)
|
||||
{
|
||||
position.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
|
||||
interpolatedPosition.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
|
||||
float maxY = Level.Loaded.Size.Y + 100;
|
||||
|
||||
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(
|
||||
new Vector3(-interpolatedPosition.X, interpolatedPosition.Y, 0)) *
|
||||
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Barotrauma
|
||||
|
||||
if (GameMain.DebugDraw)
|
||||
{
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
foreach (Submarine sub in Loaded)
|
||||
{
|
||||
Rectangle worldBorders = sub.Borders;
|
||||
worldBorders.Location += sub.WorldPosition.ToPoint();
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Barotrauma
|
||||
|
||||
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||
{
|
||||
cam.UpdateTransform(true);
|
||||
cam.UpdateTransform(true, !GameMain.DebugDraw);
|
||||
Submarine.CullEntities(cam);
|
||||
|
||||
DrawMap(graphics, spriteBatch);
|
||||
@@ -88,11 +88,11 @@ namespace Barotrauma
|
||||
{
|
||||
for (int i = 0; i < Submarine.MainSubs.Length; i++)
|
||||
{
|
||||
if (Submarine.MainSubs[i] != null)
|
||||
{
|
||||
Color indicatorColor = i == 0 ? Color.LightBlue * 0.5f : Color.Red * 0.5f;
|
||||
DrawSubmarineIndicator(spriteBatch, Submarine.MainSubs[i], indicatorColor);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1332,7 +1332,15 @@ namespace Barotrauma
|
||||
if (GameMain.Client != null && this == Controlled && !isSynced) 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;
|
||||
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull, true);
|
||||
//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)
|
||||
{
|
||||
if (Level.Loaded != null && WorldPosition.Y < Level.MaxEntityDepth)
|
||||
{
|
||||
Spawner.AddToRemoveQueue(this);
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyStatusEffects(ActionType.Always, deltaTime, null);
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
|
||||
@@ -14,8 +14,12 @@ namespace Barotrauma
|
||||
{
|
||||
partial class Level
|
||||
{
|
||||
public const float ShaftHeight = 1000.0f;
|
||||
//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 static Level Loaded
|
||||
{
|
||||
get { return loaded; }
|
||||
|
||||
@@ -414,15 +414,17 @@ namespace Barotrauma
|
||||
public static void CullEntities(Camera cam)
|
||||
{
|
||||
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(
|
||||
sub.Borders.X + (int)sub.WorldPosition.X - 500,
|
||||
sub.Borders.Y + (int)sub.WorldPosition.Y + 500,
|
||||
sub.Borders.Width + 1000,
|
||||
sub.Borders.Height + 1000);
|
||||
|
||||
if (Submarine.RectsOverlap(worldBorders, cam.WorldView))
|
||||
if (RectsOverlap(worldBorders, cam.WorldView))
|
||||
{
|
||||
visibleSubs.Add(sub);
|
||||
}
|
||||
@@ -682,21 +684,46 @@ namespace Barotrauma
|
||||
{
|
||||
//if (PlayerInput.KeyHit(InputType.Crouch) && (this == MainSub)) FlipX();
|
||||
|
||||
if (Level.Loaded == null) return;
|
||||
|
||||
if (subBody == null) return;
|
||||
if (Level.Loaded == null || 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(
|
||||
LockX ? 0.0f : subBody.Body.LinearVelocity.X,
|
||||
LockY ? 0.0f : subBody.Body.LinearVelocity.Y);
|
||||
|
||||
|
||||
|
||||
subBody.Update(deltaTime);
|
||||
|
||||
for (int i = 0; i < 2; i++ )
|
||||
{
|
||||
if (Submarine.MainSubs[i] == null) continue;
|
||||
if (this != Submarine.MainSubs[i] && Submarine.MainSubs[i].DockedTo.Contains(this)) return;
|
||||
if (MainSubs[i] == null) continue;
|
||||
if (this != MainSubs[i] && MainSubs[i].DockedTo.Contains(this)) return;
|
||||
}
|
||||
|
||||
//send updates more frequently if moving fast
|
||||
|
||||
@@ -16,8 +16,6 @@ namespace Barotrauma
|
||||
class SubmarineBody
|
||||
{
|
||||
public const float DamageDepth = -30000.0f;
|
||||
//private const float PressureDamageMultiplier = 0.001f;
|
||||
|
||||
private const float DamageMultiplier = 50.0f;
|
||||
|
||||
private const float Friction = 0.2f, Restitution = 0.0f;
|
||||
|
||||
@@ -117,6 +117,11 @@ namespace Barotrauma.Networking
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public RespawnManager RespawnManager
|
||||
{
|
||||
get { return respawnManager; }
|
||||
}
|
||||
|
||||
public NetworkMember()
|
||||
{
|
||||
InitProjSpecific();
|
||||
|
||||
@@ -59,6 +59,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
private float updateReturnTimer;
|
||||
|
||||
public Submarine RespawnShuttle
|
||||
{
|
||||
get { return respawnShuttle; }
|
||||
}
|
||||
|
||||
public RespawnManager(NetworkMember networkMember, Submarine shuttle)
|
||||
: base(shuttle)
|
||||
{
|
||||
|
||||
@@ -24,15 +24,15 @@ namespace Barotrauma
|
||||
{
|
||||
base.Select();
|
||||
|
||||
if (Character.Controlled!=null)
|
||||
if (Character.Controlled != null)
|
||||
{
|
||||
cam.Position = Character.Controlled.WorldPosition;
|
||||
cam.UpdateTransform();
|
||||
cam.UpdateTransform(true, !GameMain.DebugDraw);
|
||||
}
|
||||
else if (Submarine.MainSub != null)
|
||||
{
|
||||
cam.Position = Submarine.MainSub.WorldPosition;
|
||||
cam.UpdateTransform();
|
||||
cam.UpdateTransform(true, !GameMain.DebugDraw);
|
||||
}
|
||||
|
||||
foreach (MapEntity entity in MapEntity.mapEntityList)
|
||||
|
||||
Reference in New Issue
Block a user