Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,10 +1317,14 @@ void CreateTraitorList(Action<string> createMessage)
GameMain.LuaCs.ToggleDebugger(port);
}));

/*
commands.Add(new Command("install_cl_ep", "Installs Client-Side ProjectEP into your client.", (string[] args) =>
{
LuaCsInstaller.Install();
}));
*/
// Removed due to critical partical issues
// TODO: Partical manager requires a refactor to solve race condition

commands.Add(new Command("randomizeseed", "randomizeseed: Toggles level seed randomization on/off.", (string[] args) =>
{
Expand Down
67 changes: 33 additions & 34 deletions Barotrauma/BarotraumaShared/SharedSource/Map/Submarine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
using Barotrauma.IO;
using Barotrauma.Items.Components;
using Barotrauma.Networking;
using Barotrauma.PerkBehaviors;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Xml.Linq;
using Barotrauma.PerkBehaviors;
using Voronoi2;

namespace Barotrauma
Expand Down Expand Up @@ -485,9 +484,9 @@ private Rectangle GetDockedBordersRecursive(bool allowDifferentTeam)
{
Rectangle dockedBorders = Borders;
checkSubmarineBorders.Add(this);
var connectedSubs = DockedTo.Where(s =>
!checkSubmarineBorders.Contains(s) &&
!s.Info.IsOutpost &&
var connectedSubs = DockedTo.Where(s =>
!checkSubmarineBorders.Contains(s) &&
!s.Info.IsOutpost &&
(allowDifferentTeam || s.TeamID == TeamID));
foreach (Submarine dockedSub in connectedSubs)
{
Expand All @@ -509,16 +508,23 @@ private Rectangle GetDockedBordersRecursive(bool allowDifferentTeam)
return dockedBorders;
}

private readonly ConcurrentBag<Submarine> connectedSubs;
private readonly HashSet<Submarine> connectedSubs;
/// <summary>
/// Returns a list of all submarines that are connected to this one via docking ports, including this sub.
/// </summary>
public ConcurrentBag<Submarine> GetConnectedSubs()
public IEnumerable<Submarine> GetConnectedSubs()
{
return connectedSubs;
}

private void GetConnectedSubsRecursive(ConcurrentBag<Submarine> subs)
public void RefreshConnectedSubs()
{
connectedSubs.Clear();
connectedSubs.Add(this);
GetConnectedSubsRecursive(connectedSubs);
}

private void GetConnectedSubsRecursive(HashSet<Submarine> subs)
{
foreach (Submarine dockedSub in DockedTo)
{
Expand All @@ -528,12 +534,6 @@ private void GetConnectedSubsRecursive(ConcurrentBag<Submarine> subs)
}
}

public void RefreshConnectedSubs()
{
connectedSubs.Clear();
connectedSubs.Add(this);
GetConnectedSubsRecursive(connectedSubs);
}
/// <summary>
/// Attempt to find a spawn position close to the specified position where the sub doesn't collide with walls/ruins
/// </summary>
Expand All @@ -551,7 +551,7 @@ public Vector2 FindSpawnPos(Vector2 spawnPos, Point? submarineSize = null, float
minWidth += padding;
minHeight += padding;

int iterations = 0;
int iterations = 0;
const int maxIterations = 5;
do
{
Expand Down Expand Up @@ -580,9 +580,9 @@ public Vector2 FindSpawnPos(Vector2 spawnPos, Point? submarineSize = null, float
//if the raycast hit a wall, attempt to place the spawnpos there
int offsetFromWall = 10 * -verticalMoveDir;
float pickedPos = ConvertUnits.ToDisplayUnits(LastPickedPosition.Y) + offsetFromWall;
closestPickedPos.Y =
verticalMoveDir > 0 ?
Math.Min(closestPickedPos.Y, pickedPos) :
closestPickedPos.Y =
verticalMoveDir > 0 ?
Math.Min(closestPickedPos.Y, pickedPos) :
Math.Max(closestPickedPos.Y, pickedPos);
}
}
Expand All @@ -597,7 +597,7 @@ public Vector2 FindSpawnPos(Vector2 spawnPos, Point? submarineSize = null, float
bool couldMoveInVerticalMoveDir = Math.Sign(newSpawnPos.Y - spawnPos.Y) == Math.Sign(verticalMoveDir);
if (!couldMoveInVerticalMoveDir) { break; }
spawnPos = ClampToHorizontalLimits(newSpawnPos, limits);
}
}

iterations++;
} while (iterations < maxIterations);
Expand Down Expand Up @@ -1001,7 +1001,7 @@ private static bool CheckFixtureCollision(Fixture fixture, IEnumerable<Body> ign
/// <param name="ignoreBranches">Should plants' branches be ignored?</param>
/// <param name="blocksVisibilityPredicate">If the predicate returns false, the fixture is ignored even if it would normally block visibility.</param>
/// <returns>A physics body that was between the points (or null)</returns>
public static Body CheckVisibility(Vector2 rayStart, Vector2 rayEnd, bool ignoreLevel = false, bool ignoreSubs = false, bool ignoreSensors = true, bool ignoreDisabledWalls = true, bool ignoreBranches = true,
public static Body CheckVisibility(Vector2 rayStart, Vector2 rayEnd, bool ignoreLevel = false, bool ignoreSubs = false, bool ignoreSensors = true, bool ignoreDisabledWalls = true, bool ignoreBranches = true,
Predicate<Fixture> blocksVisibilityPredicate = null)
{
Body closestBody = null;
Expand Down Expand Up @@ -1160,10 +1160,10 @@ public void FlipX(List<Submarine> parents = null)
{
//a little hacky: undock and redock to ensure the hulls and gaps between docking ports are correct
//after all the parts of the submarine have been flipped and moved to correct places.
if (dockingPort.DockingTarget is { } dockingTarget)
if (dockingPort.DockingTarget is { } dockingTarget)
{
dockingPort.Undock();
dockingPort.Dock(dockingTarget);
dockingPort.Undock();
dockingPort.Dock(dockingTarget);
}
}

Expand Down Expand Up @@ -1487,7 +1487,7 @@ public static Submarine FindClosest(Vector2 worldPosition, bool ignoreOutposts =
{
if (ignoreOutposts && sub.Info.IsOutpost) { continue; }
if (ignoreOutsideLevel && Level.Loaded != null && sub.IsAboveLevel) { continue; }
if (ignoreRespawnShuttle && sub.IsRespawnShuttle) { continue; }
if (ignoreRespawnShuttle && sub.IsRespawnShuttle) { continue; }
if (teamType.HasValue && sub.TeamID != teamType) { continue; }
float dist = Vector2.DistanceSquared(worldPosition, sub.WorldPosition);
if (closest == null || dist < closestDist)
Expand Down Expand Up @@ -1551,7 +1551,6 @@ public bool IsEntityFoundOnThisSub(MapEntity entity, bool includingConnectedSubs
if (includingConnectedSubs)
{
// Performance-sensitive code -> implemented without Linq.

foreach (Submarine s in connectedSubs)
{
if (s == entity.Submarine && (allowDifferentTeam || entity.Submarine.TeamID == TeamID) && (allowDifferentType || entity.Submarine.Info.Type == Info.Type))
Expand Down Expand Up @@ -1601,7 +1600,7 @@ public static Rectangle GetBorders(XElement submarineElement)
Vector4 bounds = new Vector4(float.MaxValue, float.MinValue, float.MinValue, float.MaxValue);
foreach (XElement element in submarineElement.Elements())
{
if (element.Name == "Structure")
if (element.Name == "Structure")
{
string name = element.GetAttributeString("name", "");
Identifier identifier = element.GetAttributeIdentifier("identifier", "");
Expand Down Expand Up @@ -1643,7 +1642,7 @@ public Submarine(SubmarineInfo info,
{
Stopwatch sw = Stopwatch.StartNew();

connectedSubs = new ConcurrentBag<Submarine>
connectedSubs = new HashSet<Submarine>(2)
{
this
};
Expand Down Expand Up @@ -1830,7 +1829,7 @@ public Submarine(SubmarineInfo info,
}
}

if (Screen.Selected is { IsEditor: false })
if (Screen.Selected is { IsEditor : false })
{
foreach (Identifier layer in Info.LayersHiddenByDefault)
{
Expand Down Expand Up @@ -2012,7 +2011,7 @@ public void SaveToXElement(XElement element)
Item itemToSwap = kvp.Key;
ItemPrefab swapTo = kvp.Value;
itemToSwap.PurchasedNewSwap = item.PurchasedNewSwap;
if (itemToSwap.Prefab != swapTo) { itemToSwap.PendingItemSwap = swapTo; }
if (itemToSwap.Prefab != swapTo) { itemToSwap.PendingItemSwap = swapTo; }
}
}

Expand Down Expand Up @@ -2102,8 +2101,8 @@ public static bool Unloading

public static void Unload()
{
if (Unloading)
{
if (Unloading)
{
DebugConsole.AddWarning($"Called {nameof(Submarine.Unload)} when already unloading.");
return;
}
Expand Down Expand Up @@ -2153,7 +2152,7 @@ public static void Unload()

Ragdoll.RemoveAll();
PhysicsBody.RemoveAll();
StatusEffect.StopAll();
StatusEffect.StopAll();
GameMain.World = null;

Powered.Grids.Clear();
Expand Down Expand Up @@ -2349,10 +2348,10 @@ public Item FindContainerFor(Item item, bool onlyPrimary, bool checkTransferCond
if (potentialContainer.Submarine == this && !isSecondary)
{
//valid primary container in the same sub -> perfect, let's use that one
return potentialContainer;
return potentialContainer;
}
selectedContainer = potentialContainer;

}
return selectedContainer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public override void Update(double deltaTime)
GameMain.PerformanceCounter.AddElapsedTicks("Update:GameSession", sw.ElapsedTicks);
sw.Restart();

GameMain.ParticleManager.Update((float)deltaTime);
GameMain.ParticleManager?.Update((float)deltaTime);

sw.Stop();
GameMain.PerformanceCounter.AddElapsedTicks("Update:Particle", sw.ElapsedTicks);
Expand Down
Loading