Cleanup (removing unused variables & other redundancies, rethrowing exceptions instead of wrapping them in a new exception instance)

This commit is contained in:
Regalis
2017-05-20 15:35:13 +03:00
parent 89bd2b1a98
commit e3b595b9e0
40 changed files with 54 additions and 138 deletions
@@ -30,9 +30,7 @@ namespace Barotrauma
private float updateTargetsTimer;
private float raycastTimer;
private Vector2 prevPosition;
//a timer for attacks such as biting that last for a specific amount of time
//the duration is determined by the attackDuration of the attacking limb
private float attackTimer;
@@ -48,7 +48,6 @@ namespace Barotrauma
/// makes the character act according to the objective, or according to any subobjectives that
/// need to be completed before this one
/// </summary>
/// <param name="character">the character who's trying to achieve the objective</param>
public void TryComplete(float deltaTime)
{
subObjectives.RemoveAll(s => s.IsCompleted() || !s.CanBeCompleted);
@@ -5,8 +5,6 @@ namespace Barotrauma
{
class AICharacter : Character
{
const float AttackBackPriority = 1.0f;
private AIController aiController;
public override AIController AIController
@@ -857,7 +857,7 @@ namespace Barotrauma
headInWater = false;
inWater = false;
if (inWater = currentHull.Volume > currentHull.FullVolume * 0.95f)
if (currentHull.Volume > currentHull.FullVolume * 0.95f)
{
inWater = true;
}
@@ -1435,8 +1435,6 @@ namespace Barotrauma
public Vector2 GetColliderBottom()
{
float halfHeight = Collider.height * 0.5f + Collider.radius;
float offset = 0.0f;
if (!character.IsUnconscious && !character.IsDead && character.Stun <= 0.0f)
+1 -3
View File
@@ -37,9 +37,7 @@ namespace Barotrauma
}
}
}
public List<Item> SpawnItems = new List<Item>();
private bool enabled = true;
public bool Enabled
{
@@ -70,7 +70,6 @@ namespace Barotrauma
public InputNetFlags states; //keys pressed/other boolean states at this step
public UInt16 intAim; //aim angle, represented as an unsigned short where 0=0º, 65535=just a bit under 360º
public UInt16 interact; //id of the entity being interacted with
public AnimController.Animation? animation;
public UInt16 networkUpdateID;
}
+2 -4
View File
@@ -131,9 +131,7 @@ namespace Barotrauma
item.AddTag(s);
}
}
character.SpawnItems.Add(item);
if (parentItem != null) parentItem.Combine(item);
foreach (XElement childItemElement in itemElement.Elements())
@@ -142,7 +140,7 @@ namespace Barotrauma
}
}
public virtual XElement Save(XElement parentElement)
public XElement Save(XElement parentElement)
{
XElement jobElement = new XElement("job");
+1 -7
View File
@@ -48,13 +48,7 @@ namespace Barotrauma
public readonly LimbType type;
public readonly bool ignoreCollisions;
//private readonly float maxHealth;
//private float damage;
//private float bleeding;
public readonly float impactTolerance;
private float damage, burnt;
private readonly Vector2 armorSector;
+1 -1
View File
@@ -367,7 +367,7 @@ namespace Barotrauma
}
else if (spawnInventory != null)
{
Item.Spawner.AddToSpawnQueue(itemPrefab, (Inventory)spawnInventory);
Item.Spawner.AddToSpawnQueue(itemPrefab, spawnInventory);
}
break;
+2 -2
View File
@@ -114,7 +114,7 @@ namespace Barotrauma
face.LoadGlyph(face.GetCharIndex(baseChar), LoadFlags.Default, LoadTarget.Normal);
baseHeight = face.Glyph.Metrics.Height.ToInt32();
//lineHeight = baseHeight;
for (int i = 0; i < charRanges.Count(); i += 2)
for (int i = 0; i < charRanges.Length; i += 2)
{
uint start = charRanges[i];
uint end = charRanges[i + 1];
@@ -139,7 +139,7 @@ namespace Barotrauma
face.Glyph.RenderGlyph(RenderMode.Normal);
byte[] bitmap = face.Glyph.Bitmap.BufferData;
int glyphWidth = face.Glyph.Bitmap.Width;
int glyphHeight = bitmap.Count() / glyphWidth;
int glyphHeight = bitmap.Length / glyphWidth;
//if (glyphHeight>lineHeight) lineHeight=glyphHeight;
+1 -3
View File
@@ -59,9 +59,7 @@ namespace Barotrauma
public readonly Color OutlineColor;
public readonly Dictionary<GUIComponent.ComponentState, List<UISprite>> Sprites;
public readonly bool TileSprites;
public Dictionary<string, GUIComponentStyle> ChildStyles;
public GUIComponentStyle(XElement element)
+2 -2
View File
@@ -40,7 +40,7 @@ namespace Barotrauma
catch (Exception e)
{
DebugConsole.NewMessage("Error in AddToGUIUPdateList! GUIComponent runtime type: "+this.GetType().ToString()+"; children count: "+children.Count.ToString(),Color.Red);
throw e;
throw;
}
}
@@ -427,7 +427,7 @@ namespace Barotrauma
catch (Exception e)
{
DebugConsole.NewMessage("Error in Update! GUIComponent runtime type: " + this.GetType().ToString() + "; children count: " + children.Count.ToString(), Color.Red);
throw e;
throw;
}
}
+1 -1
View File
@@ -261,7 +261,7 @@ namespace Barotrauma
catch (Exception e)
{
DebugConsole.NewMessage("Error in AddToGUIUpdateList! GUIComponent runtime type: " + this.GetType().ToString() + "; children count: " + children.Count.ToString(), Color.Red);
throw e;
throw;
}
if (scrollBarEnabled && !scrollBarHidden) scrollBar.AddToGUIUpdateList();
@@ -41,7 +41,7 @@ namespace Barotrauma
Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20),
cargoRoom.Rect.Y - cargoRoom.Rect.Height + prefab.Size.Y/2);
new Item(prefab as ItemPrefab, position, wp.Submarine);
new Item(prefab, position, wp.Submarine);
}
purchasedItems.Clear();
+2 -2
View File
@@ -161,9 +161,9 @@ namespace Barotrauma
public void StartShift(string levelSeed, bool loadSecondSub = false)
{
Level level = Level.CreateRandom(levelSeed);
Level randomLevel = Level.CreateRandom(levelSeed);
StartShift(level,true,loadSecondSub);
StartShift(randomLevel, true, loadSecondSub);
}
public void StartShift(Level level, bool reloadSub = true, bool loadSecondSub = false)
+1 -1
View File
@@ -6,7 +6,7 @@ namespace Barotrauma
{
public List<CharacterInfo> availableCharacters;
const int MaxAvailableCharacters = 10;
public const int MaxAvailableCharacters = 10;
public HireManager()
{
@@ -714,7 +714,6 @@ namespace Barotrauma.Items.Components
if (gap != null)
{
gap.Remove();
gap.linkedTo.Remove(hull);
continue;
}
+1 -3
View File
@@ -33,9 +33,7 @@ namespace Barotrauma.Items.Components
private bool isHorizontal;
private bool isStuck;
private float lastReceivedMessage;
private bool? predictedState;
private float resetPredictionTimer;
@@ -95,8 +95,6 @@ namespace Barotrauma.Items.Components
if (userPos != Vector2.Zero)
{
float torsoX = character.Position.X;
Vector2 diff = (item.WorldPosition + userPos) - character.WorldPosition;
if (character.AnimController.InWater)
@@ -148,9 +148,7 @@ namespace Barotrauma.Items.Components
radarBlips[i].FadeTimer -= (float)Timing.Step * 0.5f;
if (radarBlips[i].FadeTimer <= 0.0f) radarBlips.RemoveAt(i);
}
float radius = (GuiFrame.Rect.Height / 2 - 30);
if (IsActive)
{
float pingRadius = displayRadius * pingState;
+6 -25
View File
@@ -262,13 +262,7 @@ namespace Barotrauma
{
get { return prefab.ConfigFile; }
}
public bool Removed
{
get;
private set;
}
//which type of inventory slots (head, torso, any, etc) the item can be placed in
public List<InvSlotType> AllowedSlots
{
@@ -278,16 +272,7 @@ namespace Barotrauma
return (p==null) ? new List<InvSlotType>() { InvSlotType.Any } : p.AllowedSlots;
}
}
public int Capacity
{
get
{
ItemContainer c = GetComponent<ItemContainer>();
return (c == null) ? 0 : c.Capacity;
}
}
public List<Connection> Connections
{
get
@@ -570,11 +555,11 @@ namespace Barotrauma
{
if (parentInventory.Owner is Character)
{
CurrentHull = (parentInventory.Owner as Character).AnimController.CurrentHull;
CurrentHull = ((Character)parentInventory.Owner).AnimController.CurrentHull;
}
else if (parentInventory.Owner is Item)
{
CurrentHull = (parentInventory.Owner as Item).CurrentHull;
CurrentHull = ((Item)parentInventory.Owner).CurrentHull;
}
Submarine = parentInventory.Owner.Submarine;
@@ -2306,9 +2291,7 @@ namespace Barotrauma
public override void ShallowRemove()
{
base.ShallowRemove();
Removed = true;
foreach (ItemComponent ic in components)
{
ic.ShallowRemove();
@@ -2325,9 +2308,7 @@ namespace Barotrauma
public override void Remove()
{
base.Remove();
Removed = true;
if (parentInventory != null)
{
parentInventory.RemoveItem(this);
@@ -1,13 +1,8 @@
using FarseerPhysics.Common;
using FarseerPhysics.Common.PolygonManipulation;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Voronoi2;
namespace Barotrauma.RuinGeneration
+6 -6
View File
@@ -239,15 +239,15 @@ namespace Barotrauma.Lights
private void CalculateDimensions()
{
float? minX = null, minY = null, maxX = null, maxY = null;
float minX = vertices[0].Pos.X, minY = vertices[0].Pos.Y, maxX = vertices[0].Pos.X, maxY = vertices[0].Pos.Y;
for (int i = 0; i < vertices.Length; i++)
for (int i = 1; i < vertices.Length; i++)
{
if (minX == null || vertices[i].Pos.X < minX) minX = vertices[i].Pos.X;
if (minY == null || vertices[i].Pos.Y < minY) minY = vertices[i].Pos.Y;
if (vertices[i].Pos.X < minX) minX = vertices[i].Pos.X;
if (vertices[i].Pos.Y < minY) minY = vertices[i].Pos.Y;
if (maxX == null || vertices[i].Pos.X > maxX) maxX = vertices[i].Pos.X;
if (maxY == null || vertices[i].Pos.Y > minY) maxY = vertices[i].Pos.Y;
if (vertices[i].Pos.X > maxX) maxX = vertices[i].Pos.X;
if (vertices[i].Pos.Y > minY) maxY = vertices[i].Pos.Y;
}
boundingBox = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
+4 -15
View File
@@ -40,8 +40,8 @@ namespace Barotrauma.Lights
private Texture2D visionCircle;
private Dictionary<Hull, Color> hullAmbientLights = new Dictionary<Hull, Color>();
private Dictionary<Hull, Color> smoothedHullAmbientLights = new Dictionary<Hull, Color>();
private Dictionary<Hull, Color> hullAmbientLights;
private Dictionary<Hull, Color> smoothedHullAmbientLights;
private float ambientLightUpdateTimer;
@@ -133,10 +133,7 @@ namespace Barotrauma.Lights
public void UpdateLightMap(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Effect blur)
{
if (!LightingEnabled) return;
Matrix shadowTransform = cam.ShaderTransform
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
graphics.SetRenderTarget(lightMap);
Rectangle viewRect = cam.WorldView;
@@ -337,20 +334,12 @@ namespace Barotrauma.Lights
return hullAmbientLight;
}
private void ClearAlphaToOne(GraphicsDevice graphics, SpriteBatch spriteBatch)
{
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.WriteToAlpha);
spriteBatch.Draw(alphaClearTexture, new Rectangle(0, 0,graphics.Viewport.Width, graphics.Viewport.Height), Color.White);
spriteBatch.End();
}
public void DrawLightMap(SpriteBatch spriteBatch, Effect effect)
{
if (!LightingEnabled) return;
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null, effect);
//effect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(lightMap, Vector2.Zero, Color.White);
spriteBatch.End();
}
+3 -3
View File
@@ -49,7 +49,7 @@ namespace Barotrauma
if (type.HasHireableCharacters)
{
hireManager = new HireManager();
hireManager.GenerateCharacters(this, 10);
hireManager.GenerateCharacters(this, HireManager.MaxAvailableCharacters);
}
Connections = new List<LocationConnection>();
@@ -62,9 +62,9 @@ namespace Barotrauma
private string RandomName(LocationType type)
{
string name = ToolBox.GetRandomLine("Content/Map/locationNames.txt");
string randomName = ToolBox.GetRandomLine("Content/Map/locationNames.txt");
int nameFormatIndex = Rand.Int(type.NameFormats.Count, false);
return type.NameFormats[nameFormatIndex].Replace("[name]", name);
return type.NameFormats[nameFormatIndex].Replace("[name]", randomName);
}
}
}
+1 -3
View File
@@ -362,9 +362,7 @@ namespace Barotrauma
linkedTo.Clear();
}
}
static Dictionary<string, float> timeElapsed = new Dictionary<string, float>();
/// <summary>
/// Call Update() on every object in Entity.list
/// </summary>
+1 -1
View File
@@ -872,7 +872,7 @@ namespace Barotrauma
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
for (int i = 0; i < sections.Count(); i++)
for (int i = 0; i < sections.Length; i++)
{
float damage = msg.ReadRangedSingle(0.0f, 1.0f, 8) * Health;
+1 -2
View File
@@ -1,5 +1,4 @@
using Barotrauma.Items.Components;
using Lidgren.Network;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using System;
using System.Text;
+1 -3
View File
@@ -28,11 +28,9 @@ namespace Barotrauma.Networking
public Character Character;
public CharacterInfo characterInfo;
public NetConnection Connection { get; set; }
public string version;
public bool inGame;
public UInt16 lastRecvGeneralUpdate = 0;
public bool hasLobbyData = false;
public UInt16 lastSentChatMsgID = 0; //last msg this client said
public UInt16 lastRecvChatMsgID = 0; //last msg this client knows about
+1 -5
View File
@@ -1094,8 +1094,7 @@ namespace Barotrauma.Networking
for (int i = 0; i < fileReceiver.ActiveTransfers.Count; i++)
{
var transfer = fileReceiver.ActiveTransfers[i];
GameMain.NetLobbyScreen.SubList.children.Find(c => c is GUITextBlock && ((GUITextBlock)c).Text == transfer.FileName);
GUI.DrawString(spriteBatch,
pos,
ToolBox.LimitString("Downloading " + transfer.FileName, GUI.SmallFont, 200),
@@ -1221,9 +1220,6 @@ namespace Barotrauma.Networking
if (votedClient == null) return false;
votedClient.AddKickVote(new Client(name, ID));
if (votedClient == null) return false;
Vote(VoteType.Kick, votedClient);
button.Enabled = false;
@@ -9,12 +9,12 @@ using System.Xml.Linq;
namespace Barotrauma.Networking
{
enum SelectionMode : int
enum SelectionMode
{
Manual = 0, Random = 1, Vote = 2
}
enum YesNoMaybe : int
enum YesNoMaybe
{
No = 0, Maybe = 1, Yes = 2
}
@@ -156,7 +156,7 @@ namespace Barotrauma.Networking
//kick everyone that hasn't received it yet, this is way too old
List<Client> toKick = inGameClients.FindAll(c => NetIdUtils.IdMoreRecent((UInt16)(lastSentToAll + 1), c.lastRecvEntityEventID));
if (toKick != null) toKick.ForEach(c => server.DisconnectClient(c, "", "You have been disconnected because of excessive desync"));
toKick.ForEach(c => server.DisconnectClient(c, "", "You have been disconnected because of excessive desync"));
}
if (events.Count > 0)
@@ -164,12 +164,12 @@ namespace Barotrauma.Networking
//the client is waiting for an event that we don't have anymore
//(the ID they're expecting is smaller than the ID of the first event in our list)
List<Client> toKick = inGameClients.FindAll(c => NetIdUtils.IdMoreRecent(events[0].ID, (UInt16)(c.lastRecvEntityEventID+1)));
if (toKick != null) toKick.ForEach(c => server.DisconnectClient(c, "", "You have been disconnected because of excessive desync"));
toKick.ForEach(c => server.DisconnectClient(c, "", "You have been disconnected because of excessive desync"));
}
}
var timedOutClients = clients.FindAll(c => c.inGame && c.NeedsMidRoundSync && Timing.TotalTime > c.MidRoundSyncTimeOut);
if (timedOutClients != null) timedOutClients.ForEach(c => GameMain.Server.DisconnectClient(c, "", "You have been disconnected because syncing your client with the server took too long."));
timedOutClients.ForEach(c => GameMain.Server.DisconnectClient(c, "", "You have been disconnected because syncing your client with the server took too long."));
bufferedEvents.RemoveAll(b => b.IsProcessed);
}
@@ -392,12 +392,8 @@ namespace Barotrauma.Networking
{
var server = networkMember as GameServer;
if (server == null) return;
List<Item> spawnedItems = new List<Item>();
List<Character> spawnedCharacters = new List<Character>();
var clients = GetClientsToRespawn();
foreach (Client c in clients)
{
if (c.characterInfo == null) c.characterInfo = new CharacterInfo(Character.HumanConfigFile, c.name);
+1 -2
View File
@@ -78,8 +78,7 @@ namespace Barotrauma
private Vector2 drawPosition;
private float drawRotation;
private float lastNetworkUpdateTime;
public Vector2 LastSentPosition
{
get;
@@ -95,7 +95,6 @@ namespace Barotrauma
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
cam.MoveCamera((float)deltaTime);
@@ -113,7 +112,6 @@ namespace Barotrauma
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
//cam.UpdateTransform();
@@ -960,7 +960,6 @@ namespace Barotrauma
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
if (tutorial != null) tutorial.Update((float)deltaTime);
@@ -1085,7 +1084,6 @@ namespace Barotrauma
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
cam.UpdateTransform();
-1
View File
@@ -110,7 +110,6 @@ namespace Barotrauma
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
+1 -2
View File
@@ -1120,10 +1120,9 @@ namespace Barotrauma
//}
GameModePreset modePreset = obj as GameModePreset;
missionTypeBlock.Visible = modePreset.Name == "Mission";
if (modePreset == null) return false;
missionTypeBlock.Visible = modePreset.Name == "Mission";
lastUpdateID++;
return true;
+1 -1
View File
@@ -48,7 +48,7 @@ namespace Barotrauma.Sounds
catch (DllNotFoundException e)
{
Program.CrashMessageBox("OpenAL32.dll not found");
throw e;
throw;
}
for (int i = 0 ; i < DefaultSourceCount; i++)
+1 -3
View File
@@ -22,9 +22,7 @@ namespace Barotrauma
fileName = Path.Combine(SaveFolder, fileName);
string tempPath = Path.Combine(SaveFolder, "temp");
DirectoryInfo dir = new DirectoryInfo(tempPath);
Directory.CreateDirectory(tempPath);
try
{