diff --git a/BarotraumaClient/BarotraumaClient.csproj b/BarotraumaClient/BarotraumaClient.csproj index 8bb6b1620..e7ab3ca74 100644 --- a/BarotraumaClient/BarotraumaClient.csproj +++ b/BarotraumaClient/BarotraumaClient.csproj @@ -63,6 +63,7 @@ + @@ -89,6 +90,7 @@ + @@ -148,6 +150,7 @@ + diff --git a/BarotraumaClient/Source/Characters/AI/AIController.cs b/BarotraumaClient/Source/Characters/AI/AIController.cs new file mode 100644 index 000000000..3613ba3fe --- /dev/null +++ b/BarotraumaClient/Source/Characters/AI/AIController.cs @@ -0,0 +1,11 @@ +using Lidgren.Network; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Barotrauma +{ + partial class AIController : ISteerable + { + public virtual void DebugDraw(SpriteBatch spriteBatch) { } + } +} diff --git a/BarotraumaClient/Source/GameSession/GameMode.cs b/BarotraumaClient/Source/GameSession/GameMode.cs new file mode 100644 index 000000000..83b87c5ce --- /dev/null +++ b/BarotraumaClient/Source/GameSession/GameMode.cs @@ -0,0 +1,10 @@ +using Microsoft.Xna.Framework.Graphics; +namespace Barotrauma +{ + partial class GameMode + { + public virtual void Draw(SpriteBatch spriteBatch) + { + } + } +} diff --git a/BarotraumaClient/Source/Items/CharacterInventory.cs b/BarotraumaClient/Source/Items/CharacterInventory.cs index 101eb54c1..6bb0dc064 100644 --- a/BarotraumaClient/Source/Items/CharacterInventory.cs +++ b/BarotraumaClient/Source/Items/CharacterInventory.cs @@ -12,6 +12,8 @@ namespace Barotrauma { partial class CharacterInventory : Inventory { + private static Texture2D icons; + public Vector2[] SlotPositions; private GUIButton[] useOnSelfButton; diff --git a/BarotraumaClient/Source/Map/Levels/CaveGenerator.cs b/BarotraumaClient/Source/Map/Levels/CaveGenerator.cs new file mode 100644 index 000000000..8c318a2b4 --- /dev/null +++ b/BarotraumaClient/Source/Map/Levels/CaveGenerator.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Voronoi2; +using Microsoft.Xna.Framework.Graphics; +using FarseerPhysics; +using FarseerPhysics.Common; +using FarseerPhysics.Dynamics; +using FarseerPhysics.Factories; + +namespace Barotrauma +{ + static partial class CaveGenerator + { + public static List GenerateRenderVerticeList(List triangles) + { + var verticeList = new List(); + for (int i = 0; i < triangles.Count; i++) + { + foreach (Vector2 vertex in triangles[i]) + { + //shift the coordinates around a bit to make the texture repetition less obvious + Vector2 uvCoords = new Vector2( + vertex.X / 2000.0f + (float)Math.Sin(vertex.X / 500.0f) * 0.15f, + vertex.Y / 2000.0f + (float)Math.Sin(vertex.Y / 700.0f) * 0.15f); + + verticeList.Add(new VertexPositionTexture(new Vector3(vertex, 1.0f), uvCoords)); + } + } + + return verticeList; + } + + public static VertexPositionTexture[] GenerateWallShapes(List cells) + { + float inwardThickness = 500.0f, outWardThickness = 30.0f; + + List verticeList = new List(); + + foreach (VoronoiCell cell in cells) + { + //if (cell.body == null) continue; + foreach (GraphEdge edge in cell.edges) + { + if (edge.cell1 != null && edge.cell1.body == null && edge.cell1.CellType != CellType.Empty) edge.cell1 = null; + if (edge.cell2 != null && edge.cell2.body == null && edge.cell2.CellType != CellType.Empty) edge.cell2 = null; + + CompareCCW compare = new CompareCCW(cell.Center); + if (compare.Compare(edge.point1, edge.point2) == -1) + { + var temp = edge.point1; + edge.point1 = edge.point2; + edge.point2 = temp; + } + } + } + + foreach (VoronoiCell cell in cells) + { + //if (cell.body == null) continue; + foreach (GraphEdge edge in cell.edges) + { + if (!edge.isSolid) continue; + + GraphEdge leftEdge = cell.edges.Find(e => e != edge && (edge.point1 == e.point1 || edge.point1 == e.point2)); + GraphEdge rightEdge = cell.edges.Find(e => e != edge && (edge.point2 == e.point1 || edge.point2 == e.point2)); + + Vector2 leftNormal = Vector2.Zero, rightNormal = Vector2.Zero; + + if (leftEdge == null) + { + leftNormal = GetEdgeNormal(edge, cell); + } + else + { + leftNormal = (leftEdge.isSolid) ? + Vector2.Normalize(GetEdgeNormal(leftEdge) + GetEdgeNormal(edge, cell)) : + Vector2.Normalize(leftEdge.Center - edge.point1); + } + + + if (!MathUtils.IsValid(leftNormal)) + { +#if DEBUG + DebugConsole.ThrowError("Invalid left normal"); +#endif + if (cell.body != null) + { + GameMain.World.RemoveBody(cell.body); + cell.body = null; + } + leftNormal = Vector2.UnitX; + break; + } + + + if (rightEdge == null) + { + rightNormal = GetEdgeNormal(edge, cell); + } + else + { + rightNormal = (rightEdge.isSolid) ? + Vector2.Normalize(GetEdgeNormal(rightEdge) + GetEdgeNormal(edge, cell)) : + Vector2.Normalize(rightEdge.Center - edge.point2); + } + + if (!MathUtils.IsValid(rightNormal)) + { +#if DEBUG + DebugConsole.ThrowError("Invalid right normal"); +#endif + if (cell.body != null) + { + GameMain.World.RemoveBody(cell.body); + cell.body = null; + } + rightNormal = Vector2.UnitX; + break; + } + + for (int i = 0; i < 2; i++) + { + Vector2[] verts = new Vector2[3]; + VertexPositionTexture[] vertPos = new VertexPositionTexture[3]; + + + if (i == 0) + { + verts[0] = edge.point1 - leftNormal * outWardThickness; + verts[1] = edge.point2 - rightNormal * outWardThickness; + verts[2] = edge.point1 + leftNormal * inwardThickness; + + vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), Vector2.Zero); + vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX); + vertPos[2] = new VertexPositionTexture(new Vector3(verts[2], 0.0f), new Vector2(0, 0.5f)); + } + else + { + verts[0] = edge.point1 + leftNormal * inwardThickness; + verts[1] = edge.point2 - rightNormal * outWardThickness; + verts[2] = edge.point2 + rightNormal * inwardThickness; + + vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), new Vector2(0.0f, 0.5f)); + vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX); + vertPos[2] = new VertexPositionTexture(new Vector3(verts[2], 0.0f), new Vector2(1.0f, 0.5f)); + } + + var comparer = new CompareCCW((verts[0] + verts[1] + verts[2]) / 3.0f); + Array.Sort(verts, vertPos, comparer); + + for (int j = 0; j < 3; j++) + { + verticeList.Add(vertPos[j]); + } + } + } + } + + return verticeList.ToArray(); + } + } +} diff --git a/BarotraumaClient/Source/Physics/PhysicsBody.cs b/BarotraumaClient/Source/Physics/PhysicsBody.cs index dd32fa518..e3fecd26f 100644 --- a/BarotraumaClient/Source/Physics/PhysicsBody.cs +++ b/BarotraumaClient/Source/Physics/PhysicsBody.cs @@ -11,6 +11,12 @@ namespace Barotrauma { partial class PhysicsBody { + private Texture2D bodyShapeTexture; + public Texture2D BodyShapeTexture + { + get { return bodyShapeTexture; } + } + public void Draw(SpriteBatch spriteBatch, Sprite sprite, Color color, float? depth = null, float scale = 1.0f) { if (!Enabled) return; @@ -88,5 +94,14 @@ namespace Barotrauma new Vector2(bodyShapeTexture.Width / 2, bodyShapeTexture.Height / 2), 1.0f, SpriteEffects.None, 0.0f); } + + private void DisposeProjSpecific() + { + if (bodyShapeTexture != null) + { + bodyShapeTexture.Dispose(); + bodyShapeTexture = null; + } + } } } diff --git a/BarotraumaServer/BarotraumaServer.csproj b/BarotraumaServer/BarotraumaServer.csproj index 43ed4c3a3..7a52f44c8 100644 --- a/BarotraumaServer/BarotraumaServer.csproj +++ b/BarotraumaServer/BarotraumaServer.csproj @@ -52,16 +52,9 @@ ..\BarotraumaShared\Icon.ico - - False - C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll - ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll - - False - @@ -89,20 +82,30 @@ + + + + + + + + + + - - {0aad36e3-51a5-4a07-ab60-5c8a66bd38b7} - Farseer Physics MonoGame + + {a4610e4c-dd34-428b-babb-779ca0b5993a} + Farseer Physics {3b8f9edb-6e5e-450c-abc2-ec49075d0b50} diff --git a/BarotraumaServer/Source/Camera.cs b/BarotraumaServer/Source/Camera.cs index d7aafcd3a..35d930cd5 100644 --- a/BarotraumaServer/Source/Camera.cs +++ b/BarotraumaServer/Source/Camera.cs @@ -1,6 +1,5 @@ using System; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Input; using System.Linq; //TODO: this class still does things that the server doesn't need, cleanup diff --git a/BarotraumaServer/Source/DebugConsole.cs b/BarotraumaServer/Source/DebugConsole.cs index e2c48b0bf..9ca53c56f 100644 --- a/BarotraumaServer/Source/DebugConsole.cs +++ b/BarotraumaServer/Source/DebugConsole.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using Barotrauma.Networking; using Barotrauma.Items.Components; using System.Text; diff --git a/BarotraumaServer/Source/Items/CharacterInventory.cs b/BarotraumaServer/Source/Items/CharacterInventory.cs index 0d1e32a0e..5564c4108 100644 --- a/BarotraumaServer/Source/Items/CharacterInventory.cs +++ b/BarotraumaServer/Source/Items/CharacterInventory.cs @@ -2,7 +2,6 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using Barotrauma.Networking; using Lidgren.Network; using System.Collections.Generic; diff --git a/BarotraumaServer/Source/Networking/NetworkMember.cs b/BarotraumaServer/Source/Networking/NetworkMember.cs index f4ea9e15e..960fd2909 100644 --- a/BarotraumaServer/Source/Networking/NetworkMember.cs +++ b/BarotraumaServer/Source/Networking/NetworkMember.cs @@ -2,7 +2,6 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using System.Collections.Generic; using Lidgren.Network; using Barotrauma.Items.Components; diff --git a/BarotraumaServer/Source/Physics/PhysicsBody.cs b/BarotraumaServer/Source/Physics/PhysicsBody.cs new file mode 100644 index 000000000..625f435e5 --- /dev/null +++ b/BarotraumaServer/Source/Physics/PhysicsBody.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Barotrauma +{ + partial class PhysicsBody + { + private void DisposeProjSpecific() + { + //do nothing + } + } +} diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Color.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Color.cs new file mode 100644 index 000000000..35d05167f --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Color.cs @@ -0,0 +1,1856 @@ +// MIT License - Copyright (C) The Mono.Xna Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +// Modified by juanjp600 to remove LerpPrecise, as it is not +// available in Farseer's implementation of MathHelper. + +using System; +using System.Text; +using System.Runtime.Serialization; +using System.Diagnostics; + +namespace Microsoft.Xna.Framework +{ + /// + /// Describes a 32-bit packed color. + /// + [DebuggerDisplay("{DebugDisplayString,nq}")] + public struct Color : IEquatable + { + static Color() + { + TransparentBlack = new Color(0); + Transparent = new Color(0); + AliceBlue = new Color(0xfffff8f0); + AntiqueWhite = new Color(0xffd7ebfa); + Aqua = new Color(0xffffff00); + Aquamarine = new Color(0xffd4ff7f); + Azure = new Color(0xfffffff0); + Beige = new Color(0xffdcf5f5); + Bisque = new Color(0xffc4e4ff); + Black = new Color(0xff000000); + BlanchedAlmond = new Color(0xffcdebff); + Blue = new Color(0xffff0000); + BlueViolet = new Color(0xffe22b8a); + Brown = new Color(0xff2a2aa5); + BurlyWood = new Color(0xff87b8de); + CadetBlue = new Color(0xffa09e5f); + Chartreuse = new Color(0xff00ff7f); + Chocolate = new Color(0xff1e69d2); + Coral = new Color(0xff507fff); + CornflowerBlue = new Color(0xffed9564); + Cornsilk = new Color(0xffdcf8ff); + Crimson = new Color(0xff3c14dc); + Cyan = new Color(0xffffff00); + DarkBlue = new Color(0xff8b0000); + DarkCyan = new Color(0xff8b8b00); + DarkGoldenrod = new Color(0xff0b86b8); + DarkGray = new Color(0xffa9a9a9); + DarkGreen = new Color(0xff006400); + DarkKhaki = new Color(0xff6bb7bd); + DarkMagenta = new Color(0xff8b008b); + DarkOliveGreen = new Color(0xff2f6b55); + DarkOrange = new Color(0xff008cff); + DarkOrchid = new Color(0xffcc3299); + DarkRed = new Color(0xff00008b); + DarkSalmon = new Color(0xff7a96e9); + DarkSeaGreen = new Color(0xff8bbc8f); + DarkSlateBlue = new Color(0xff8b3d48); + DarkSlateGray = new Color(0xff4f4f2f); + DarkTurquoise = new Color(0xffd1ce00); + DarkViolet = new Color(0xffd30094); + DeepPink = new Color(0xff9314ff); + DeepSkyBlue = new Color(0xffffbf00); + DimGray = new Color(0xff696969); + DodgerBlue = new Color(0xffff901e); + Firebrick = new Color(0xff2222b2); + FloralWhite = new Color(0xfff0faff); + ForestGreen = new Color(0xff228b22); + Fuchsia = new Color(0xffff00ff); + Gainsboro = new Color(0xffdcdcdc); + GhostWhite = new Color(0xfffff8f8); + Gold = new Color(0xff00d7ff); + Goldenrod = new Color(0xff20a5da); + Gray = new Color(0xff808080); + Green = new Color(0xff008000); + GreenYellow = new Color(0xff2fffad); + Honeydew = new Color(0xfff0fff0); + HotPink = new Color(0xffb469ff); + IndianRed = new Color(0xff5c5ccd); + Indigo = new Color(0xff82004b); + Ivory = new Color(0xfff0ffff); + Khaki = new Color(0xff8ce6f0); + Lavender = new Color(0xfffae6e6); + LavenderBlush = new Color(0xfff5f0ff); + LawnGreen = new Color(0xff00fc7c); + LemonChiffon = new Color(0xffcdfaff); + LightBlue = new Color(0xffe6d8ad); + LightCoral = new Color(0xff8080f0); + LightCyan = new Color(0xffffffe0); + LightGoldenrodYellow = new Color(0xffd2fafa); + LightGray = new Color(0xffd3d3d3); + LightGreen = new Color(0xff90ee90); + LightPink = new Color(0xffc1b6ff); + LightSalmon = new Color(0xff7aa0ff); + LightSeaGreen = new Color(0xffaab220); + LightSkyBlue = new Color(0xffface87); + LightSlateGray = new Color(0xff998877); + LightSteelBlue = new Color(0xffdec4b0); + LightYellow = new Color(0xffe0ffff); + Lime = new Color(0xff00ff00); + LimeGreen = new Color(0xff32cd32); + Linen = new Color(0xffe6f0fa); + Magenta = new Color(0xffff00ff); + Maroon = new Color(0xff000080); + MediumAquamarine = new Color(0xffaacd66); + MediumBlue = new Color(0xffcd0000); + MediumOrchid = new Color(0xffd355ba); + MediumPurple = new Color(0xffdb7093); + MediumSeaGreen = new Color(0xff71b33c); + MediumSlateBlue = new Color(0xffee687b); + MediumSpringGreen = new Color(0xff9afa00); + MediumTurquoise = new Color(0xffccd148); + MediumVioletRed = new Color(0xff8515c7); + MidnightBlue = new Color(0xff701919); + MintCream = new Color(0xfffafff5); + MistyRose = new Color(0xffe1e4ff); + Moccasin = new Color(0xffb5e4ff); + MonoGameOrange = new Color(0xff003ce7); + NavajoWhite = new Color(0xffaddeff); + Navy = new Color(0xff800000); + OldLace = new Color(0xffe6f5fd); + Olive = new Color(0xff008080); + OliveDrab = new Color(0xff238e6b); + Orange = new Color(0xff00a5ff); + OrangeRed = new Color(0xff0045ff); + Orchid = new Color(0xffd670da); + PaleGoldenrod = new Color(0xffaae8ee); + PaleGreen = new Color(0xff98fb98); + PaleTurquoise = new Color(0xffeeeeaf); + PaleVioletRed = new Color(0xff9370db); + PapayaWhip = new Color(0xffd5efff); + PeachPuff = new Color(0xffb9daff); + Peru = new Color(0xff3f85cd); + Pink = new Color(0xffcbc0ff); + Plum = new Color(0xffdda0dd); + PowderBlue = new Color(0xffe6e0b0); + Purple = new Color(0xff800080); + Red = new Color(0xff0000ff); + RosyBrown = new Color(0xff8f8fbc); + RoyalBlue = new Color(0xffe16941); + SaddleBrown = new Color(0xff13458b); + Salmon= new Color(0xff7280fa); + SandyBrown = new Color(0xff60a4f4); + SeaGreen = new Color(0xff578b2e); + SeaShell = new Color(0xffeef5ff); + Sienna = new Color(0xff2d52a0); + Silver = new Color(0xffc0c0c0); + SkyBlue = new Color(0xffebce87); + SlateBlue= new Color(0xffcd5a6a); + SlateGray= new Color(0xff908070); + Snow= new Color(0xfffafaff); + SpringGreen= new Color(0xff7fff00); + SteelBlue= new Color(0xffb48246); + Tan= new Color(0xff8cb4d2); + Teal= new Color(0xff808000); + Thistle= new Color(0xffd8bfd8); + Tomato= new Color(0xff4763ff); + Turquoise= new Color(0xffd0e040); + Violet= new Color(0xffee82ee); + Wheat= new Color(0xffb3def5); + White= new Color(uint.MaxValue); + WhiteSmoke= new Color(0xfff5f5f5); + Yellow = new Color(0xff00ffff); + YellowGreen = new Color(0xff32cd9a); + } + + // Stored as RGBA with R in the least significant octet: + // |-------|-------|-------|------- + // A B G R + private uint _packedValue; + + /// + /// Constructs an RGBA color from a packed value. + /// The value is a 32-bit unsigned integer, with R in the least significant octet. + /// + /// The packed value. + [CLSCompliant(false)] + public Color(uint packedValue) + { + _packedValue = packedValue; + } + + /// + /// Constructs an RGBA color from the XYZW unit length components of a vector. + /// + /// A representing color. + public Color(Vector4 color) + : this((int)(color.X * 255), (int)(color.Y * 255), (int)(color.Z * 255), (int)(color.W * 255)) + { + } + + /// + /// Constructs an RGBA color from the XYZ unit length components of a vector. Alpha value will be opaque. + /// + /// A representing color. + public Color(Vector3 color) + : this((int)(color.X * 255), (int)(color.Y * 255), (int)(color.Z * 255)) + { + } + + /// + /// Constructs an RGBA color from a and an alpha value. + /// + /// A for RGB values of new instance. + /// The alpha component value from 0 to 255. + public Color(Color color, int alpha) + { + if ((alpha & 0xFFFFFF00) != 0) + { + var clampedA = (uint)MathHelper.Clamp(alpha, Byte.MinValue, Byte.MaxValue); + + _packedValue = (color._packedValue & 0x00FFFFFF) | (clampedA << 24); + } + else + { + _packedValue = (color._packedValue & 0x00FFFFFF) | ((uint)alpha << 24); + } + } + + /// + /// Constructs an RGBA color from color and alpha value. + /// + /// A for RGB values of new instance. + /// Alpha component value from 0.0f to 1.0f. + public Color(Color color, float alpha): + this(color, (int)(alpha * 255)) + { + } + + /// + /// Constructs an RGBA color from scalars representing red, green and blue values. Alpha value will be opaque. + /// + /// Red component value from 0.0f to 1.0f. + /// Green component value from 0.0f to 1.0f. + /// Blue component value from 0.0f to 1.0f. + public Color(float r, float g, float b) + : this((int)(r * 255), (int)(g * 255), (int)(b * 255)) + { + } + + /// + /// Constructs an RGBA color from scalars representing red, green, blue and alpha values. + /// + /// Red component value from 0.0f to 1.0f. + /// Green component value from 0.0f to 1.0f. + /// Blue component value from 0.0f to 1.0f. + /// Alpha component value from 0.0f to 1.0f. + public Color(float r, float g, float b, float alpha) + : this((int)(r * 255), (int)(g * 255), (int)(b * 255), (int)(alpha * 255)) + { + } + + /// + /// Constructs an RGBA color from scalars representing red, green and blue values. Alpha value will be opaque. + /// + /// Red component value from 0 to 255. + /// Green component value from 0 to 255. + /// Blue component value from 0 to 255. + public Color(int r, int g, int b) + { + _packedValue = 0xFF000000; // A = 255 + + if (((r | g | b) & 0xFFFFFF00) != 0) + { + var clampedR = (uint)MathHelper.Clamp(r, Byte.MinValue, Byte.MaxValue); + var clampedG = (uint)MathHelper.Clamp(g, Byte.MinValue, Byte.MaxValue); + var clampedB = (uint)MathHelper.Clamp(b, Byte.MinValue, Byte.MaxValue); + + _packedValue |= (clampedB << 16) | (clampedG << 8) | (clampedR); + } + else + { + _packedValue |= ((uint)b << 16) | ((uint)g << 8) | ((uint)r); + } + } + + /// + /// Constructs an RGBA color from scalars representing red, green, blue and alpha values. + /// + /// Red component value from 0 to 255. + /// Green component value from 0 to 255. + /// Blue component value from 0 to 255. + /// Alpha component value from 0 to 255. + public Color(int r, int g, int b, int alpha) + { + if (((r | g | b | alpha) & 0xFFFFFF00) != 0) + { + var clampedR = (uint)MathHelper.Clamp(r, Byte.MinValue, Byte.MaxValue); + var clampedG = (uint)MathHelper.Clamp(g, Byte.MinValue, Byte.MaxValue); + var clampedB = (uint)MathHelper.Clamp(b, Byte.MinValue, Byte.MaxValue); + var clampedA = (uint)MathHelper.Clamp(alpha, Byte.MinValue, Byte.MaxValue); + + _packedValue = (clampedA << 24) | (clampedB << 16) | (clampedG << 8) | (clampedR); + } + else + { + _packedValue = ((uint)alpha << 24) | ((uint)b << 16) | ((uint)g << 8) | ((uint)r); + } + } + + /// + /// Constructs an RGBA color from scalars representing red, green, blue and alpha values. + /// + /// + /// This overload sets the values directly without clamping, and may therefore be faster than the other overloads. + /// + /// + /// + /// + /// + public Color(byte r, byte g, byte b, byte alpha) + { + _packedValue = ((uint)alpha << 24) | ((uint)b << 16) | ((uint)g << 8) | (r); + } + + /// + /// Gets or sets the blue component. + /// + public byte B + { + get + { + unchecked + { + return (byte) (this._packedValue >> 16); + } + } + set + { + this._packedValue = (this._packedValue & 0xff00ffff) | ((uint)value << 16); + } + } + + /// + /// Gets or sets the green component. + /// + public byte G + { + get + { + unchecked + { + return (byte)(this._packedValue >> 8); + } + } + set + { + this._packedValue = (this._packedValue & 0xffff00ff) | ((uint)value << 8); + } + } + + /// + /// Gets or sets the red component. + /// + public byte R + { + get + { + unchecked + { + return (byte) this._packedValue; + } + } + set + { + this._packedValue = (this._packedValue & 0xffffff00) | value; + } + } + + /// + /// Gets or sets the alpha component. + /// + public byte A + { + get + { + unchecked + { + return (byte)(this._packedValue >> 24); + } + } + set + { + this._packedValue = (this._packedValue & 0x00ffffff) | ((uint)value << 24); + } + } + + /// + /// Compares whether two instances are equal. + /// + /// instance on the left of the equal sign. + /// instance on the right of the equal sign. + /// true if the instances are equal; false otherwise. + public static bool operator ==(Color a, Color b) + { + return (a._packedValue == b._packedValue); + } + + /// + /// Compares whether two instances are not equal. + /// + /// instance on the left of the not equal sign. + /// instance on the right of the not equal sign. + /// true if the instances are not equal; false otherwise. + public static bool operator !=(Color a, Color b) + { + return (a._packedValue != b._packedValue); + } + + /// + /// Gets the hash code of this . + /// + /// Hash code of this . + public override int GetHashCode() + { + return this._packedValue.GetHashCode(); + } + + /// + /// Compares whether current instance is equal to specified object. + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public override bool Equals(object obj) + { + return ((obj is Color) && this.Equals((Color)obj)); + } + + #region Color Bank + /// + /// TransparentBlack color (R:0,G:0,B:0,A:0). + /// + public static Color TransparentBlack + { + get; + private set; + } + + /// + /// Transparent color (R:0,G:0,B:0,A:0). + /// + public static Color Transparent + { + get; + private set; + } + + /// + /// AliceBlue color (R:240,G:248,B:255,A:255). + /// + public static Color AliceBlue + { + get; + private set; + } + + /// + /// AntiqueWhite color (R:250,G:235,B:215,A:255). + /// + public static Color AntiqueWhite + { + get; + private set; + } + + /// + /// Aqua color (R:0,G:255,B:255,A:255). + /// + public static Color Aqua + { + get; + private set; + } + + /// + /// Aquamarine color (R:127,G:255,B:212,A:255). + /// + public static Color Aquamarine + { + get; + private set; + } + + /// + /// Azure color (R:240,G:255,B:255,A:255). + /// + public static Color Azure + { + get; + private set; + } + + /// + /// Beige color (R:245,G:245,B:220,A:255). + /// + public static Color Beige + { + get; + private set; + } + + /// + /// Bisque color (R:255,G:228,B:196,A:255). + /// + public static Color Bisque + { + get; + private set; + } + + /// + /// Black color (R:0,G:0,B:0,A:255). + /// + public static Color Black + { + get; + private set; + } + + /// + /// BlanchedAlmond color (R:255,G:235,B:205,A:255). + /// + public static Color BlanchedAlmond + { + get; + private set; + } + + /// + /// Blue color (R:0,G:0,B:255,A:255). + /// + public static Color Blue + { + get; + private set; + } + + /// + /// BlueViolet color (R:138,G:43,B:226,A:255). + /// + public static Color BlueViolet + { + get; + private set; + } + + /// + /// Brown color (R:165,G:42,B:42,A:255). + /// + public static Color Brown + { + get; + private set; + } + + /// + /// BurlyWood color (R:222,G:184,B:135,A:255). + /// + public static Color BurlyWood + { + get; + private set; + } + + /// + /// CadetBlue color (R:95,G:158,B:160,A:255). + /// + public static Color CadetBlue + { + get; + private set; + } + + /// + /// Chartreuse color (R:127,G:255,B:0,A:255). + /// + public static Color Chartreuse + { + get; + private set; + } + + /// + /// Chocolate color (R:210,G:105,B:30,A:255). + /// + public static Color Chocolate + { + get; + private set; + } + + /// + /// Coral color (R:255,G:127,B:80,A:255). + /// + public static Color Coral + { + get; + private set; + } + + /// + /// CornflowerBlue color (R:100,G:149,B:237,A:255). + /// + public static Color CornflowerBlue + { + get; + private set; + } + + /// + /// Cornsilk color (R:255,G:248,B:220,A:255). + /// + public static Color Cornsilk + { + get; + private set; + } + + /// + /// Crimson color (R:220,G:20,B:60,A:255). + /// + public static Color Crimson + { + get; + private set; + } + + /// + /// Cyan color (R:0,G:255,B:255,A:255). + /// + public static Color Cyan + { + get; + private set; + } + + /// + /// DarkBlue color (R:0,G:0,B:139,A:255). + /// + public static Color DarkBlue + { + get; + private set; + } + + /// + /// DarkCyan color (R:0,G:139,B:139,A:255). + /// + public static Color DarkCyan + { + get; + private set; + } + + /// + /// DarkGoldenrod color (R:184,G:134,B:11,A:255). + /// + public static Color DarkGoldenrod + { + get; + private set; + } + + /// + /// DarkGray color (R:169,G:169,B:169,A:255). + /// + public static Color DarkGray + { + get; + private set; + } + + /// + /// DarkGreen color (R:0,G:100,B:0,A:255). + /// + public static Color DarkGreen + { + get; + private set; + } + + /// + /// DarkKhaki color (R:189,G:183,B:107,A:255). + /// + public static Color DarkKhaki + { + get; + private set; + } + + /// + /// DarkMagenta color (R:139,G:0,B:139,A:255). + /// + public static Color DarkMagenta + { + get; + private set; + } + + /// + /// DarkOliveGreen color (R:85,G:107,B:47,A:255). + /// + public static Color DarkOliveGreen + { + get; + private set; + } + + /// + /// DarkOrange color (R:255,G:140,B:0,A:255). + /// + public static Color DarkOrange + { + get; + private set; + } + + /// + /// DarkOrchid color (R:153,G:50,B:204,A:255). + /// + public static Color DarkOrchid + { + get; + private set; + } + + /// + /// DarkRed color (R:139,G:0,B:0,A:255). + /// + public static Color DarkRed + { + get; + private set; + } + + /// + /// DarkSalmon color (R:233,G:150,B:122,A:255). + /// + public static Color DarkSalmon + { + get; + private set; + } + + /// + /// DarkSeaGreen color (R:143,G:188,B:139,A:255). + /// + public static Color DarkSeaGreen + { + get; + private set; + } + + /// + /// DarkSlateBlue color (R:72,G:61,B:139,A:255). + /// + public static Color DarkSlateBlue + { + get; + private set; + } + + /// + /// DarkSlateGray color (R:47,G:79,B:79,A:255). + /// + public static Color DarkSlateGray + { + get; + private set; + } + + /// + /// DarkTurquoise color (R:0,G:206,B:209,A:255). + /// + public static Color DarkTurquoise + { + get; + private set; + } + + /// + /// DarkViolet color (R:148,G:0,B:211,A:255). + /// + public static Color DarkViolet + { + get; + private set; + } + + /// + /// DeepPink color (R:255,G:20,B:147,A:255). + /// + public static Color DeepPink + { + get; + private set; + } + + /// + /// DeepSkyBlue color (R:0,G:191,B:255,A:255). + /// + public static Color DeepSkyBlue + { + get; + private set; + } + + /// + /// DimGray color (R:105,G:105,B:105,A:255). + /// + public static Color DimGray + { + get; + private set; + } + + /// + /// DodgerBlue color (R:30,G:144,B:255,A:255). + /// + public static Color DodgerBlue + { + get; + private set; + } + + /// + /// Firebrick color (R:178,G:34,B:34,A:255). + /// + public static Color Firebrick + { + get; + private set; + } + + /// + /// FloralWhite color (R:255,G:250,B:240,A:255). + /// + public static Color FloralWhite + { + get; + private set; + } + + /// + /// ForestGreen color (R:34,G:139,B:34,A:255). + /// + public static Color ForestGreen + { + get; + private set; + } + + /// + /// Fuchsia color (R:255,G:0,B:255,A:255). + /// + public static Color Fuchsia + { + get; + private set; + } + + /// + /// Gainsboro color (R:220,G:220,B:220,A:255). + /// + public static Color Gainsboro + { + get; + private set; + } + + /// + /// GhostWhite color (R:248,G:248,B:255,A:255). + /// + public static Color GhostWhite + { + get; + private set; + } + /// + /// Gold color (R:255,G:215,B:0,A:255). + /// + public static Color Gold + { + get; + private set; + } + + /// + /// Goldenrod color (R:218,G:165,B:32,A:255). + /// + public static Color Goldenrod + { + get; + private set; + } + + /// + /// Gray color (R:128,G:128,B:128,A:255). + /// + public static Color Gray + { + get; + private set; + } + + /// + /// Green color (R:0,G:128,B:0,A:255). + /// + public static Color Green + { + get; + private set; + } + + /// + /// GreenYellow color (R:173,G:255,B:47,A:255). + /// + public static Color GreenYellow + { + get; + private set; + } + + /// + /// Honeydew color (R:240,G:255,B:240,A:255). + /// + public static Color Honeydew + { + get; + private set; + } + + /// + /// HotPink color (R:255,G:105,B:180,A:255). + /// + public static Color HotPink + { + get; + private set; + } + + /// + /// IndianRed color (R:205,G:92,B:92,A:255). + /// + public static Color IndianRed + { + get; + private set; + } + + /// + /// Indigo color (R:75,G:0,B:130,A:255). + /// + public static Color Indigo + { + get; + private set; + } + + /// + /// Ivory color (R:255,G:255,B:240,A:255). + /// + public static Color Ivory + { + get; + private set; + } + + /// + /// Khaki color (R:240,G:230,B:140,A:255). + /// + public static Color Khaki + { + get; + private set; + } + + /// + /// Lavender color (R:230,G:230,B:250,A:255). + /// + public static Color Lavender + { + get; + private set; + } + + /// + /// LavenderBlush color (R:255,G:240,B:245,A:255). + /// + public static Color LavenderBlush + { + get; + private set; + } + + /// + /// LawnGreen color (R:124,G:252,B:0,A:255). + /// + public static Color LawnGreen + { + get; + private set; + } + + /// + /// LemonChiffon color (R:255,G:250,B:205,A:255). + /// + public static Color LemonChiffon + { + get; + private set; + } + + /// + /// LightBlue color (R:173,G:216,B:230,A:255). + /// + public static Color LightBlue + { + get; + private set; + } + + /// + /// LightCoral color (R:240,G:128,B:128,A:255). + /// + public static Color LightCoral + { + get; + private set; + } + + /// + /// LightCyan color (R:224,G:255,B:255,A:255). + /// + public static Color LightCyan + { + get; + private set; + } + + /// + /// LightGoldenrodYellow color (R:250,G:250,B:210,A:255). + /// + public static Color LightGoldenrodYellow + { + get; + private set; + } + + /// + /// LightGray color (R:211,G:211,B:211,A:255). + /// + public static Color LightGray + { + get; + private set; + } + + /// + /// LightGreen color (R:144,G:238,B:144,A:255). + /// + public static Color LightGreen + { + get; + private set; + } + + /// + /// LightPink color (R:255,G:182,B:193,A:255). + /// + public static Color LightPink + { + get; + private set; + } + + /// + /// LightSalmon color (R:255,G:160,B:122,A:255). + /// + public static Color LightSalmon + { + get; + private set; + } + + /// + /// LightSeaGreen color (R:32,G:178,B:170,A:255). + /// + public static Color LightSeaGreen + { + get; + private set; + } + + /// + /// LightSkyBlue color (R:135,G:206,B:250,A:255). + /// + public static Color LightSkyBlue + { + get; + private set; + } + + /// + /// LightSlateGray color (R:119,G:136,B:153,A:255). + /// + public static Color LightSlateGray + { + get; + private set; + } + + /// + /// LightSteelBlue color (R:176,G:196,B:222,A:255). + /// + public static Color LightSteelBlue + { + get; + private set; + } + + /// + /// LightYellow color (R:255,G:255,B:224,A:255). + /// + public static Color LightYellow + { + get; + private set; + } + + /// + /// Lime color (R:0,G:255,B:0,A:255). + /// + public static Color Lime + { + get; + private set; + } + + /// + /// LimeGreen color (R:50,G:205,B:50,A:255). + /// + public static Color LimeGreen + { + get; + private set; + } + + /// + /// Linen color (R:250,G:240,B:230,A:255). + /// + public static Color Linen + { + get; + private set; + } + + /// + /// Magenta color (R:255,G:0,B:255,A:255). + /// + public static Color Magenta + { + get; + private set; + } + + /// + /// Maroon color (R:128,G:0,B:0,A:255). + /// + public static Color Maroon + { + get; + private set; + } + + /// + /// MediumAquamarine color (R:102,G:205,B:170,A:255). + /// + public static Color MediumAquamarine + { + get; + private set; + } + + /// + /// MediumBlue color (R:0,G:0,B:205,A:255). + /// + public static Color MediumBlue + { + get; + private set; + } + + /// + /// MediumOrchid color (R:186,G:85,B:211,A:255). + /// + public static Color MediumOrchid + { + get; + private set; + } + + /// + /// MediumPurple color (R:147,G:112,B:219,A:255). + /// + public static Color MediumPurple + { + get; + private set; + } + + /// + /// MediumSeaGreen color (R:60,G:179,B:113,A:255). + /// + public static Color MediumSeaGreen + { + get; + private set; + } + + /// + /// MediumSlateBlue color (R:123,G:104,B:238,A:255). + /// + public static Color MediumSlateBlue + { + get; + private set; + } + + /// + /// MediumSpringGreen color (R:0,G:250,B:154,A:255). + /// + public static Color MediumSpringGreen + { + get; + private set; + } + + /// + /// MediumTurquoise color (R:72,G:209,B:204,A:255). + /// + public static Color MediumTurquoise + { + get; + private set; + } + + /// + /// MediumVioletRed color (R:199,G:21,B:133,A:255). + /// + public static Color MediumVioletRed + { + get; + private set; + } + + /// + /// MidnightBlue color (R:25,G:25,B:112,A:255). + /// + public static Color MidnightBlue + { + get; + private set; + } + + /// + /// MintCream color (R:245,G:255,B:250,A:255). + /// + public static Color MintCream + { + get; + private set; + } + + /// + /// MistyRose color (R:255,G:228,B:225,A:255). + /// + public static Color MistyRose + { + get; + private set; + } + + /// + /// Moccasin color (R:255,G:228,B:181,A:255). + /// + public static Color Moccasin + { + get; + private set; + } + + /// + /// MonoGame orange theme color (R:231,G:60,B:0,A:255). + /// + public static Color MonoGameOrange + { + get; + private set; + } + + /// + /// NavajoWhite color (R:255,G:222,B:173,A:255). + /// + public static Color NavajoWhite + { + get; + private set; + } + + /// + /// Navy color (R:0,G:0,B:128,A:255). + /// + public static Color Navy + { + get; + private set; + } + + /// + /// OldLace color (R:253,G:245,B:230,A:255). + /// + public static Color OldLace + { + get; + private set; + } + + /// + /// Olive color (R:128,G:128,B:0,A:255). + /// + public static Color Olive + { + get; + private set; + } + + /// + /// OliveDrab color (R:107,G:142,B:35,A:255). + /// + public static Color OliveDrab + { + get; + private set; + } + + /// + /// Orange color (R:255,G:165,B:0,A:255). + /// + public static Color Orange + { + get; + private set; + } + + /// + /// OrangeRed color (R:255,G:69,B:0,A:255). + /// + public static Color OrangeRed + { + get; + private set; + } + + /// + /// Orchid color (R:218,G:112,B:214,A:255). + /// + public static Color Orchid + { + get; + private set; + } + + /// + /// PaleGoldenrod color (R:238,G:232,B:170,A:255). + /// + public static Color PaleGoldenrod + { + get; + private set; + } + + /// + /// PaleGreen color (R:152,G:251,B:152,A:255). + /// + public static Color PaleGreen + { + get; + private set; + } + + /// + /// PaleTurquoise color (R:175,G:238,B:238,A:255). + /// + public static Color PaleTurquoise + { + get; + private set; + } + /// + /// PaleVioletRed color (R:219,G:112,B:147,A:255). + /// + public static Color PaleVioletRed + { + get; + private set; + } + + /// + /// PapayaWhip color (R:255,G:239,B:213,A:255). + /// + public static Color PapayaWhip + { + get; + private set; + } + + /// + /// PeachPuff color (R:255,G:218,B:185,A:255). + /// + public static Color PeachPuff + { + get; + private set; + } + + /// + /// Peru color (R:205,G:133,B:63,A:255). + /// + public static Color Peru + { + get; + private set; + } + + /// + /// Pink color (R:255,G:192,B:203,A:255). + /// + public static Color Pink + { + get; + private set; + } + + /// + /// Plum color (R:221,G:160,B:221,A:255). + /// + public static Color Plum + { + get; + private set; + } + + /// + /// PowderBlue color (R:176,G:224,B:230,A:255). + /// + public static Color PowderBlue + { + get; + private set; + } + + /// + /// Purple color (R:128,G:0,B:128,A:255). + /// + public static Color Purple + { + get; + private set; + } + + /// + /// Red color (R:255,G:0,B:0,A:255). + /// + public static Color Red + { + get; + private set; + } + + /// + /// RosyBrown color (R:188,G:143,B:143,A:255). + /// + public static Color RosyBrown + { + get; + private set; + } + + /// + /// RoyalBlue color (R:65,G:105,B:225,A:255). + /// + public static Color RoyalBlue + { + get; + private set; + } + + /// + /// SaddleBrown color (R:139,G:69,B:19,A:255). + /// + public static Color SaddleBrown + { + get; + private set; + } + + /// + /// Salmon color (R:250,G:128,B:114,A:255). + /// + public static Color Salmon + { + get; + private set; + } + + /// + /// SandyBrown color (R:244,G:164,B:96,A:255). + /// + public static Color SandyBrown + { + get; + private set; + } + + /// + /// SeaGreen color (R:46,G:139,B:87,A:255). + /// + public static Color SeaGreen + { + get; + private set; + } + + /// + /// SeaShell color (R:255,G:245,B:238,A:255). + /// + public static Color SeaShell + { + get; + private set; + } + + /// + /// Sienna color (R:160,G:82,B:45,A:255). + /// + public static Color Sienna + { + get; + private set; + } + + /// + /// Silver color (R:192,G:192,B:192,A:255). + /// + public static Color Silver + { + get; + private set; + } + + /// + /// SkyBlue color (R:135,G:206,B:235,A:255). + /// + public static Color SkyBlue + { + get; + private set; + } + + /// + /// SlateBlue color (R:106,G:90,B:205,A:255). + /// + public static Color SlateBlue + { + get; + private set; + } + + /// + /// SlateGray color (R:112,G:128,B:144,A:255). + /// + public static Color SlateGray + { + get; + private set; + } + + /// + /// Snow color (R:255,G:250,B:250,A:255). + /// + public static Color Snow + { + get; + private set; + } + + /// + /// SpringGreen color (R:0,G:255,B:127,A:255). + /// + public static Color SpringGreen + { + get; + private set; + } + + /// + /// SteelBlue color (R:70,G:130,B:180,A:255). + /// + public static Color SteelBlue + { + get; + private set; + } + + /// + /// Tan color (R:210,G:180,B:140,A:255). + /// + public static Color Tan + { + get; + private set; + } + + /// + /// Teal color (R:0,G:128,B:128,A:255). + /// + public static Color Teal + { + get; + private set; + } + + /// + /// Thistle color (R:216,G:191,B:216,A:255). + /// + public static Color Thistle + { + get; + private set; + } + + /// + /// Tomato color (R:255,G:99,B:71,A:255). + /// + public static Color Tomato + { + get; + private set; + } + + /// + /// Turquoise color (R:64,G:224,B:208,A:255). + /// + public static Color Turquoise + { + get; + private set; + } + + /// + /// Violet color (R:238,G:130,B:238,A:255). + /// + public static Color Violet + { + get; + private set; + } + + /// + /// Wheat color (R:245,G:222,B:179,A:255). + /// + public static Color Wheat + { + get; + private set; + } + + /// + /// White color (R:255,G:255,B:255,A:255). + /// + public static Color White + { + get; + private set; + } + + /// + /// WhiteSmoke color (R:245,G:245,B:245,A:255). + /// + public static Color WhiteSmoke + { + get; + private set; + } + + /// + /// Yellow color (R:255,G:255,B:0,A:255). + /// + public static Color Yellow + { + get; + private set; + } + + /// + /// YellowGreen color (R:154,G:205,B:50,A:255). + /// + public static Color YellowGreen + { + get; + private set; + } + #endregion + + /// + /// Performs linear interpolation of . + /// + /// Source . + /// Destination . + /// Interpolation factor. + /// Interpolated . + public static Color Lerp(Color value1, Color value2, Single amount) + { + amount = MathHelper.Clamp(amount, 0, 1); + return new Color( + (int)MathHelper.Lerp(value1.R, value2.R, amount), + (int)MathHelper.Lerp(value1.G, value2.G, amount), + (int)MathHelper.Lerp(value1.B, value2.B, amount), + (int)MathHelper.Lerp(value1.A, value2.A, amount) ); + } + + /// + /// Multiply by value. + /// + /// Source . + /// Multiplicator. + /// Multiplication result. + public static Color Multiply(Color value, float scale) + { + return new Color((int)(value.R * scale), (int)(value.G * scale), (int)(value.B * scale), (int)(value.A * scale)); + } + + /// + /// Multiply by value. + /// + /// Source . + /// Multiplicator. + /// Multiplication result. + public static Color operator *(Color value, float scale) + { + return new Color((int)(value.R * scale), (int)(value.G * scale), (int)(value.B * scale), (int)(value.A * scale)); + } + + /// + /// Gets a representation for this object. + /// + /// A representation for this object. + public Vector3 ToVector3() + { + return new Vector3(R / 255.0f, G / 255.0f, B / 255.0f); + } + + /// + /// Gets a representation for this object. + /// + /// A representation for this object. + public Vector4 ToVector4() + { + return new Vector4(R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f); + } + + /// + /// Gets or sets packed value of this . + /// + [CLSCompliant(false)] + public UInt32 PackedValue + { + get { return _packedValue; } + set { _packedValue = value; } + } + + + internal string DebugDisplayString + { + get + { + return string.Concat( + this.R.ToString(), " ", + this.G.ToString(), " ", + this.B.ToString(), " ", + this.A.ToString() + ); + } + } + + + /// + /// Returns a representation of this in the format: + /// {R:[red] G:[green] B:[blue] A:[alpha]} + /// + /// representation of this . + public override string ToString () + { + StringBuilder sb = new StringBuilder(25); + sb.Append("{R:"); + sb.Append(R); + sb.Append(" G:"); + sb.Append(G); + sb.Append(" B:"); + sb.Append(B); + sb.Append(" A:"); + sb.Append(A); + sb.Append("}"); + return sb.ToString(); + } + + /// + /// Translate a non-premultipled alpha to a that contains premultiplied alpha. + /// + /// A representing color. + /// A which contains premultiplied alpha data. + public static Color FromNonPremultiplied(Vector4 vector) + { + return new Color(vector.X * vector.W, vector.Y * vector.W, vector.Z * vector.W, vector.W); + } + + /// + /// Translate a non-premultipled alpha to a that contains premultiplied alpha. + /// + /// Red component value. + /// Green component value. + /// Blue component value. + /// Alpha component value. + /// A which contains premultiplied alpha data. + public static Color FromNonPremultiplied(int r, int g, int b, int a) + { + return new Color(r * a / 255, g * a / 255, b * a / 255, a); + } + + #region IEquatable Members + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public bool Equals(Color other) + { + return this.PackedValue == other.PackedValue; + } + + #endregion + } +} diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Graphics/SpriteEffects.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Graphics/SpriteEffects.cs new file mode 100644 index 000000000..10937c51c --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Graphics/SpriteEffects.cs @@ -0,0 +1,28 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System; + +namespace Microsoft.Xna.Framework.Graphics +{ + /// + /// Defines sprite visual options for mirroring. + /// + [Flags] + public enum SpriteEffects + { + /// + /// No options specified. + /// + None = 0, + /// + /// Render the sprite reversed along the X axis. + /// + FlipHorizontally = 1, + /// + /// Render the sprite reversed along the Y axis. + /// + FlipVertically = 2 + } +} \ No newline at end of file diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyState.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyState.cs new file mode 100644 index 000000000..5bba7b39a --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyState.cs @@ -0,0 +1,58 @@ +#region License +// /* +// Microsoft Public License (Ms-PL) +// MonoGame - Copyright © 2009 The MonoGame Team +// +// All rights reserved. +// +// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not +// accept the license, do not use the software. +// +// 1. Definitions +// The terms "reproduce, " "reproduction, " "derivative works, " and "distribution" have the same meaning here as under +// U.S. copyright law. +// +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2. Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, +// each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, +// each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. +// +// 3. Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, +// your patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object +// code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent +// permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular +// purpose and non-infringement. +// */ +#endregion License + +namespace Microsoft.Xna.Framework.Input +{ + /// + /// Identifies the state of a keyboard key. + /// + public enum KeyState + { + /// + /// Key is released. + /// + Up, + + /// + /// Key is pressed. + /// + Down, + } +} diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyboardState.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyboardState.cs new file mode 100644 index 000000000..dd78935b6 --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Input/KeyboardState.cs @@ -0,0 +1,303 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System.Collections.Generic; + +namespace Microsoft.Xna.Framework.Input +{ + /// + /// Holds the state of keystrokes by a keyboard. + /// + public struct KeyboardState + { + // Used for the common situation where GetPressedKeys will return an empty array + static Keys[] empty = new Keys[0]; + + #region Key Data + + // Array of 256 bits: + uint keys0, keys1, keys2, keys3, keys4, keys5, keys6, keys7; + + bool InternalGetKey(Keys key) + { + uint mask = (uint)1 << (((int)key) & 0x1f); + + uint element; + switch (((int)key) >> 5) + { + case 0: element = keys0; break; + case 1: element = keys1; break; + case 2: element = keys2; break; + case 3: element = keys3; break; + case 4: element = keys4; break; + case 5: element = keys5; break; + case 6: element = keys6; break; + case 7: element = keys7; break; + default: element = 0; break; + } + + return (element & mask) != 0; + } + + void InternalSetKey(Keys key) + { + uint mask = (uint)1 << (((int)key) & 0x1f); + switch (((int)key) >> 5) + { + case 0: keys0 |= mask; break; + case 1: keys1 |= mask; break; + case 2: keys2 |= mask; break; + case 3: keys3 |= mask; break; + case 4: keys4 |= mask; break; + case 5: keys5 |= mask; break; + case 6: keys6 |= mask; break; + case 7: keys7 |= mask; break; + } + } + + void InternalClearKey(Keys key) + { + uint mask = (uint)1 << (((int)key) & 0x1f); + switch (((int)key) >> 5) + { + case 0: keys0 &= ~mask; break; + case 1: keys1 &= ~mask; break; + case 2: keys2 &= ~mask; break; + case 3: keys3 &= ~mask; break; + case 4: keys4 &= ~mask; break; + case 5: keys5 &= ~mask; break; + case 6: keys6 &= ~mask; break; + case 7: keys7 &= ~mask; break; + } + } + + void InternalClearAllKeys() + { + keys0 = 0; + keys1 = 0; + keys2 = 0; + keys3 = 0; + keys4 = 0; + keys5 = 0; + keys6 = 0; + keys7 = 0; + } + + #endregion + + + #region XNA Interface + + /// + /// Gets the current state of the Caps Lock key. + /// + public bool CapsLock { get; private set; } + + /// + /// Gets the current state of the Num Lock key. + /// + public bool NumLock { get; private set; } + + internal KeyboardState(List keys, bool capsLock = false, bool numLock = false) : this() + { + CapsLock = capsLock; + NumLock = numLock; + + keys0 = 0; + keys1 = 0; + keys2 = 0; + keys3 = 0; + keys4 = 0; + keys5 = 0; + keys6 = 0; + keys7 = 0; + + if (keys != null) + foreach (Keys k in keys) + InternalSetKey(k); + } + + /// + /// Initializes a new instance of the class. + /// + /// List of keys to be flagged as pressed on initialization. + /// Caps Lock state. + /// Num Lock state. + public KeyboardState(Keys[] keys, bool capsLock = false, bool numLock = false) : this() + { + CapsLock = capsLock; + NumLock = numLock; + + keys0 = 0; + keys1 = 0; + keys2 = 0; + keys3 = 0; + keys4 = 0; + keys5 = 0; + keys6 = 0; + keys7 = 0; + + if (keys != null) + foreach (Keys k in keys) + InternalSetKey(k); + } + + /// + /// Initializes a new instance of the class. + /// + /// List of keys to be flagged as pressed on initialization. + public KeyboardState(params Keys[] keys) : this() + { + CapsLock = false; + NumLock = false; + + keys0 = 0; + keys1 = 0; + keys2 = 0; + keys3 = 0; + keys4 = 0; + keys5 = 0; + keys6 = 0; + keys7 = 0; + + if (keys != null) + foreach (Keys k in keys) + InternalSetKey(k); + } + + /// + /// Returns the state of a specified key. + /// + /// The key to query. + /// The state of the key. + public KeyState this[Keys key] + { + get { return InternalGetKey(key) ? KeyState.Down : KeyState.Up; } + } + + /// + /// Gets whether given key is currently being pressed. + /// + /// The key to query. + /// true if the key is pressed; false otherwise. + public bool IsKeyDown(Keys key) + { + return InternalGetKey(key); + } + + /// + /// Gets whether given key is currently being not pressed. + /// + /// The key to query. + /// true if the key is not pressed; false otherwise. + public bool IsKeyUp(Keys key) + { + return !InternalGetKey(key); + } + + #endregion + + + #region GetPressedKeys() + + private static uint CountBits(uint v) + { + // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel + v = v - ((v >> 1) & 0x55555555); // reuse input as temporary + v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp + return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count + } + + private static int AddKeysToArray(uint keys, int offset, Keys[] pressedKeys, int index) + { + for (int i = 0; i < 32; i++) + { + if ((keys & (1 << i)) != 0) + pressedKeys[index++] = (Keys)(offset + i); + } + return index; + } + + /// + /// Returns an array of values holding keys that are currently being pressed. + /// + /// The keys that are currently being pressed. + public Keys[] GetPressedKeys() + { + uint count = CountBits(keys0) + CountBits(keys1) + CountBits(keys2) + CountBits(keys3) + + CountBits(keys4) + CountBits(keys5) + CountBits(keys6) + CountBits(keys7); + if (count == 0) + return empty; + Keys[] keys = new Keys[count]; + + int index = 0; + if (keys0 != 0) index = AddKeysToArray(keys0, 0 * 32, keys, index); + if (keys1 != 0) index = AddKeysToArray(keys1, 1 * 32, keys, index); + if (keys2 != 0) index = AddKeysToArray(keys2, 2 * 32, keys, index); + if (keys3 != 0) index = AddKeysToArray(keys3, 3 * 32, keys, index); + if (keys4 != 0) index = AddKeysToArray(keys4, 4 * 32, keys, index); + if (keys5 != 0) index = AddKeysToArray(keys5, 5 * 32, keys, index); + if (keys6 != 0) index = AddKeysToArray(keys6, 6 * 32, keys, index); + if (keys7 != 0) index = AddKeysToArray(keys7, 7 * 32, keys, index); + + return keys; + } + + #endregion + + + #region Objet and Equality + + /// + /// Gets the hash code for instance. + /// + /// Hash code of the object. + public override int GetHashCode() + { + return (int)(keys0 ^ keys1 ^ keys2 ^ keys3 ^ keys4 ^ keys5 ^ keys6 ^ keys7); + } + + /// + /// Compares whether two instances are equal. + /// + /// instance to the left of the equality operator. + /// instance to the right of the equality operator. + /// true if the instances are equal; false otherwise. + public static bool operator ==(KeyboardState a, KeyboardState b) + { + return a.keys0 == b.keys0 + && a.keys1 == b.keys1 + && a.keys2 == b.keys2 + && a.keys3 == b.keys3 + && a.keys4 == b.keys4 + && a.keys5 == b.keys5 + && a.keys6 == b.keys6 + && a.keys7 == b.keys7; + } + + /// + /// Compares whether two instances are not equal. + /// + /// instance to the left of the inequality operator. + /// instance to the right of the inequality operator. + /// true if the instances are different; false otherwise. + public static bool operator !=(KeyboardState a, KeyboardState b) + { + return !(a == b); + } + + /// + /// Compares whether current instance is equal to specified object. + /// + /// The to compare. + /// true if the provided instance is same with current; false otherwise. + public override bool Equals(object obj) + { + return obj is KeyboardState && this == (KeyboardState)obj; + } + + #endregion + + } +} diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Input/Keys.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Input/Keys.cs new file mode 100644 index 000000000..5420cd52a --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Input/Keys.cs @@ -0,0 +1,653 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +namespace Microsoft.Xna.Framework.Input +{ + /// + /// Defines the keys on a keyboard. + /// + public enum Keys + { + /// + /// Reserved. + /// + None = 0, + /// + /// BACKSPACE key. + /// + Back = 8, + /// + /// TAB key. + /// + Tab = 9, + /// + /// ENTER key. + /// + Enter = 13, + /// + /// CAPS LOCK key. + /// + CapsLock = 20, + /// + /// ESC key. + /// + Escape = 27, + /// + /// SPACEBAR key. + /// + Space = 32, + /// + /// PAGE UP key. + /// + PageUp = 33, + /// + /// PAGE DOWN key. + /// + PageDown = 34, + /// + /// END key. + /// + End = 35, + /// + /// HOME key. + /// + Home = 36, + /// + /// LEFT ARROW key. + /// + Left = 37, + /// + /// UP ARROW key. + /// + Up = 38, + /// + /// RIGHT ARROW key. + /// + Right = 39, + /// + /// DOWN ARROW key. + /// + Down = 40, + /// + /// SELECT key. + /// + Select = 41, + /// + /// PRINT key. + /// + Print = 42, + /// + /// EXECUTE key. + /// + Execute = 43, + /// + /// PRINT SCREEN key. + /// + PrintScreen = 44, + /// + /// INS key. + /// + Insert = 45, + /// + /// DEL key. + /// + Delete = 46, + /// + /// HELP key. + /// + Help = 47, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D0 = 48, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D1 = 49, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D2 = 50, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D3 = 51, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D4 = 52, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D5 = 53, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D6 = 54, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D7 = 55, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D8 = 56, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + D9 = 57, + /// + /// A key. + /// + A = 65, + /// + /// B key. + /// + B = 66, + /// + /// C key. + /// + C = 67, + /// + /// D key. + /// + D = 68, + /// + /// E key. + /// + E = 69, + /// + /// F key. + /// + F = 70, + /// + /// G key. + /// + G = 71, + /// + /// H key. + /// + H = 72, + /// + /// I key. + /// + I = 73, + /// + /// J key. + /// + J = 74, + /// + /// K key. + /// + K = 75, + /// + /// L key. + /// + L = 76, + /// + /// M key. + /// + M = 77, + /// + /// N key. + /// + N = 78, + /// + /// O key. + /// + O = 79, + /// + /// P key. + /// + P = 80, + /// + /// Q key. + /// + Q = 81, + /// + /// R key. + /// + R = 82, + /// + /// S key. + /// + S = 83, + /// + /// T key. + /// + T = 84, + /// + /// U key. + /// + U = 85, + /// + /// V key. + /// + V = 86, + /// + /// W key. + /// + W = 87, + /// + /// X key. + /// + X = 88, + /// + /// Y key. + /// + Y = 89, + /// + /// Z key. + /// + Z = 90, + /// + /// Left Windows key. + /// + LeftWindows = 91, + /// + /// Right Windows key. + /// + RightWindows = 92, + /// + /// Applications key. + /// + Apps = 93, + /// + /// Computer Sleep key. + /// + Sleep = 95, + /// + /// Numeric keypad 0 key. + /// + NumPad0 = 96, + /// + /// Numeric keypad 1 key. + /// + NumPad1 = 97, + /// + /// Numeric keypad 2 key. + /// + NumPad2 = 98, + /// + /// Numeric keypad 3 key. + /// + NumPad3 = 99, + /// + /// Numeric keypad 4 key. + /// + NumPad4 = 100, + /// + /// Numeric keypad 5 key. + /// + NumPad5 = 101, + /// + /// Numeric keypad 6 key. + /// + NumPad6 = 102, + /// + /// Numeric keypad 7 key. + /// + NumPad7 = 103, + /// + /// Numeric keypad 8 key. + /// + NumPad8 = 104, + /// + /// Numeric keypad 9 key. + /// + NumPad9 = 105, + /// + /// Multiply key. + /// + Multiply = 106, + /// + /// Add key. + /// + Add = 107, + /// + /// Separator key. + /// + Separator = 108, + /// + /// Subtract key. + /// + Subtract = 109, + /// + /// Decimal key. + /// + Decimal = 110, + /// + /// Divide key. + /// + Divide = 111, + /// + /// F1 key. + /// + F1 = 112, + /// + /// F2 key. + /// + F2 = 113, + /// + /// F3 key. + /// + F3 = 114, + /// + /// F4 key. + /// + F4 = 115, + /// + /// F5 key. + /// + F5 = 116, + /// + /// F6 key. + /// + F6 = 117, + /// + /// F7 key. + /// + F7 = 118, + /// + /// F8 key. + /// + F8 = 119, + /// + /// F9 key. + /// + F9 = 120, + /// + /// F10 key. + /// + F10 = 121, + /// + /// F11 key. + /// + F11 = 122, + /// + /// F12 key. + /// + F12 = 123, + /// + /// F13 key. + /// + F13 = 124, + /// + /// F14 key. + /// + F14 = 125, + /// + /// F15 key. + /// + F15 = 126, + /// + /// F16 key. + /// + F16 = 127, + /// + /// F17 key. + /// + F17 = 128, + /// + /// F18 key. + /// + F18 = 129, + /// + /// F19 key. + /// + F19 = 130, + /// + /// F20 key. + /// + F20 = 131, + /// + /// F21 key. + /// + F21 = 132, + /// + /// F22 key. + /// + F22 = 133, + /// + /// F23 key. + /// + F23 = 134, + /// + /// F24 key. + /// + F24 = 135, + /// + /// NUM LOCK key. + /// + NumLock = 144, + /// + /// SCROLL LOCK key. + /// + Scroll = 145, + /// + /// Left SHIFT key. + /// + LeftShift = 160, + /// + /// Right SHIFT key. + /// + RightShift = 161, + /// + /// Left CONTROL key. + /// + LeftControl = 162, + /// + /// Right CONTROL key. + /// + RightControl = 163, + /// + /// Left ALT key. + /// + LeftAlt = 164, + /// + /// Right ALT key. + /// + RightAlt = 165, + /// + /// Browser Back key. + /// + BrowserBack = 166, + /// + /// Browser Forward key. + /// + BrowserForward = 167, + /// + /// Browser Refresh key. + /// + BrowserRefresh = 168, + /// + /// Browser Stop key. + /// + BrowserStop = 169, + /// + /// Browser Search key. + /// + BrowserSearch = 170, + /// + /// Browser Favorites key. + /// + BrowserFavorites = 171, + /// + /// Browser Start and Home key. + /// + BrowserHome = 172, + /// + /// Volume Mute key. + /// + VolumeMute = 173, + /// + /// Volume Down key. + /// + VolumeDown = 174, + /// + /// Volume Up key. + /// + VolumeUp = 175, + /// + /// Next Track key. + /// + MediaNextTrack = 176, + /// + /// Previous Track key. + /// + MediaPreviousTrack = 177, + /// + /// Stop Media key. + /// + MediaStop = 178, + /// + /// Play/Pause Media key. + /// + MediaPlayPause = 179, + /// + /// Start Mail key. + /// + LaunchMail = 180, + /// + /// Select Media key. + /// + SelectMedia = 181, + /// + /// Start Application 1 key. + /// + LaunchApplication1 = 182, + /// + /// Start Application 2 key. + /// + LaunchApplication2 = 183, + /// + /// The OEM Semicolon key on a US standard keyboard. + /// + OemSemicolon = 186, + /// + /// For any country/region, the '+' key. + /// + OemPlus = 187, + /// + /// For any country/region, the ',' key. + /// + OemComma = 188, + /// + /// For any country/region, the '-' key. + /// + OemMinus = 189, + /// + /// For any country/region, the '.' key. + /// + OemPeriod = 190, + /// + /// The OEM question mark key on a US standard keyboard. + /// + OemQuestion = 191, + /// + /// The OEM tilde key on a US standard keyboard. + /// + OemTilde = 192, + /// + /// The OEM open bracket key on a US standard keyboard. + /// + OemOpenBrackets = 219, + /// + /// The OEM pipe key on a US standard keyboard. + /// + OemPipe = 220, + /// + /// The OEM close bracket key on a US standard keyboard. + /// + OemCloseBrackets = 221, + /// + /// The OEM singled/double quote key on a US standard keyboard. + /// + OemQuotes = 222, + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + Oem8 = 223, + /// + /// The OEM angle bracket or backslash key on the RT 102 key keyboard. + /// + OemBackslash = 226, + /// + /// IME PROCESS key. + /// + ProcessKey = 229, + /// + /// Attn key. + /// + Attn = 246, + /// + /// CrSel key. + /// + Crsel = 247, + /// + /// ExSel key. + /// + Exsel = 248, + /// + /// Erase EOF key. + /// + EraseEof = 249, + /// + /// Play key. + /// + Play = 250, + /// + /// Zoom key. + /// + Zoom = 251, + /// + /// PA1 key. + /// + Pa1 = 253, + /// + /// CLEAR key. + /// + OemClear = 254, + /// + /// Green ChatPad key. + /// + ChatPadGreen = 0xCA, + /// + /// Orange ChatPad key. + /// + ChatPadOrange = 0xCB, + /// + /// PAUSE key. + /// + Pause = 0x13, + /// + /// IME Convert key. + /// + ImeConvert = 0x1c, + /// + /// IME NoConvert key. + /// + ImeNoConvert = 0x1d, + /// + /// Kana key on Japanese keyboards. + /// + Kana = 0x15, + /// + /// Kanji key on Japanese keyboards. + /// + Kanji = 0x19, + /// + /// OEM Auto key. + /// + OemAuto = 0xf3, + /// + /// OEM Copy key. + /// + OemCopy = 0xf2, + /// + /// OEM Enlarge Window key. + /// + OemEnlW = 0xf4 + } +} diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Point.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Point.cs new file mode 100644 index 000000000..4ee354fb2 --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Point.cs @@ -0,0 +1,220 @@ +// MIT License - Copyright (C) The Mono.Xna Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System; +using System.Diagnostics; +using System.Runtime.Serialization; + +namespace Microsoft.Xna.Framework +{ + /// + /// Describes a 2D-point. + /// + [DebuggerDisplay("{DebugDisplayString,nq}")] + public struct Point : IEquatable + { + #region Private Fields + + private static readonly Point zeroPoint = new Point(); + + #endregion + + #region Public Fields + + /// + /// The x coordinate of this . + /// + public int X; + + /// + /// The y coordinate of this . + /// + public int Y; + + #endregion + + #region Properties + + /// + /// Returns a with coordinates 0, 0. + /// + public static Point Zero + { + get { return zeroPoint; } + } + + #endregion + + #region Internal Properties + + internal string DebugDisplayString + { + get + { + return string.Concat( + this.X.ToString(), " ", + this.Y.ToString() + ); + } + } + + #endregion + + #region Constructors + + /// + /// Constructs a point with X and Y from two values. + /// + /// The x coordinate in 2d-space. + /// The y coordinate in 2d-space. + public Point(int x, int y) + { + this.X = x; + this.Y = y; + } + + /// + /// Constructs a point with X and Y set to the same value. + /// + /// The x and y coordinates in 2d-space. + public Point(int value) + { + this.X = value; + this.Y = value; + } + + #endregion + + #region Operators + + /// + /// Adds two points. + /// + /// Source on the left of the add sign. + /// Source on the right of the add sign. + /// Sum of the points. + public static Point operator +(Point value1, Point value2) + { + return new Point(value1.X + value2.X, value1.Y + value2.Y); + } + + /// + /// Subtracts a from a . + /// + /// Source on the left of the sub sign. + /// Source on the right of the sub sign. + /// Result of the subtraction. + public static Point operator -(Point value1, Point value2) + { + return new Point(value1.X - value2.X, value1.Y - value2.Y); + } + + /// + /// Multiplies the components of two points by each other. + /// + /// Source on the left of the mul sign. + /// Source on the right of the mul sign. + /// Result of the multiplication. + public static Point operator *(Point value1, Point value2) + { + return new Point(value1.X * value2.X, value1.Y * value2.Y); + } + + /// + /// Divides the components of a by the components of another . + /// + /// Source on the left of the div sign. + /// Divisor on the right of the div sign. + /// The result of dividing the points. + public static Point operator /(Point source, Point divisor) + { + return new Point(source.X / divisor.X, source.Y / divisor.Y); + } + + /// + /// Compares whether two instances are equal. + /// + /// instance on the left of the equal sign. + /// instance on the right of the equal sign. + /// true if the instances are equal; false otherwise. + public static bool operator ==(Point a, Point b) + { + return a.Equals(b); + } + + /// + /// Compares whether two instances are not equal. + /// + /// instance on the left of the not equal sign. + /// instance on the right of the not equal sign. + /// true if the instances are not equal; false otherwise. + public static bool operator !=(Point a, Point b) + { + return !a.Equals(b); + } + + #endregion + + #region Public methods + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public override bool Equals(object obj) + { + return (obj is Point) && Equals((Point)obj); + } + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public bool Equals(Point other) + { + return ((X == other.X) && (Y == other.Y)); + } + + /// + /// Gets the hash code of this . + /// + /// Hash code of this . + public override int GetHashCode() + { + unchecked + { + var hash = 17; + hash = hash * 23 + X.GetHashCode(); + hash = hash * 23 + Y.GetHashCode(); + return hash; + } + + } + + /// + /// Returns a representation of this in the format: + /// {X:[] Y:[]} + /// + /// representation of this . + public override string ToString() + { + return "{X:" + X + " Y:" + Y + "}"; + } + + /// + /// Gets a representation for this object. + /// + /// A representation for this object. + public Vector2 ToVector2() + { + return new Vector2(X, Y); + } + + #endregion + } +} + + diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Quaternion.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Quaternion.cs new file mode 100644 index 000000000..f758552e6 --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Quaternion.cs @@ -0,0 +1,1170 @@ +// MIT License - Copyright (C) The Mono.Xna Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System; +using System.Diagnostics; +using System.Runtime.Serialization; + +namespace Microsoft.Xna.Framework +{ + /// + /// An efficient mathematical representation for three dimensional rotations. + /// + + [DebuggerDisplay("{DebugDisplayString,nq}")] + public struct Quaternion : IEquatable + { + #region Private Fields + + private static readonly Quaternion _identity = new Quaternion(0, 0, 0, 1); + + #endregion + + #region Public Fields + + /// + /// The x coordinate of this . + /// + + public float X; + + /// + /// The y coordinate of this . + /// + + public float Y; + + /// + /// The z coordinate of this . + /// + + public float Z; + + /// + /// The rotation component of this . + /// + + public float W; + + #endregion + + #region Constructors + + /// + /// Constructs a quaternion with X, Y, Z and W from four values. + /// + /// The x coordinate in 3d-space. + /// The y coordinate in 3d-space. + /// The z coordinate in 3d-space. + /// The rotation component. + public Quaternion(float x, float y, float z, float w) + { + this.X = x; + this.Y = y; + this.Z = z; + this.W = w; + } + + /// + /// Constructs a quaternion with X, Y, Z from and rotation component from a scalar. + /// + /// The x, y, z coordinates in 3d-space. + /// The rotation component. + public Quaternion(Vector3 value, float w) + { + this.X = value.X; + this.Y = value.Y; + this.Z = value.Z; + this.W = w; + } + + /// + /// Constructs a quaternion from . + /// + /// The x, y, z coordinates in 3d-space and the rotation component. + public Quaternion(Vector4 value) + { + this.X = value.X; + this.Y = value.Y; + this.Z = value.Z; + this.W = value.W; + } + + #endregion + + #region Public Properties + + /// + /// Returns a quaternion representing no rotation. + /// + public static Quaternion Identity + { + get{ return _identity; } + } + + #endregion + + #region Internal Properties + + internal string DebugDisplayString + { + get + { + if (this == Quaternion._identity) + { + return "Identity"; + } + + return string.Concat( + this.X.ToString(), " ", + this.Y.ToString(), " ", + this.Z.ToString(), " ", + this.W.ToString() + ); + } + } + + #endregion + + #region Public Methods + + #region Add + + /// + /// Creates a new that contains the sum of two quaternions. + /// + /// Source . + /// Source . + /// The result of the quaternion addition. + public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2) + { + Quaternion quaternion; + quaternion.X = quaternion1.X + quaternion2.X; + quaternion.Y = quaternion1.Y + quaternion2.Y; + quaternion.Z = quaternion1.Z + quaternion2.Z; + quaternion.W = quaternion1.W + quaternion2.W; + return quaternion; + } + + /// + /// Creates a new that contains the sum of two quaternions. + /// + /// Source . + /// Source . + /// The result of the quaternion addition as an output parameter. + public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) + { + result.X = quaternion1.X + quaternion2.X; + result.Y = quaternion1.Y + quaternion2.Y; + result.Z = quaternion1.Z + quaternion2.Z; + result.W = quaternion1.W + quaternion2.W; + } + + #endregion + + #region Concatenate + + /// + /// Creates a new that contains concatenation between two quaternion. + /// + /// The first to concatenate. + /// The second to concatenate. + /// The result of rotation of followed by rotation. + public static Quaternion Concatenate(Quaternion value1, Quaternion value2) + { + Quaternion quaternion; + + float x1 = value1.X; + float y1 = value1.Y; + float z1 = value1.Z; + float w1 = value1.W; + + float x2 = value2.X; + float y2 = value2.Y; + float z2 = value2.Z; + float w2 = value2.W; + + quaternion.X = ((x2 * w1) + (x1 * w2)) + ((y2 * z1) - (z2 * y1)); + quaternion.Y = ((y2 * w1) + (y1 * w2)) + ((z2 * x1) - (x2 * z1)); + quaternion.Z = ((z2 * w1) + (z1 * w2)) + ((x2 * y1) - (y2 * x1)); + quaternion.W = (w2 * w1) - (((x2 * x1) + (y2 * y1)) + (z2 * z1)); + + return quaternion; + } + + /// + /// Creates a new that contains concatenation between two quaternion. + /// + /// The first to concatenate. + /// The second to concatenate. + /// The result of rotation of followed by rotation as an output parameter. + public static void Concatenate(ref Quaternion value1, ref Quaternion value2, out Quaternion result) + { + float x1 = value1.X; + float y1 = value1.Y; + float z1 = value1.Z; + float w1 = value1.W; + + float x2 = value2.X; + float y2 = value2.Y; + float z2 = value2.Z; + float w2 = value2.W; + + result.X = ((x2 * w1) + (x1 * w2)) + ((y2 * z1) - (z2 * y1)); + result.Y = ((y2 * w1) + (y1 * w2)) + ((z2 * x1) - (x2 * z1)); + result.Z = ((z2 * w1) + (z1 * w2)) + ((x2 * y1) - (y2 * x1)); + result.W = (w2 * w1) - (((x2 * x1) + (y2 * y1)) + (z2 * z1)); + } + + #endregion + + #region Conjugate + + /// + /// Transforms this quaternion into its conjugated version. + /// + public void Conjugate() + { + X = -X; + Y = -Y; + Z = -Z; + } + + /// + /// Creates a new that contains conjugated version of the specified quaternion. + /// + /// The quaternion which values will be used to create the conjugated version. + /// The conjugate version of the specified quaternion. + public static Quaternion Conjugate(Quaternion value) + { + return new Quaternion(-value.X,-value.Y,-value.Z,value.W); + } + + /// + /// Creates a new that contains conjugated version of the specified quaternion. + /// + /// The quaternion which values will be used to create the conjugated version. + /// The conjugated version of the specified quaternion as an output parameter. + public static void Conjugate(ref Quaternion value, out Quaternion result) + { + result.X = -value.X; + result.Y = -value.Y; + result.Z = -value.Z; + result.W = value.W; + } + + #endregion + + #region CreateFromAxisAngle + + /// + /// Creates a new from the specified axis and angle. + /// + /// The axis of rotation. + /// The angle in radians. + /// The new quaternion builded from axis and angle. + public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle) + { + float half = angle * 0.5f; + float sin = (float)Math.Sin(half); + float cos = (float)Math.Cos(half); + return new Quaternion(axis.X * sin, axis.Y * sin, axis.Z * sin, cos); + } + + /// + /// Creates a new from the specified axis and angle. + /// + /// The axis of rotation. + /// The angle in radians. + /// The new quaternion builded from axis and angle as an output parameter. + public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Quaternion result) + { + float half = angle * 0.5f; + float sin = (float)Math.Sin(half); + float cos = (float)Math.Cos(half); + result.X = axis.X * sin; + result.Y = axis.Y * sin; + result.Z = axis.Z * sin; + result.W = cos; + } + + #endregion + + #region CreateFromRotationMatrix + + /// + /// Creates a new from the specified . + /// + /// The rotation matrix. + /// A quaternion composed from the rotation part of the matrix. + public static Quaternion CreateFromRotationMatrix(Matrix matrix) + { + Quaternion quaternion; + float sqrt; + float half; + float scale = matrix.M11 + matrix.M22 + matrix.M33; + + if (scale > 0.0f) + { + sqrt = (float)Math.Sqrt(scale + 1.0f); + quaternion.W = sqrt * 0.5f; + sqrt = 0.5f / sqrt; + + quaternion.X = (matrix.M23 - matrix.M32) * sqrt; + quaternion.Y = (matrix.M31 - matrix.M13) * sqrt; + quaternion.Z = (matrix.M12 - matrix.M21) * sqrt; + + return quaternion; + } + if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33)) + { + sqrt = (float) Math.Sqrt(1.0f + matrix.M11 - matrix.M22 - matrix.M33); + half = 0.5f / sqrt; + + quaternion.X = 0.5f * sqrt; + quaternion.Y = (matrix.M12 + matrix.M21) * half; + quaternion.Z = (matrix.M13 + matrix.M31) * half; + quaternion.W = (matrix.M23 - matrix.M32) * half; + + return quaternion; + } + if (matrix.M22 > matrix.M33) + { + sqrt = (float) Math.Sqrt(1.0f + matrix.M22 - matrix.M11 - matrix.M33); + half = 0.5f / sqrt; + + quaternion.X = (matrix.M21 + matrix.M12) * half; + quaternion.Y = 0.5f * sqrt; + quaternion.Z = (matrix.M32 + matrix.M23) * half; + quaternion.W = (matrix.M31 - matrix.M13) * half; + + return quaternion; + } + sqrt = (float) Math.Sqrt(1.0f + matrix.M33 - matrix.M11 - matrix.M22); + half = 0.5f / sqrt; + + quaternion.X = (matrix.M31 + matrix.M13) * half; + quaternion.Y = (matrix.M32 + matrix.M23) * half; + quaternion.Z = 0.5f * sqrt; + quaternion.W = (matrix.M12 - matrix.M21) * half; + + return quaternion; + } + + /// + /// Creates a new from the specified . + /// + /// The rotation matrix. + /// A quaternion composed from the rotation part of the matrix as an output parameter. + public static void CreateFromRotationMatrix(ref Matrix matrix, out Quaternion result) + { + float sqrt; + float half; + float scale = matrix.M11 + matrix.M22 + matrix.M33; + + if (scale > 0.0f) + { + sqrt = (float)Math.Sqrt(scale + 1.0f); + result.W = sqrt * 0.5f; + sqrt = 0.5f / sqrt; + + result.X = (matrix.M23 - matrix.M32) * sqrt; + result.Y = (matrix.M31 - matrix.M13) * sqrt; + result.Z = (matrix.M12 - matrix.M21) * sqrt; + } + else + if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33)) + { + sqrt = (float)Math.Sqrt(1.0f + matrix.M11 - matrix.M22 - matrix.M33); + half = 0.5f / sqrt; + + result.X = 0.5f * sqrt; + result.Y = (matrix.M12 + matrix.M21) * half; + result.Z = (matrix.M13 + matrix.M31) * half; + result.W = (matrix.M23 - matrix.M32) * half; + } + else if (matrix.M22 > matrix.M33) + { + sqrt = (float) Math.Sqrt(1.0f + matrix.M22 - matrix.M11 - matrix.M33); + half = 0.5f/sqrt; + + result.X = (matrix.M21 + matrix.M12)*half; + result.Y = 0.5f*sqrt; + result.Z = (matrix.M32 + matrix.M23)*half; + result.W = (matrix.M31 - matrix.M13)*half; + } + else + { + sqrt = (float)Math.Sqrt(1.0f + matrix.M33 - matrix.M11 - matrix.M22); + half = 0.5f / sqrt; + + result.X = (matrix.M31 + matrix.M13) * half; + result.Y = (matrix.M32 + matrix.M23) * half; + result.Z = 0.5f * sqrt; + result.W = (matrix.M12 - matrix.M21) * half; + } + } + + #endregion + + #region CreateFromYawPitchRoll + + /// + /// Creates a new from the specified yaw, pitch and roll angles. + /// + /// Yaw around the y axis in radians. + /// Pitch around the x axis in radians. + /// Roll around the z axis in radians. + /// A new quaternion from the concatenated yaw, pitch, and roll angles. + public static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll) + { + float halfRoll = roll * 0.5f; + float halfPitch = pitch * 0.5f; + float halfYaw = yaw * 0.5f; + + float sinRoll = (float)Math.Sin(halfRoll); + float cosRoll = (float)Math.Cos(halfRoll); + float sinPitch = (float)Math.Sin(halfPitch); + float cosPitch = (float)Math.Cos(halfPitch); + float sinYaw = (float)Math.Sin(halfYaw); + float cosYaw = (float)Math.Cos(halfYaw); + + return new Quaternion((cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll), + (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll), + (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll), + (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll)); + } + + /// + /// Creates a new from the specified yaw, pitch and roll angles. + /// + /// Yaw around the y axis in radians. + /// Pitch around the x axis in radians. + /// Roll around the z axis in radians. + /// A new quaternion from the concatenated yaw, pitch, and roll angles as an output parameter. + public static void CreateFromYawPitchRoll(float yaw, float pitch, float roll, out Quaternion result) + { + float halfRoll = roll * 0.5f; + float halfPitch = pitch * 0.5f; + float halfYaw = yaw * 0.5f; + + float sinRoll = (float)Math.Sin(halfRoll); + float cosRoll = (float)Math.Cos(halfRoll); + float sinPitch = (float)Math.Sin(halfPitch); + float cosPitch = (float)Math.Cos(halfPitch); + float sinYaw = (float)Math.Sin(halfYaw); + float cosYaw = (float)Math.Cos(halfYaw); + + result.X = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll); + result.Y = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll); + result.Z = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll); + result.W = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll); + } + + #endregion + + #region Divide + + /// + /// Divides a by the other . + /// + /// Source . + /// Divisor . + /// The result of dividing the quaternions. + public static Quaternion Divide(Quaternion quaternion1, Quaternion quaternion2) + { + Quaternion quaternion; + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); + float num5 = 1f / num14; + float num4 = -quaternion2.X * num5; + float num3 = -quaternion2.Y * num5; + float num2 = -quaternion2.Z * num5; + float num = quaternion2.W * num5; + float num13 = (y * num2) - (z * num3); + float num12 = (z * num4) - (x * num2); + float num11 = (x * num3) - (y * num4); + float num10 = ((x * num4) + (y * num3)) + (z * num2); + quaternion.X = ((x * num) + (num4 * w)) + num13; + quaternion.Y = ((y * num) + (num3 * w)) + num12; + quaternion.Z = ((z * num) + (num2 * w)) + num11; + quaternion.W = (w * num) - num10; + return quaternion; + } + + /// + /// Divides a by the other . + /// + /// Source . + /// Divisor . + /// The result of dividing the quaternions as an output parameter. + public static void Divide(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) + { + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); + float num5 = 1f / num14; + float num4 = -quaternion2.X * num5; + float num3 = -quaternion2.Y * num5; + float num2 = -quaternion2.Z * num5; + float num = quaternion2.W * num5; + float num13 = (y * num2) - (z * num3); + float num12 = (z * num4) - (x * num2); + float num11 = (x * num3) - (y * num4); + float num10 = ((x * num4) + (y * num3)) + (z * num2); + result.X = ((x * num) + (num4 * w)) + num13; + result.Y = ((y * num) + (num3 * w)) + num12; + result.Z = ((z * num) + (num2 * w)) + num11; + result.W = (w * num) - num10; + } + + #endregion + + #region Dot + + /// + /// Returns a dot product of two quaternions. + /// + /// The first quaternion. + /// The second quaternion. + /// The dot product of two quaternions. + public static float Dot(Quaternion quaternion1, Quaternion quaternion2) + { + return ((((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W)); + } + + /// + /// Returns a dot product of two quaternions. + /// + /// The first quaternion. + /// The second quaternion. + /// The dot product of two quaternions as an output parameter. + public static void Dot(ref Quaternion quaternion1, ref Quaternion quaternion2, out float result) + { + result = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + } + + #endregion + + #region Equals + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public override bool Equals(object obj) + { + if (obj is Quaternion) + return Equals((Quaternion)obj); + return false; + } + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public bool Equals(Quaternion other) + { + return X == other.X && + Y == other.Y && + Z == other.Z && + W == other.W; + } + + #endregion + + /// + /// Gets the hash code of this . + /// + /// Hash code of this . + public override int GetHashCode() + { + return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + W.GetHashCode(); + } + + #region Inverse + + /// + /// Returns the inverse quaternion which represents the opposite rotation. + /// + /// Source . + /// The inverse quaternion. + public static Quaternion Inverse(Quaternion quaternion) + { + Quaternion quaternion2; + float num2 = (((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y)) + (quaternion.Z * quaternion.Z)) + (quaternion.W * quaternion.W); + float num = 1f / num2; + quaternion2.X = -quaternion.X * num; + quaternion2.Y = -quaternion.Y * num; + quaternion2.Z = -quaternion.Z * num; + quaternion2.W = quaternion.W * num; + return quaternion2; + } + + /// + /// Returns the inverse quaternion which represents the opposite rotation. + /// + /// Source . + /// The inverse quaternion as an output parameter. + public static void Inverse(ref Quaternion quaternion, out Quaternion result) + { + float num2 = (((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y)) + (quaternion.Z * quaternion.Z)) + (quaternion.W * quaternion.W); + float num = 1f / num2; + result.X = -quaternion.X * num; + result.Y = -quaternion.Y * num; + result.Z = -quaternion.Z * num; + result.W = quaternion.W * num; + } + + #endregion + + /// + /// Returns the magnitude of the quaternion components. + /// + /// The magnitude of the quaternion components. + public float Length() + { + return (float) Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W)); + } + + /// + /// Returns the squared magnitude of the quaternion components. + /// + /// The squared magnitude of the quaternion components. + public float LengthSquared() + { + return (X * X) + (Y * Y) + (Z * Z) + (W * W); + } + + #region Lerp + + /// + /// Performs a linear blend between two quaternions. + /// + /// Source . + /// Source . + /// The blend amount where 0 returns and 1 . + /// The result of linear blending between two quaternions. + public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount) + { + float num = amount; + float num2 = 1f - num; + Quaternion quaternion = new Quaternion(); + float num5 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + if (num5 >= 0f) + { + quaternion.X = (num2 * quaternion1.X) + (num * quaternion2.X); + quaternion.Y = (num2 * quaternion1.Y) + (num * quaternion2.Y); + quaternion.Z = (num2 * quaternion1.Z) + (num * quaternion2.Z); + quaternion.W = (num2 * quaternion1.W) + (num * quaternion2.W); + } + else + { + quaternion.X = (num2 * quaternion1.X) - (num * quaternion2.X); + quaternion.Y = (num2 * quaternion1.Y) - (num * quaternion2.Y); + quaternion.Z = (num2 * quaternion1.Z) - (num * quaternion2.Z); + quaternion.W = (num2 * quaternion1.W) - (num * quaternion2.W); + } + float num4 = (((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y)) + (quaternion.Z * quaternion.Z)) + (quaternion.W * quaternion.W); + float num3 = 1f / ((float) Math.Sqrt((double) num4)); + quaternion.X *= num3; + quaternion.Y *= num3; + quaternion.Z *= num3; + quaternion.W *= num3; + return quaternion; + } + + /// + /// Performs a linear blend between two quaternions. + /// + /// Source . + /// Source . + /// The blend amount where 0 returns and 1 . + /// The result of linear blending between two quaternions as an output parameter. + public static void Lerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) + { + float num = amount; + float num2 = 1f - num; + float num5 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + if (num5 >= 0f) + { + result.X = (num2 * quaternion1.X) + (num * quaternion2.X); + result.Y = (num2 * quaternion1.Y) + (num * quaternion2.Y); + result.Z = (num2 * quaternion1.Z) + (num * quaternion2.Z); + result.W = (num2 * quaternion1.W) + (num * quaternion2.W); + } + else + { + result.X = (num2 * quaternion1.X) - (num * quaternion2.X); + result.Y = (num2 * quaternion1.Y) - (num * quaternion2.Y); + result.Z = (num2 * quaternion1.Z) - (num * quaternion2.Z); + result.W = (num2 * quaternion1.W) - (num * quaternion2.W); + } + float num4 = (((result.X * result.X) + (result.Y * result.Y)) + (result.Z * result.Z)) + (result.W * result.W); + float num3 = 1f / ((float) Math.Sqrt((double) num4)); + result.X *= num3; + result.Y *= num3; + result.Z *= num3; + result.W *= num3; + + } + + #endregion + + #region Slerp + + /// + /// Performs a spherical linear blend between two quaternions. + /// + /// Source . + /// Source . + /// The blend amount where 0 returns and 1 . + /// The result of spherical linear blending between two quaternions. + public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount) + { + float num2; + float num3; + Quaternion quaternion; + float num = amount; + float num4 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + bool flag = false; + if (num4 < 0f) + { + flag = true; + num4 = -num4; + } + if (num4 > 0.999999f) + { + num3 = 1f - num; + num2 = flag ? -num : num; + } + else + { + float num5 = (float) Math.Acos((double) num4); + float num6 = (float) (1.0 / Math.Sin((double) num5)); + num3 = ((float) Math.Sin((double) ((1f - num) * num5))) * num6; + num2 = flag ? (((float) -Math.Sin((double) (num * num5))) * num6) : (((float) Math.Sin((double) (num * num5))) * num6); + } + quaternion.X = (num3 * quaternion1.X) + (num2 * quaternion2.X); + quaternion.Y = (num3 * quaternion1.Y) + (num2 * quaternion2.Y); + quaternion.Z = (num3 * quaternion1.Z) + (num2 * quaternion2.Z); + quaternion.W = (num3 * quaternion1.W) + (num2 * quaternion2.W); + return quaternion; + } + + /// + /// Performs a spherical linear blend between two quaternions. + /// + /// Source . + /// Source . + /// The blend amount where 0 returns and 1 . + /// The result of spherical linear blending between two quaternions as an output parameter. + public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) + { + float num2; + float num3; + float num = amount; + float num4 = (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y)) + (quaternion1.Z * quaternion2.Z)) + (quaternion1.W * quaternion2.W); + bool flag = false; + if (num4 < 0f) + { + flag = true; + num4 = -num4; + } + if (num4 > 0.999999f) + { + num3 = 1f - num; + num2 = flag ? -num : num; + } + else + { + float num5 = (float) Math.Acos((double) num4); + float num6 = (float) (1.0 / Math.Sin((double) num5)); + num3 = ((float) Math.Sin((double) ((1f - num) * num5))) * num6; + num2 = flag ? (((float) -Math.Sin((double) (num * num5))) * num6) : (((float) Math.Sin((double) (num * num5))) * num6); + } + result.X = (num3 * quaternion1.X) + (num2 * quaternion2.X); + result.Y = (num3 * quaternion1.Y) + (num2 * quaternion2.Y); + result.Z = (num3 * quaternion1.Z) + (num2 * quaternion2.Z); + result.W = (num3 * quaternion1.W) + (num2 * quaternion2.W); + } + + #endregion + + #region Subtract + + /// + /// Creates a new that contains subtraction of one from another. + /// + /// Source . + /// Source . + /// The result of the quaternion subtraction. + public static Quaternion Subtract(Quaternion quaternion1, Quaternion quaternion2) + { + Quaternion quaternion; + quaternion.X = quaternion1.X - quaternion2.X; + quaternion.Y = quaternion1.Y - quaternion2.Y; + quaternion.Z = quaternion1.Z - quaternion2.Z; + quaternion.W = quaternion1.W - quaternion2.W; + return quaternion; + } + + /// + /// Creates a new that contains subtraction of one from another. + /// + /// Source . + /// Source . + /// The result of the quaternion subtraction as an output parameter. + public static void Subtract(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) + { + result.X = quaternion1.X - quaternion2.X; + result.Y = quaternion1.Y - quaternion2.Y; + result.Z = quaternion1.Z - quaternion2.Z; + result.W = quaternion1.W - quaternion2.W; + } + + #endregion + + #region Multiply + + /// + /// Creates a new that contains a multiplication of two quaternions. + /// + /// Source . + /// Source . + /// The result of the quaternion multiplication. + public static Quaternion Multiply(Quaternion quaternion1, Quaternion quaternion2) + { + Quaternion quaternion; + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num4 = quaternion2.X; + float num3 = quaternion2.Y; + float num2 = quaternion2.Z; + float num = quaternion2.W; + float num12 = (y * num2) - (z * num3); + float num11 = (z * num4) - (x * num2); + float num10 = (x * num3) - (y * num4); + float num9 = ((x * num4) + (y * num3)) + (z * num2); + quaternion.X = ((x * num) + (num4 * w)) + num12; + quaternion.Y = ((y * num) + (num3 * w)) + num11; + quaternion.Z = ((z * num) + (num2 * w)) + num10; + quaternion.W = (w * num) - num9; + return quaternion; + } + + /// + /// Creates a new that contains a multiplication of and a scalar. + /// + /// Source . + /// Scalar value. + /// The result of the quaternion multiplication with a scalar. + public static Quaternion Multiply(Quaternion quaternion1, float scaleFactor) + { + Quaternion quaternion; + quaternion.X = quaternion1.X * scaleFactor; + quaternion.Y = quaternion1.Y * scaleFactor; + quaternion.Z = quaternion1.Z * scaleFactor; + quaternion.W = quaternion1.W * scaleFactor; + return quaternion; + } + + /// + /// Creates a new that contains a multiplication of and a scalar. + /// + /// Source . + /// Scalar value. + /// The result of the quaternion multiplication with a scalar as an output parameter. + public static void Multiply(ref Quaternion quaternion1, float scaleFactor, out Quaternion result) + { + result.X = quaternion1.X * scaleFactor; + result.Y = quaternion1.Y * scaleFactor; + result.Z = quaternion1.Z * scaleFactor; + result.W = quaternion1.W * scaleFactor; + } + + /// + /// Creates a new that contains a multiplication of two quaternions. + /// + /// Source . + /// Source . + /// The result of the quaternion multiplication as an output parameter. + public static void Multiply(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) + { + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num4 = quaternion2.X; + float num3 = quaternion2.Y; + float num2 = quaternion2.Z; + float num = quaternion2.W; + float num12 = (y * num2) - (z * num3); + float num11 = (z * num4) - (x * num2); + float num10 = (x * num3) - (y * num4); + float num9 = ((x * num4) + (y * num3)) + (z * num2); + result.X = ((x * num) + (num4 * w)) + num12; + result.Y = ((y * num) + (num3 * w)) + num11; + result.Z = ((z * num) + (num2 * w)) + num10; + result.W = (w * num) - num9; + } + + #endregion + + #region Negate + + /// + /// Flips the sign of the all the quaternion components. + /// + /// Source . + /// The result of the quaternion negation. + public static Quaternion Negate(Quaternion quaternion) + { + return new Quaternion(-quaternion.X, -quaternion.Y, -quaternion.Z, -quaternion.W); + } + + /// + /// Flips the sign of the all the quaternion components. + /// + /// Source . + /// The result of the quaternion negation as an output parameter. + public static void Negate(ref Quaternion quaternion, out Quaternion result) + { + result.X = -quaternion.X; + result.Y = -quaternion.Y; + result.Z = -quaternion.Z; + result.W = -quaternion.W; + } + + #endregion + + #region Normalize + + /// + /// Scales the quaternion magnitude to unit length. + /// + public void Normalize() + { + float num = 1f / ((float) Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W))); + X *= num; + Y *= num; + Z *= num; + W *= num; + } + + /// + /// Scales the quaternion magnitude to unit length. + /// + /// Source . + /// The unit length quaternion. + public static Quaternion Normalize(Quaternion quaternion) + { + Quaternion result; + float num = 1f / ((float) Math.Sqrt((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W))); + result.X = quaternion.X * num; + result.Y = quaternion.Y * num; + result.Z = quaternion.Z * num; + result.W = quaternion.W * num; + return result; + } + + /// + /// Scales the quaternion magnitude to unit length. + /// + /// Source . + /// The unit length quaternion an output parameter. + public static void Normalize(ref Quaternion quaternion, out Quaternion result) + { + float num = 1f / ((float) Math.Sqrt((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W))); + result.X = quaternion.X * num; + result.Y = quaternion.Y * num; + result.Z = quaternion.Z * num; + result.W = quaternion.W * num; + } + + #endregion + + /// + /// Returns a representation of this in the format: + /// {X:[] Y:[] Z:[] W:[]} + /// + /// A representation of this . + public override string ToString() + { + return "{X:" + X + " Y:" + Y + " Z:" + Z + " W:" + W + "}"; + } + + /// + /// Gets a representation for this object. + /// + /// A representation for this object. + public Vector4 ToVector4() + { + return new Vector4(X,Y,Z,W); + } + + #endregion + + #region Operators + + /// + /// Adds two quaternions. + /// + /// Source on the left of the add sign. + /// Source on the right of the add sign. + /// Sum of the vectors. + public static Quaternion operator +(Quaternion quaternion1, Quaternion quaternion2) + { + Quaternion quaternion; + quaternion.X = quaternion1.X + quaternion2.X; + quaternion.Y = quaternion1.Y + quaternion2.Y; + quaternion.Z = quaternion1.Z + quaternion2.Z; + quaternion.W = quaternion1.W + quaternion2.W; + return quaternion; + } + + /// + /// Divides a by the other . + /// + /// Source on the left of the div sign. + /// Divisor on the right of the div sign. + /// The result of dividing the quaternions. + public static Quaternion operator /(Quaternion quaternion1, Quaternion quaternion2) + { + Quaternion quaternion; + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num14 = (((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y)) + (quaternion2.Z * quaternion2.Z)) + (quaternion2.W * quaternion2.W); + float num5 = 1f / num14; + float num4 = -quaternion2.X * num5; + float num3 = -quaternion2.Y * num5; + float num2 = -quaternion2.Z * num5; + float num = quaternion2.W * num5; + float num13 = (y * num2) - (z * num3); + float num12 = (z * num4) - (x * num2); + float num11 = (x * num3) - (y * num4); + float num10 = ((x * num4) + (y * num3)) + (z * num2); + quaternion.X = ((x * num) + (num4 * w)) + num13; + quaternion.Y = ((y * num) + (num3 * w)) + num12; + quaternion.Z = ((z * num) + (num2 * w)) + num11; + quaternion.W = (w * num) - num10; + return quaternion; + } + + /// + /// Compares whether two instances are equal. + /// + /// instance on the left of the equal sign. + /// instance on the right of the equal sign. + /// true if the instances are equal; false otherwise. + public static bool operator ==(Quaternion quaternion1, Quaternion quaternion2) + { + return ((((quaternion1.X == quaternion2.X) && (quaternion1.Y == quaternion2.Y)) && (quaternion1.Z == quaternion2.Z)) && (quaternion1.W == quaternion2.W)); + } + + /// + /// Compares whether two instances are not equal. + /// + /// instance on the left of the not equal sign. + /// instance on the right of the not equal sign. + /// true if the instances are not equal; false otherwise. + public static bool operator !=(Quaternion quaternion1, Quaternion quaternion2) + { + if (((quaternion1.X == quaternion2.X) && (quaternion1.Y == quaternion2.Y)) && (quaternion1.Z == quaternion2.Z)) + { + return (quaternion1.W != quaternion2.W); + } + return true; + } + + /// + /// Multiplies two quaternions. + /// + /// Source on the left of the mul sign. + /// Source on the right of the mul sign. + /// Result of the quaternions multiplication. + public static Quaternion operator *(Quaternion quaternion1, Quaternion quaternion2) + { + Quaternion quaternion; + float x = quaternion1.X; + float y = quaternion1.Y; + float z = quaternion1.Z; + float w = quaternion1.W; + float num4 = quaternion2.X; + float num3 = quaternion2.Y; + float num2 = quaternion2.Z; + float num = quaternion2.W; + float num12 = (y * num2) - (z * num3); + float num11 = (z * num4) - (x * num2); + float num10 = (x * num3) - (y * num4); + float num9 = ((x * num4) + (y * num3)) + (z * num2); + quaternion.X = ((x * num) + (num4 * w)) + num12; + quaternion.Y = ((y * num) + (num3 * w)) + num11; + quaternion.Z = ((z * num) + (num2 * w)) + num10; + quaternion.W = (w * num) - num9; + return quaternion; + } + + /// + /// Multiplies the components of quaternion by a scalar. + /// + /// Source on the left of the mul sign. + /// Scalar value on the right of the mul sign. + /// Result of the quaternion multiplication with a scalar. + public static Quaternion operator *(Quaternion quaternion1, float scaleFactor) + { + Quaternion quaternion; + quaternion.X = quaternion1.X * scaleFactor; + quaternion.Y = quaternion1.Y * scaleFactor; + quaternion.Z = quaternion1.Z * scaleFactor; + quaternion.W = quaternion1.W * scaleFactor; + return quaternion; + } + + /// + /// Subtracts a from a . + /// + /// Source on the left of the sub sign. + /// Source on the right of the sub sign. + /// Result of the quaternion subtraction. + public static Quaternion operator -(Quaternion quaternion1, Quaternion quaternion2) + { + Quaternion quaternion; + quaternion.X = quaternion1.X - quaternion2.X; + quaternion.Y = quaternion1.Y - quaternion2.Y; + quaternion.Z = quaternion1.Z - quaternion2.Z; + quaternion.W = quaternion1.W - quaternion2.W; + return quaternion; + + } + + /// + /// Flips the sign of the all the quaternion components. + /// + /// Source on the right of the sub sign. + /// The result of the quaternion negation. + public static Quaternion operator -(Quaternion quaternion) + { + Quaternion quaternion2; + quaternion2.X = -quaternion.X; + quaternion2.Y = -quaternion.Y; + quaternion2.Z = -quaternion.Z; + quaternion2.W = -quaternion.W; + return quaternion2; + } + + #endregion + } +} diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Rectangle.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Rectangle.cs new file mode 100644 index 000000000..469f51fc0 --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Rectangle.cs @@ -0,0 +1,524 @@ +// MIT License - Copyright (C) The Mono.Xna Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System; +using System.Runtime.Serialization; +using System.Diagnostics; + +namespace Microsoft.Xna.Framework +{ + /// + /// Describes a 2D-rectangle. + /// + + [DebuggerDisplay("{DebugDisplayString,nq}")] + public struct Rectangle : IEquatable + { + #region Private Fields + + private static Rectangle emptyRectangle = new Rectangle(); + + #endregion + + #region Public Fields + + /// + /// The x coordinate of the top-left corner of this . + /// + + public int X; + + /// + /// The y coordinate of the top-left corner of this . + /// + + public int Y; + + /// + /// The width of this . + /// + + public int Width; + + /// + /// The height of this . + /// + + public int Height; + + #endregion + + #region Public Properties + + /// + /// Returns a with X=0, Y=0, Width=0, Height=0. + /// + public static Rectangle Empty + { + get { return emptyRectangle; } + } + + /// + /// Returns the x coordinate of the left edge of this . + /// + public int Left + { + get { return this.X; } + } + + /// + /// Returns the x coordinate of the right edge of this . + /// + public int Right + { + get { return (this.X + this.Width); } + } + + /// + /// Returns the y coordinate of the top edge of this . + /// + public int Top + { + get { return this.Y; } + } + + /// + /// Returns the y coordinate of the bottom edge of this . + /// + public int Bottom + { + get { return (this.Y + this.Height); } + } + + /// + /// Whether or not this has a and + /// of 0, and a of (0, 0). + /// + public bool IsEmpty + { + get + { + return ((((this.Width == 0) && (this.Height == 0)) && (this.X == 0)) && (this.Y == 0)); + } + } + + /// + /// The top-left coordinates of this . + /// + public Point Location + { + get + { + return new Point(this.X, this.Y); + } + set + { + X = value.X; + Y = value.Y; + } + } + + /// + /// The width-height coordinates of this . + /// + public Point Size + { + get + { + return new Point(this.Width,this.Height); + } + set + { + Width = value.X; + Height = value.Y; + } + } + + /// + /// A located in the center of this . + /// + /// + /// If or is an odd number, + /// the center point will be rounded down. + /// + public Point Center + { + get + { + return new Point(this.X + (this.Width / 2), this.Y + (this.Height / 2)); + } + } + + #endregion + + #region Internal Properties + + internal string DebugDisplayString + { + get + { + return string.Concat( + this.X, " ", + this.Y, " ", + this.Width, " ", + this.Height + ); + } + } + + #endregion + + #region Constructors + + /// + /// Creates a new instance of struct, with the specified + /// position, width, and height. + /// + /// The x coordinate of the top-left corner of the created . + /// The y coordinate of the top-left corner of the created . + /// The width of the created . + /// The height of the created . + public Rectangle(int x, int y, int width, int height) + { + this.X = x; + this.Y = y; + this.Width = width; + this.Height = height; + } + + /// + /// Creates a new instance of struct, with the specified + /// location and size. + /// + /// The x and y coordinates of the top-left corner of the created . + /// The width and height of the created . + public Rectangle(Point location,Point size) + { + this.X = location.X; + this.Y = location.Y; + this.Width = size.X; + this.Height = size.Y; + } + + #endregion + + #region Operators + + /// + /// Compares whether two instances are equal. + /// + /// instance on the left of the equal sign. + /// instance on the right of the equal sign. + /// true if the instances are equal; false otherwise. + public static bool operator ==(Rectangle a, Rectangle b) + { + return ((a.X == b.X) && (a.Y == b.Y) && (a.Width == b.Width) && (a.Height == b.Height)); + } + + /// + /// Compares whether two instances are not equal. + /// + /// instance on the left of the not equal sign. + /// instance on the right of the not equal sign. + /// true if the instances are not equal; false otherwise. + public static bool operator !=(Rectangle a, Rectangle b) + { + return !(a == b); + } + + #endregion + + #region Public Methods + + /// + /// Gets whether or not the provided coordinates lie within the bounds of this . + /// + /// The x coordinate of the point to check for containment. + /// The y coordinate of the point to check for containment. + /// true if the provided coordinates lie inside this ; false otherwise. + public bool Contains(int x, int y) + { + return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height))); + } + + /// + /// Gets whether or not the provided coordinates lie within the bounds of this . + /// + /// The x coordinate of the point to check for containment. + /// The y coordinate of the point to check for containment. + /// true if the provided coordinates lie inside this ; false otherwise. + public bool Contains(float x, float y) + { + return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height))); + } + + /// + /// Gets whether or not the provided lies within the bounds of this . + /// + /// The coordinates to check for inclusion in this . + /// true if the provided lies inside this ; false otherwise. + public bool Contains(Point value) + { + return ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height))); + } + + /// + /// Gets whether or not the provided lies within the bounds of this . + /// + /// The coordinates to check for inclusion in this . + /// true if the provided lies inside this ; false otherwise. As an output parameter. + public void Contains(ref Point value, out bool result) + { + result = ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height))); + } + + /// + /// Gets whether or not the provided lies within the bounds of this . + /// + /// The coordinates to check for inclusion in this . + /// true if the provided lies inside this ; false otherwise. + public bool Contains(Vector2 value) + { + return ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height))); + } + + /// + /// Gets whether or not the provided lies within the bounds of this . + /// + /// The coordinates to check for inclusion in this . + /// true if the provided lies inside this ; false otherwise. As an output parameter. + public void Contains(ref Vector2 value, out bool result) + { + result = ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height))); + } + + /// + /// Gets whether or not the provided lies within the bounds of this . + /// + /// The to check for inclusion in this . + /// true if the provided 's bounds lie entirely inside this ; false otherwise. + public bool Contains(Rectangle value) + { + return ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height))); + } + + /// + /// Gets whether or not the provided lies within the bounds of this . + /// + /// The to check for inclusion in this . + /// true if the provided 's bounds lie entirely inside this ; false otherwise. As an output parameter. + public void Contains(ref Rectangle value,out bool result) + { + result = ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height))); + } + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public override bool Equals(object obj) + { + return (obj is Rectangle) && this == ((Rectangle)obj); + } + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public bool Equals(Rectangle other) + { + return this == other; + } + + /// + /// Gets the hash code of this . + /// + /// Hash code of this . + public override int GetHashCode() + { + unchecked + { + var hash = 17; + hash = hash * 23 + X.GetHashCode(); + hash = hash * 23 + Y.GetHashCode(); + hash = hash * 23 + Width.GetHashCode(); + hash = hash * 23 + Height.GetHashCode(); + return hash; + } + } + + /// + /// Adjusts the edges of this by specified horizontal and vertical amounts. + /// + /// Value to adjust the left and right edges. + /// Value to adjust the top and bottom edges. + public void Inflate(int horizontalAmount, int verticalAmount) + { + X -= horizontalAmount; + Y -= verticalAmount; + Width += horizontalAmount * 2; + Height += verticalAmount * 2; + } + + /// + /// Adjusts the edges of this by specified horizontal and vertical amounts. + /// + /// Value to adjust the left and right edges. + /// Value to adjust the top and bottom edges. + public void Inflate(float horizontalAmount, float verticalAmount) + { + X -= (int)horizontalAmount; + Y -= (int)verticalAmount; + Width += (int)horizontalAmount * 2; + Height += (int)verticalAmount * 2; + } + + /// + /// Gets whether or not the other intersects with this rectangle. + /// + /// The other rectangle for testing. + /// true if other intersects with this rectangle; false otherwise. + public bool Intersects(Rectangle value) + { + return value.Left < Right && + Left < value.Right && + value.Top < Bottom && + Top < value.Bottom; + } + + + /// + /// Gets whether or not the other intersects with this rectangle. + /// + /// The other rectangle for testing. + /// true if other intersects with this rectangle; false otherwise. As an output parameter. + public void Intersects(ref Rectangle value, out bool result) + { + result = value.Left < Right && + Left < value.Right && + value.Top < Bottom && + Top < value.Bottom; + } + + /// + /// Creates a new that contains overlapping region of two other rectangles. + /// + /// The first . + /// The second . + /// Overlapping region of the two rectangles. + public static Rectangle Intersect(Rectangle value1, Rectangle value2) + { + Rectangle rectangle; + Intersect(ref value1, ref value2, out rectangle); + return rectangle; + } + + /// + /// Creates a new that contains overlapping region of two other rectangles. + /// + /// The first . + /// The second . + /// Overlapping region of the two rectangles as an output parameter. + public static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result) + { + if (value1.Intersects(value2)) + { + int right_side = Math.Min(value1.X + value1.Width, value2.X + value2.Width); + int left_side = Math.Max(value1.X, value2.X); + int top_side = Math.Max(value1.Y, value2.Y); + int bottom_side = Math.Min(value1.Y + value1.Height, value2.Y + value2.Height); + result = new Rectangle(left_side, top_side, right_side - left_side, bottom_side - top_side); + } + else + { + result = new Rectangle(0, 0, 0, 0); + } + } + + /// + /// Changes the of this . + /// + /// The x coordinate to add to this . + /// The y coordinate to add to this . + public void Offset(int offsetX, int offsetY) + { + X += offsetX; + Y += offsetY; + } + + /// + /// Changes the of this . + /// + /// The x coordinate to add to this . + /// The y coordinate to add to this . + public void Offset(float offsetX, float offsetY) + { + X += (int)offsetX; + Y += (int)offsetY; + } + + /// + /// Changes the of this . + /// + /// The x and y components to add to this . + public void Offset(Point amount) + { + X += amount.X; + Y += amount.Y; + } + + /// + /// Changes the of this . + /// + /// The x and y components to add to this . + public void Offset(Vector2 amount) + { + X += (int)amount.X; + Y += (int)amount.Y; + } + + /// + /// Returns a representation of this in the format: + /// {X:[] Y:[] Width:[] Height:[]} + /// + /// representation of this . + public override string ToString() + { + return "{X:" + X + " Y:" + Y + " Width:" + Width + " Height:" + Height + "}"; + } + + /// + /// Creates a new that completely contains two other rectangles. + /// + /// The first . + /// The second . + /// The union of the two rectangles. + public static Rectangle Union(Rectangle value1, Rectangle value2) + { + int x = Math.Min(value1.X, value2.X); + int y = Math.Min(value1.Y, value2.Y); + return new Rectangle(x, y, + Math.Max(value1.Right, value2.Right) - x, + Math.Max(value1.Bottom, value2.Bottom) - y); + } + + /// + /// Creates a new that completely contains two other rectangles. + /// + /// The first . + /// The second . + /// The union of the two rectangles as an output parameter. + public static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result) + { + result.X = Math.Min(value1.X, value2.X); + result.Y = Math.Min(value1.Y, value2.Y); + result.Width = Math.Max(value1.Right, value2.Right) - result.X; + result.Height = Math.Max(value1.Bottom, value2.Bottom) - result.Y; + } + + #endregion + } +} diff --git a/BarotraumaServer/Source/Utils/MonogameTypes/Vector4.cs b/BarotraumaServer/Source/Utils/MonogameTypes/Vector4.cs new file mode 100644 index 000000000..257829a34 --- /dev/null +++ b/BarotraumaServer/Source/Utils/MonogameTypes/Vector4.cs @@ -0,0 +1,1238 @@ +// MIT License - Copyright (C) The Mono.Xna Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +// Modified by juanjp600 to remove LerpPrecise, as it is not +// available in Farseer's implementation of MathHelper. + +using System; +using System.Runtime.Serialization; +using System.Diagnostics; + +namespace Microsoft.Xna.Framework +{ + /// + /// Describes a 4D-vector. + /// +#if XNADESIGNPROVIDED + [System.ComponentModel.TypeConverter(typeof(Microsoft.Xna.Framework.Design.Vector4TypeConverter))] +#endif + [DebuggerDisplay("{DebugDisplayString,nq}")] + public struct Vector4 : IEquatable + { + #region Private Fields + + private static readonly Vector4 zero = new Vector4(); + private static readonly Vector4 one = new Vector4(1f, 1f, 1f, 1f); + private static readonly Vector4 unitX = new Vector4(1f, 0f, 0f, 0f); + private static readonly Vector4 unitY = new Vector4(0f, 1f, 0f, 0f); + private static readonly Vector4 unitZ = new Vector4(0f, 0f, 1f, 0f); + private static readonly Vector4 unitW = new Vector4(0f, 0f, 0f, 1f); + + #endregion + + #region Public Fields + + /// + /// The x coordinate of this . + /// + + public float X; + + /// + /// The y coordinate of this . + /// + + public float Y; + + /// + /// The z coordinate of this . + /// + + public float Z; + + /// + /// The w coordinate of this . + /// + + public float W; + + #endregion + + #region Public Properties + + /// + /// Returns a with components 0, 0, 0, 0. + /// + public static Vector4 Zero + { + get { return zero; } + } + + /// + /// Returns a with components 1, 1, 1, 1. + /// + public static Vector4 One + { + get { return one; } + } + + /// + /// Returns a with components 1, 0, 0, 0. + /// + public static Vector4 UnitX + { + get { return unitX; } + } + + /// + /// Returns a with components 0, 1, 0, 0. + /// + public static Vector4 UnitY + { + get { return unitY; } + } + + /// + /// Returns a with components 0, 0, 1, 0. + /// + public static Vector4 UnitZ + { + get { return unitZ; } + } + + /// + /// Returns a with components 0, 0, 0, 1. + /// + public static Vector4 UnitW + { + get { return unitW; } + } + + #endregion + + #region Internal Properties + + internal string DebugDisplayString + { + get + { + return string.Concat( + this.X.ToString(), " ", + this.Y.ToString(), " ", + this.Z.ToString(), " ", + this.W.ToString() + ); + } + } + + #endregion + + #region Constructors + + /// + /// Constructs a 3d vector with X, Y, Z and W from four values. + /// + /// The x coordinate in 4d-space. + /// The y coordinate in 4d-space. + /// The z coordinate in 4d-space. + /// The w coordinate in 4d-space. + public Vector4(float x, float y, float z, float w) + { + this.X = x; + this.Y = y; + this.Z = z; + this.W = w; + } + + /// + /// Constructs a 3d vector with X and Z from and Z and W from the scalars. + /// + /// The x and y coordinates in 4d-space. + /// The z coordinate in 4d-space. + /// The w coordinate in 4d-space. + public Vector4(Vector2 value, float z, float w) + { + this.X = value.X; + this.Y = value.Y; + this.Z = z; + this.W = w; + } + + /// + /// Constructs a 3d vector with X, Y, Z from and W from a scalar. + /// + /// The x, y and z coordinates in 4d-space. + /// The w coordinate in 4d-space. + public Vector4(Vector3 value, float w) + { + this.X = value.X; + this.Y = value.Y; + this.Z = value.Z; + this.W = w; + } + + /// + /// Constructs a 4d vector with X, Y, Z and W set to the same value. + /// + /// The x, y, z and w coordinates in 4d-space. + public Vector4(float value) + { + this.X = value; + this.Y = value; + this.Z = value; + this.W = value; + } + + #endregion + + #region Public Methods + + /// + /// Performs vector addition on and . + /// + /// The first vector to add. + /// The second vector to add. + /// The result of the vector addition. + public static Vector4 Add(Vector4 value1, Vector4 value2) + { + value1.X += value2.X; + value1.Y += value2.Y; + value1.Z += value2.Z; + value1.W += value2.W; + return value1; + } + + /// + /// Performs vector addition on and + /// , storing the result of the + /// addition in . + /// + /// The first vector to add. + /// The second vector to add. + /// The result of the vector addition. + public static void Add(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.X = value1.X + value2.X; + result.Y = value1.Y + value2.Y; + result.Z = value1.Z + value2.Z; + result.W = value1.W + value2.W; + } + + /// + /// Creates a new that contains the cartesian coordinates of a vector specified in barycentric coordinates and relative to 4d-triangle. + /// + /// The first vector of 4d-triangle. + /// The second vector of 4d-triangle. + /// The third vector of 4d-triangle. + /// Barycentric scalar b2 which represents a weighting factor towards second vector of 4d-triangle. + /// Barycentric scalar b3 which represents a weighting factor towards third vector of 4d-triangle. + /// The cartesian translation of barycentric coordinates. + public static Vector4 Barycentric(Vector4 value1, Vector4 value2, Vector4 value3, float amount1, float amount2) + { + return new Vector4( + MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), + MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), + MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2), + MathHelper.Barycentric(value1.W, value2.W, value3.W, amount1, amount2)); + } + + /// + /// Creates a new that contains the cartesian coordinates of a vector specified in barycentric coordinates and relative to 4d-triangle. + /// + /// The first vector of 4d-triangle. + /// The second vector of 4d-triangle. + /// The third vector of 4d-triangle. + /// Barycentric scalar b2 which represents a weighting factor towards second vector of 4d-triangle. + /// Barycentric scalar b3 which represents a weighting factor towards third vector of 4d-triangle. + /// The cartesian translation of barycentric coordinates as an output parameter. + public static void Barycentric(ref Vector4 value1, ref Vector4 value2, ref Vector4 value3, float amount1, float amount2, out Vector4 result) + { + result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2); + result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2); + result.Z = MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2); + result.W = MathHelper.Barycentric(value1.W, value2.W, value3.W, amount1, amount2); + } + + /// + /// Creates a new that contains CatmullRom interpolation of the specified vectors. + /// + /// The first vector in interpolation. + /// The second vector in interpolation. + /// The third vector in interpolation. + /// The fourth vector in interpolation. + /// Weighting factor. + /// The result of CatmullRom interpolation. + public static Vector4 CatmullRom(Vector4 value1, Vector4 value2, Vector4 value3, Vector4 value4, float amount) + { + return new Vector4( + MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), + MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), + MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount), + MathHelper.CatmullRom(value1.W, value2.W, value3.W, value4.W, amount)); + } + + /// + /// Creates a new that contains CatmullRom interpolation of the specified vectors. + /// + /// The first vector in interpolation. + /// The second vector in interpolation. + /// The third vector in interpolation. + /// The fourth vector in interpolation. + /// Weighting factor. + /// The result of CatmullRom interpolation as an output parameter. + public static void CatmullRom(ref Vector4 value1, ref Vector4 value2, ref Vector4 value3, ref Vector4 value4, float amount, out Vector4 result) + { + result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount); + result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount); + result.Z = MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount); + result.W = MathHelper.CatmullRom(value1.W, value2.W, value3.W, value4.W, amount); + } + + /// + /// Clamps the specified value within a range. + /// + /// The value to clamp. + /// The min value. + /// The max value. + /// The clamped value. + public static Vector4 Clamp(Vector4 value1, Vector4 min, Vector4 max) + { + return new Vector4( + MathHelper.Clamp(value1.X, min.X, max.X), + MathHelper.Clamp(value1.Y, min.Y, max.Y), + MathHelper.Clamp(value1.Z, min.Z, max.Z), + MathHelper.Clamp(value1.W, min.W, max.W)); + } + + /// + /// Clamps the specified value within a range. + /// + /// The value to clamp. + /// The min value. + /// The max value. + /// The clamped value as an output parameter. + public static void Clamp(ref Vector4 value1, ref Vector4 min, ref Vector4 max, out Vector4 result) + { + result.X = MathHelper.Clamp(value1.X, min.X, max.X); + result.Y = MathHelper.Clamp(value1.Y, min.Y, max.Y); + result.Z = MathHelper.Clamp(value1.Z, min.Z, max.Z); + result.W = MathHelper.Clamp(value1.W, min.W, max.W); + } + + /// + /// Returns the distance between two vectors. + /// + /// The first vector. + /// The second vector. + /// The distance between two vectors. + public static float Distance(Vector4 value1, Vector4 value2) + { + return (float)Math.Sqrt(DistanceSquared(value1, value2)); + } + + /// + /// Returns the distance between two vectors. + /// + /// The first vector. + /// The second vector. + /// The distance between two vectors as an output parameter. + public static void Distance(ref Vector4 value1, ref Vector4 value2, out float result) + { + result = (float)Math.Sqrt(DistanceSquared(value1, value2)); + } + + /// + /// Returns the squared distance between two vectors. + /// + /// The first vector. + /// The second vector. + /// The squared distance between two vectors. + public static float DistanceSquared(Vector4 value1, Vector4 value2) + { + return (value1.W - value2.W) * (value1.W - value2.W) + + (value1.X - value2.X) * (value1.X - value2.X) + + (value1.Y - value2.Y) * (value1.Y - value2.Y) + + (value1.Z - value2.Z) * (value1.Z - value2.Z); + } + + /// + /// Returns the squared distance between two vectors. + /// + /// The first vector. + /// The second vector. + /// The squared distance between two vectors as an output parameter. + public static void DistanceSquared(ref Vector4 value1, ref Vector4 value2, out float result) + { + result = (value1.W - value2.W) * (value1.W - value2.W) + + (value1.X - value2.X) * (value1.X - value2.X) + + (value1.Y - value2.Y) * (value1.Y - value2.Y) + + (value1.Z - value2.Z) * (value1.Z - value2.Z); + } + + /// + /// Divides the components of a by the components of another . + /// + /// Source . + /// Divisor . + /// The result of dividing the vectors. + public static Vector4 Divide(Vector4 value1, Vector4 value2) + { + value1.W /= value2.W; + value1.X /= value2.X; + value1.Y /= value2.Y; + value1.Z /= value2.Z; + return value1; + } + + /// + /// Divides the components of a by a scalar. + /// + /// Source . + /// Divisor scalar. + /// The result of dividing a vector by a scalar. + public static Vector4 Divide(Vector4 value1, float divider) + { + float factor = 1f / divider; + value1.W *= factor; + value1.X *= factor; + value1.Y *= factor; + value1.Z *= factor; + return value1; + } + + /// + /// Divides the components of a by a scalar. + /// + /// Source . + /// Divisor scalar. + /// The result of dividing a vector by a scalar as an output parameter. + public static void Divide(ref Vector4 value1, float divider, out Vector4 result) + { + float factor = 1f / divider; + result.W = value1.W * factor; + result.X = value1.X * factor; + result.Y = value1.Y * factor; + result.Z = value1.Z * factor; + } + + /// + /// Divides the components of a by the components of another . + /// + /// Source . + /// Divisor . + /// The result of dividing the vectors as an output parameter. + public static void Divide(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.W = value1.W / value2.W; + result.X = value1.X / value2.X; + result.Y = value1.Y / value2.Y; + result.Z = value1.Z / value2.Z; + } + + /// + /// Returns a dot product of two vectors. + /// + /// The first vector. + /// The second vector. + /// The dot product of two vectors. + public static float Dot(Vector4 value1, Vector4 value2) + { + return value1.X * value2.X + value1.Y * value2.Y + value1.Z * value2.Z + value1.W * value2.W; + } + + /// + /// Returns a dot product of two vectors. + /// + /// The first vector. + /// The second vector. + /// The dot product of two vectors as an output parameter. + public static void Dot(ref Vector4 value1, ref Vector4 value2, out float result) + { + result = value1.X * value2.X + value1.Y * value2.Y + value1.Z * value2.Z + value1.W * value2.W; + } + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public override bool Equals(object obj) + { + return (obj is Vector4) ? this == (Vector4)obj : false; + } + + /// + /// Compares whether current instance is equal to specified . + /// + /// The to compare. + /// true if the instances are equal; false otherwise. + public bool Equals(Vector4 other) + { + return this.W == other.W + && this.X == other.X + && this.Y == other.Y + && this.Z == other.Z; + } + + /// + /// Gets the hash code of this . + /// + /// Hash code of this . + public override int GetHashCode() + { + return (int)(this.W + this.X + this.Y + this.Y); + } + + /// + /// Creates a new that contains hermite spline interpolation. + /// + /// The first position vector. + /// The first tangent vector. + /// The second position vector. + /// The second tangent vector. + /// Weighting factor. + /// The hermite spline interpolation vector. + public static Vector4 Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount) + { + return new Vector4(MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount), + MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount), + MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount), + MathHelper.Hermite(value1.W, tangent1.W, value2.W, tangent2.W, amount)); + } + + /// + /// Creates a new that contains hermite spline interpolation. + /// + /// The first position vector. + /// The first tangent vector. + /// The second position vector. + /// The second tangent vector. + /// Weighting factor. + /// The hermite spline interpolation vector as an output parameter. + public static void Hermite(ref Vector4 value1, ref Vector4 tangent1, ref Vector4 value2, ref Vector4 tangent2, float amount, out Vector4 result) + { + result.W = MathHelper.Hermite(value1.W, tangent1.W, value2.W, tangent2.W, amount); + result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount); + result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount); + result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount); + } + + /// + /// Returns the length of this . + /// + /// The length of this . + public float Length() + { + float result = DistanceSquared(this, zero); + return (float)Math.Sqrt(result); + } + + /// + /// Returns the squared length of this . + /// + /// The squared length of this . + public float LengthSquared() + { + return DistanceSquared(this, zero); + } + + /// + /// Creates a new that contains linear interpolation of the specified vectors. + /// + /// The first vector. + /// The second vector. + /// Weighting value(between 0.0 and 1.0). + /// The result of linear interpolation of the specified vectors. + public static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount) + { + return new Vector4( + MathHelper.Lerp(value1.X, value2.X, amount), + MathHelper.Lerp(value1.Y, value2.Y, amount), + MathHelper.Lerp(value1.Z, value2.Z, amount), + MathHelper.Lerp(value1.W, value2.W, amount)); + } + + /// + /// Creates a new that contains linear interpolation of the specified vectors. + /// + /// The first vector. + /// The second vector. + /// Weighting value(between 0.0 and 1.0). + /// The result of linear interpolation of the specified vectors as an output parameter. + public static void Lerp(ref Vector4 value1, ref Vector4 value2, float amount, out Vector4 result) + { + result.X = MathHelper.Lerp(value1.X, value2.X, amount); + result.Y = MathHelper.Lerp(value1.Y, value2.Y, amount); + result.Z = MathHelper.Lerp(value1.Z, value2.Z, amount); + result.W = MathHelper.Lerp(value1.W, value2.W, amount); + } + + /// + /// Creates a new that contains a maximal values from the two vectors. + /// + /// The first vector. + /// The second vector. + /// The with maximal values from the two vectors. + public static Vector4 Max(Vector4 value1, Vector4 value2) + { + return new Vector4( + MathHelper.Max(value1.X, value2.X), + MathHelper.Max(value1.Y, value2.Y), + MathHelper.Max(value1.Z, value2.Z), + MathHelper.Max(value1.W, value2.W)); + } + + /// + /// Creates a new that contains a maximal values from the two vectors. + /// + /// The first vector. + /// The second vector. + /// The with maximal values from the two vectors as an output parameter. + public static void Max(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.X = MathHelper.Max(value1.X, value2.X); + result.Y = MathHelper.Max(value1.Y, value2.Y); + result.Z = MathHelper.Max(value1.Z, value2.Z); + result.W = MathHelper.Max(value1.W, value2.W); + } + + /// + /// Creates a new that contains a minimal values from the two vectors. + /// + /// The first vector. + /// The second vector. + /// The with minimal values from the two vectors. + public static Vector4 Min(Vector4 value1, Vector4 value2) + { + return new Vector4( + MathHelper.Min(value1.X, value2.X), + MathHelper.Min(value1.Y, value2.Y), + MathHelper.Min(value1.Z, value2.Z), + MathHelper.Min(value1.W, value2.W)); + } + + /// + /// Creates a new that contains a minimal values from the two vectors. + /// + /// The first vector. + /// The second vector. + /// The with minimal values from the two vectors as an output parameter. + public static void Min(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.X = MathHelper.Min(value1.X, value2.X); + result.Y = MathHelper.Min(value1.Y, value2.Y); + result.Z = MathHelper.Min(value1.Z, value2.Z); + result.W = MathHelper.Min(value1.W, value2.W); + } + + /// + /// Creates a new that contains a multiplication of two vectors. + /// + /// Source . + /// Source . + /// The result of the vector multiplication. + public static Vector4 Multiply(Vector4 value1, Vector4 value2) + { + value1.W *= value2.W; + value1.X *= value2.X; + value1.Y *= value2.Y; + value1.Z *= value2.Z; + return value1; + } + + /// + /// Creates a new that contains a multiplication of and a scalar. + /// + /// Source . + /// Scalar value. + /// The result of the vector multiplication with a scalar. + public static Vector4 Multiply(Vector4 value1, float scaleFactor) + { + value1.W *= scaleFactor; + value1.X *= scaleFactor; + value1.Y *= scaleFactor; + value1.Z *= scaleFactor; + return value1; + } + + /// + /// Creates a new that contains a multiplication of and a scalar. + /// + /// Source . + /// Scalar value. + /// The result of the multiplication with a scalar as an output parameter. + public static void Multiply(ref Vector4 value1, float scaleFactor, out Vector4 result) + { + result.W = value1.W * scaleFactor; + result.X = value1.X * scaleFactor; + result.Y = value1.Y * scaleFactor; + result.Z = value1.Z * scaleFactor; + } + + /// + /// Creates a new that contains a multiplication of two vectors. + /// + /// Source . + /// Source . + /// The result of the vector multiplication as an output parameter. + public static void Multiply(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.W = value1.W * value2.W; + result.X = value1.X * value2.X; + result.Y = value1.Y * value2.Y; + result.Z = value1.Z * value2.Z; + } + + /// + /// Creates a new that contains the specified vector inversion. + /// + /// Source . + /// The result of the vector inversion. + public static Vector4 Negate(Vector4 value) + { + value = new Vector4(-value.X, -value.Y, -value.Z, -value.W); + return value; + } + + /// + /// Creates a new that contains the specified vector inversion. + /// + /// Source . + /// The result of the vector inversion as an output parameter. + public static void Negate(ref Vector4 value, out Vector4 result) + { + result.X = -value.X; + result.Y = -value.Y; + result.Z = -value.Z; + result.W = -value.W; + } + + /// + /// Turns this to a unit vector with the same direction. + /// + public void Normalize() + { + Normalize(ref this, out this); + } + + /// + /// Creates a new that contains a normalized values from another vector. + /// + /// Source . + /// Unit vector. + public static Vector4 Normalize(Vector4 value) + { + float factor = DistanceSquared(value, zero); + factor = 1f / (float)Math.Sqrt(factor); + + return new Vector4(value.X*factor,value.Y*factor,value.Z*factor,value.W*factor); + } + + /// + /// Creates a new that contains a normalized values from another vector. + /// + /// Source . + /// Unit vector as an output parameter. + public static void Normalize(ref Vector4 value, out Vector4 result) + { + float factor = DistanceSquared(value, zero); + factor = 1f / (float)Math.Sqrt(factor); + + result.W = value.W * factor; + result.X = value.X * factor; + result.Y = value.Y * factor; + result.Z = value.Z * factor; + } + + /// + /// Creates a new that contains cubic interpolation of the specified vectors. + /// + /// Source . + /// Source . + /// Weighting value. + /// Cubic interpolation of the specified vectors. + public static Vector4 SmoothStep(Vector4 value1, Vector4 value2, float amount) + { + return new Vector4( + MathHelper.SmoothStep(value1.X, value2.X, amount), + MathHelper.SmoothStep(value1.Y, value2.Y, amount), + MathHelper.SmoothStep(value1.Z, value2.Z, amount), + MathHelper.SmoothStep(value1.W, value2.W, amount)); + } + + /// + /// Creates a new that contains cubic interpolation of the specified vectors. + /// + /// Source . + /// Source . + /// Weighting value. + /// Cubic interpolation of the specified vectors as an output parameter. + public static void SmoothStep(ref Vector4 value1, ref Vector4 value2, float amount, out Vector4 result) + { + result.X = MathHelper.SmoothStep(value1.X, value2.X, amount); + result.Y = MathHelper.SmoothStep(value1.Y, value2.Y, amount); + result.Z = MathHelper.SmoothStep(value1.Z, value2.Z, amount); + result.W = MathHelper.SmoothStep(value1.W, value2.W, amount); + } + + /// + /// Creates a new that contains subtraction of on from a another. + /// + /// Source . + /// Source . + /// The result of the vector subtraction. + public static Vector4 Subtract(Vector4 value1, Vector4 value2) + { + value1.W -= value2.W; + value1.X -= value2.X; + value1.Y -= value2.Y; + value1.Z -= value2.Z; + return value1; + } + + /// + /// Creates a new that contains subtraction of on from a another. + /// + /// Source . + /// Source . + /// The result of the vector subtraction as an output parameter. + public static void Subtract(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.W = value1.W - value2.W; + result.X = value1.X - value2.X; + result.Y = value1.Y - value2.Y; + result.Z = value1.Z - value2.Z; + } + + #region Transform + + /// + /// Creates a new that contains a transformation of 2d-vector by the specified . + /// + /// Source . + /// The transformation . + /// Transformed . + public static Vector4 Transform(Vector2 value, Matrix matrix) + { + Vector4 result; + Transform(ref value, ref matrix, out result); + return result; + } + + /// + /// Creates a new that contains a transformation of 2d-vector by the specified . + /// + /// Source . + /// The which contains rotation transformation. + /// Transformed . + public static Vector4 Transform(Vector2 value, Quaternion rotation) + { + Vector4 result; + Transform(ref value, ref rotation, out result); + return result; + } + + /// + /// Creates a new that contains a transformation of 3d-vector by the specified . + /// + /// Source . + /// The transformation . + /// Transformed . + public static Vector4 Transform(Vector3 value, Matrix matrix) + { + Vector4 result; + Transform(ref value, ref matrix, out result); + return result; + } + + /// + /// Creates a new that contains a transformation of 3d-vector by the specified . + /// + /// Source . + /// The which contains rotation transformation. + /// Transformed . + public static Vector4 Transform(Vector3 value, Quaternion rotation) + { + Vector4 result; + Transform(ref value, ref rotation, out result); + return result; + } + + /// + /// Creates a new that contains a transformation of 4d-vector by the specified . + /// + /// Source . + /// The transformation . + /// Transformed . + public static Vector4 Transform(Vector4 value, Matrix matrix) + { + Transform(ref value, ref matrix, out value); + return value; + } + + /// + /// Creates a new that contains a transformation of 4d-vector by the specified . + /// + /// Source . + /// The which contains rotation transformation. + /// Transformed . + public static Vector4 Transform(Vector4 value, Quaternion rotation) + { + Vector4 result; + Transform(ref value, ref rotation, out result); + return result; + } + + /// + /// Creates a new that contains a transformation of 2d-vector by the specified . + /// + /// Source . + /// The transformation . + /// Transformed as an output parameter. + public static void Transform(ref Vector2 value, ref Matrix matrix, out Vector4 result) + { + result.X = (value.X * matrix.M11) + (value.Y * matrix.M21) + matrix.M41; + result.Y = (value.X * matrix.M12) + (value.Y * matrix.M22) + matrix.M42; + result.Z = (value.X * matrix.M13) + (value.Y * matrix.M23) + matrix.M43; + result.W = (value.X * matrix.M14) + (value.Y * matrix.M24) + matrix.M44; + } + + /// + /// Creates a new that contains a transformation of 2d-vector by the specified . + /// + /// Source . + /// The which contains rotation transformation. + /// Transformed as an output parameter. + public static void Transform(ref Vector2 value, ref Quaternion rotation, out Vector4 result) + { + throw new NotImplementedException(); + } + + /// + /// Creates a new that contains a transformation of 3d-vector by the specified . + /// + /// Source . + /// The transformation . + /// Transformed as an output parameter. + public static void Transform(ref Vector3 value, ref Matrix matrix, out Vector4 result) + { + result.X = (value.X * matrix.M11) + (value.Y * matrix.M21) + (value.Z * matrix.M31) + matrix.M41; + result.Y = (value.X * matrix.M12) + (value.Y * matrix.M22) + (value.Z * matrix.M32) + matrix.M42; + result.Z = (value.X * matrix.M13) + (value.Y * matrix.M23) + (value.Z * matrix.M33) + matrix.M43; + result.W = (value.X * matrix.M14) + (value.Y * matrix.M24) + (value.Z * matrix.M34) + matrix.M44; + } + + /// + /// Creates a new that contains a transformation of 3d-vector by the specified . + /// + /// Source . + /// The which contains rotation transformation. + /// Transformed as an output parameter. + public static void Transform(ref Vector3 value, ref Quaternion rotation, out Vector4 result) + { + throw new NotImplementedException(); + } + + /// + /// Creates a new that contains a transformation of 4d-vector by the specified . + /// + /// Source . + /// The transformation . + /// Transformed as an output parameter. + public static void Transform(ref Vector4 value, ref Matrix matrix, out Vector4 result) + { + var x = (value.X * matrix.M11) + (value.Y * matrix.M21) + (value.Z * matrix.M31) + (value.W * matrix.M41); + var y = (value.X * matrix.M12) + (value.Y * matrix.M22) + (value.Z * matrix.M32) + (value.W * matrix.M42); + var z = (value.X * matrix.M13) + (value.Y * matrix.M23) + (value.Z * matrix.M33) + (value.W * matrix.M43); + var w = (value.X * matrix.M14) + (value.Y * matrix.M24) + (value.Z * matrix.M34) + (value.W * matrix.M44); + result.X = x; + result.Y = y; + result.Z = z; + result.W = w; + } + + /// + /// Creates a new that contains a transformation of 4d-vector by the specified . + /// + /// Source . + /// The which contains rotation transformation. + /// Transformed as an output parameter. + public static void Transform(ref Vector4 value, ref Quaternion rotation, out Vector4 result) + { + throw new NotImplementedException(); + } + + /// + /// Apply transformation on vectors within array of by the specified and places the results in an another array. + /// + /// Source array. + /// The starting index of transformation in the source array. + /// The transformation . + /// Destination array. + /// The starting index in the destination array, where the first should be written. + /// The number of vectors to be transformed. + public static void Transform + ( + Vector4[] sourceArray, + int sourceIndex, + ref Matrix matrix, + Vector4[] destinationArray, + int destinationIndex, + int length + ) + { + if (sourceArray == null) + throw new ArgumentNullException("sourceArray"); + if (destinationArray == null) + throw new ArgumentNullException("destinationArray"); + if (sourceArray.Length < sourceIndex + length) + throw new ArgumentException("Source array length is lesser than sourceIndex + length"); + if (destinationArray.Length < destinationIndex + length) + throw new ArgumentException("Destination array length is lesser than destinationIndex + length"); + + for (var i = 0; i < length; i++) + { + var value = sourceArray[sourceIndex + i]; + destinationArray[destinationIndex + i] = Transform(value, matrix); + } + } + + /// + /// Apply transformation on vectors within array of by the specified and places the results in an another array. + /// + /// Source array. + /// The starting index of transformation in the source array. + /// The which contains rotation transformation. + /// Destination array. + /// The starting index in the destination array, where the first should be written. + /// The number of vectors to be transformed. + public static void Transform( + Vector4[] sourceArray, + int sourceIndex, + ref Quaternion rotation, + Vector4[] destinationArray, + int destinationIndex, + int length + ) + { + if (sourceArray == null) + throw new ArgumentNullException("sourceArray"); + if (destinationArray == null) + throw new ArgumentNullException("destinationArray"); + if (sourceArray.Length < sourceIndex + length) + throw new ArgumentException("Source array length is lesser than sourceIndex + length"); + if (destinationArray.Length < destinationIndex + length) + throw new ArgumentException("Destination array length is lesser than destinationIndex + length"); + + for (var i = 0; i < length; i++) + { + var value = sourceArray[sourceIndex + i]; + destinationArray[destinationIndex + i] = Transform(value, rotation); + } + } + + /// + /// Apply transformation on all vectors within array of by the specified and places the results in an another array. + /// + /// Source array. + /// The transformation . + /// Destination array. + public static void Transform(Vector4[] sourceArray, ref Matrix matrix, Vector4[] destinationArray) + { + if (sourceArray == null) + throw new ArgumentNullException("sourceArray"); + if (destinationArray == null) + throw new ArgumentNullException("destinationArray"); + if (destinationArray.Length < sourceArray.Length) + throw new ArgumentException("Destination array length is lesser than source array length"); + + for (var i = 0; i < sourceArray.Length; i++) + { + var value = sourceArray[i]; + destinationArray[i] = Transform(value, matrix); + } + } + + /// + /// Apply transformation on all vectors within array of by the specified and places the results in an another array. + /// + /// Source array. + /// The which contains rotation transformation. + /// Destination array. + public static void Transform(Vector4[] sourceArray, ref Quaternion rotation, Vector4[] destinationArray) + { + if (sourceArray == null) + throw new ArgumentNullException("sourceArray"); + if (destinationArray == null) + throw new ArgumentNullException("destinationArray"); + if (destinationArray.Length < sourceArray.Length) + throw new ArgumentException("Destination array length is lesser than source array length"); + + for (var i = 0; i < sourceArray.Length; i++) + { + var value = sourceArray[i]; + destinationArray[i] = Transform(value, rotation); + } + } + + #endregion + + /// + /// Returns a representation of this in the format: + /// {X:[] Y:[] Z:[] W:[]} + /// + /// A representation of this . + public override string ToString() + { + return "{X:" + X + " Y:" + Y + " Z:" + Z + " W:" + W + "}"; + } + + #endregion + + #region Operators + + /// + /// Inverts values in the specified . + /// + /// Source on the right of the sub sign. + /// Result of the inversion. + public static Vector4 operator -(Vector4 value) + { + return new Vector4(-value.X, -value.Y, -value.Z, -value.W); + } + + /// + /// Compares whether two instances are equal. + /// + /// instance on the left of the equal sign. + /// instance on the right of the equal sign. + /// true if the instances are equal; false otherwise. + public static bool operator ==(Vector4 value1, Vector4 value2) + { + return value1.W == value2.W + && value1.X == value2.X + && value1.Y == value2.Y + && value1.Z == value2.Z; + } + + /// + /// Compares whether two instances are not equal. + /// + /// instance on the left of the not equal sign. + /// instance on the right of the not equal sign. + /// true if the instances are not equal; false otherwise. + public static bool operator !=(Vector4 value1, Vector4 value2) + { + return !(value1 == value2); + } + + /// + /// Adds two vectors. + /// + /// Source on the left of the add sign. + /// Source on the right of the add sign. + /// Sum of the vectors. + public static Vector4 operator +(Vector4 value1, Vector4 value2) + { + value1.W += value2.W; + value1.X += value2.X; + value1.Y += value2.Y; + value1.Z += value2.Z; + return value1; + } + + /// + /// Subtracts a from a . + /// + /// Source on the left of the sub sign. + /// Source on the right of the sub sign. + /// Result of the vector subtraction. + public static Vector4 operator -(Vector4 value1, Vector4 value2) + { + value1.W -= value2.W; + value1.X -= value2.X; + value1.Y -= value2.Y; + value1.Z -= value2.Z; + return value1; + } + + /// + /// Multiplies the components of two vectors by each other. + /// + /// Source on the left of the mul sign. + /// Source on the right of the mul sign. + /// Result of the vector multiplication. + public static Vector4 operator *(Vector4 value1, Vector4 value2) + { + value1.W *= value2.W; + value1.X *= value2.X; + value1.Y *= value2.Y; + value1.Z *= value2.Z; + return value1; + } + + /// + /// Multiplies the components of vector by a scalar. + /// + /// Source on the left of the mul sign. + /// Scalar value on the right of the mul sign. + /// Result of the vector multiplication with a scalar. + public static Vector4 operator *(Vector4 value, float scaleFactor) + { + value.W *= scaleFactor; + value.X *= scaleFactor; + value.Y *= scaleFactor; + value.Z *= scaleFactor; + return value; + } + + /// + /// Multiplies the components of vector by a scalar. + /// + /// Scalar value on the left of the mul sign. + /// Source on the right of the mul sign. + /// Result of the vector multiplication with a scalar. + public static Vector4 operator *(float scaleFactor, Vector4 value) + { + value.W *= scaleFactor; + value.X *= scaleFactor; + value.Y *= scaleFactor; + value.Z *= scaleFactor; + return value; + } + + /// + /// Divides the components of a by the components of another . + /// + /// Source on the left of the div sign. + /// Divisor on the right of the div sign. + /// The result of dividing the vectors. + public static Vector4 operator /(Vector4 value1, Vector4 value2) + { + value1.W /= value2.W; + value1.X /= value2.X; + value1.Y /= value2.Y; + value1.Z /= value2.Z; + return value1; + } + + /// + /// Divides the components of a by a scalar. + /// + /// Source on the left of the div sign. + /// Divisor scalar on the right of the div sign. + /// The result of dividing a vector by a scalar. + public static Vector4 operator /(Vector4 value1, float divider) + { + float factor = 1f / divider; + value1.W *= factor; + value1.X *= factor; + value1.Y *= factor; + value1.Z *= factor; + return value1; + } + + #endregion + } +} diff --git a/BarotraumaShared/Source/Characters/AI/AIController.cs b/BarotraumaShared/Source/Characters/AI/AIController.cs index a909e4e31..e8a535b04 100644 --- a/BarotraumaShared/Source/Characters/AI/AIController.cs +++ b/BarotraumaShared/Source/Characters/AI/AIController.cs @@ -4,9 +4,8 @@ using Microsoft.Xna.Framework.Graphics; namespace Barotrauma { - class AIController : ISteerable + partial class AIController : ISteerable { - public enum AiState { None, Attack, GoTo, Escape } public enum SteeringState { Wander, Seek, Escape } @@ -57,8 +56,6 @@ namespace Barotrauma Enabled = true; } - public virtual void DebugDraw(SpriteBatch spriteBatch) { } - public virtual void OnAttacked(IDamageable attacker, float amount) { } public virtual void SelectTarget(AITarget target) { } diff --git a/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs b/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs index bce305169..c819e3dff 100644 --- a/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs +++ b/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs @@ -4,7 +4,6 @@ using System.Xml.Linq; using FarseerPhysics; using FarseerPhysics.Dynamics.Joints; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Input; namespace Barotrauma { diff --git a/BarotraumaShared/Source/DebugConsole.cs b/BarotraumaShared/Source/DebugConsole.cs index 1101f292f..bd3d5ae5e 100644 --- a/BarotraumaShared/Source/DebugConsole.cs +++ b/BarotraumaShared/Source/DebugConsole.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using Barotrauma.Networking; using Barotrauma.Items.Components; using System.Text; diff --git a/BarotraumaShared/Source/GameSession/GameModes/GameMode.cs b/BarotraumaShared/Source/GameSession/GameModes/GameMode.cs index ae25c4ef2..5803458d2 100644 --- a/BarotraumaShared/Source/GameSession/GameModes/GameMode.cs +++ b/BarotraumaShared/Source/GameSession/GameModes/GameMode.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace Barotrauma { - class GameMode + partial class GameMode { public static List PresetList = new List(); @@ -55,10 +55,6 @@ namespace Barotrauma this.preset = preset; } - public virtual void Draw(SpriteBatch spriteBatch) - { - } - public virtual void Start() { startTime = DateTime.Now; diff --git a/BarotraumaShared/Source/Items/CharacterInventory.cs b/BarotraumaShared/Source/Items/CharacterInventory.cs index b6b476d79..1258ded3a 100644 --- a/BarotraumaShared/Source/Items/CharacterInventory.cs +++ b/BarotraumaShared/Source/Items/CharacterInventory.cs @@ -2,7 +2,6 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using Barotrauma.Networking; using Lidgren.Network; using System.Collections.Generic; @@ -18,8 +17,6 @@ namespace Barotrauma partial class CharacterInventory : Inventory { - private static Texture2D icons; - private Character character; public static InvSlotType[] limbSlots = new InvSlotType[] { diff --git a/BarotraumaShared/Source/Items/Components/DockingPort.cs b/BarotraumaShared/Source/Items/Components/DockingPort.cs index 6d6e35a40..88c426fce 100644 --- a/BarotraumaShared/Source/Items/Components/DockingPort.cs +++ b/BarotraumaShared/Source/Items/Components/DockingPort.cs @@ -392,7 +392,7 @@ namespace Barotrauma.Items.Components for (int i = 0; i < 2; i++) { - hullRects[i].Location -= (subs[i].WorldPosition - subs[i].HiddenSubPosition).ToPoint(); + hullRects[i].Location -= MathUtils.ToPoint((subs[i].WorldPosition - subs[i].HiddenSubPosition)); hulls[i] = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), hullRects[i], subs[i]); hulls[i].AddToGrid(subs[i]); @@ -422,7 +422,7 @@ namespace Barotrauma.Items.Components for (int i = 0; i < 2; i++) { - hullRects[i].Location -= (subs[i].WorldPosition - subs[i].HiddenSubPosition).ToPoint(); + hullRects[i].Location -= MathUtils.ToPoint((subs[i].WorldPosition - subs[i].HiddenSubPosition)); hulls[i] = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), hullRects[i], subs[i]); hulls[i].AddToGrid(subs[i]); diff --git a/BarotraumaShared/Source/Items/Item.cs b/BarotraumaShared/Source/Items/Item.cs index 6d96519d1..e1b0186b9 100644 --- a/BarotraumaShared/Source/Items/Item.cs +++ b/BarotraumaShared/Source/Items/Item.cs @@ -6,7 +6,6 @@ using FarseerPhysics.Dynamics.Contacts; using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; diff --git a/BarotraumaShared/Source/Items/ItemPrefab.cs b/BarotraumaShared/Source/Items/ItemPrefab.cs index d29c7de0f..ef7e8d130 100644 --- a/BarotraumaShared/Source/Items/ItemPrefab.cs +++ b/BarotraumaShared/Source/Items/ItemPrefab.cs @@ -5,7 +5,6 @@ using System.Xml.Linq; using FarseerPhysics; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; namespace Barotrauma { diff --git a/BarotraumaShared/Source/Map/Hull.cs b/BarotraumaShared/Source/Map/Hull.cs index a5856595b..027bd704f 100644 --- a/BarotraumaShared/Source/Map/Hull.cs +++ b/BarotraumaShared/Source/Map/Hull.cs @@ -281,11 +281,11 @@ namespace Barotrauma { if (grid.Submarine != submarine) continue; - rect.Location -= submarine.HiddenSubPosition.ToPoint(); + rect.Location -= MathUtils.ToPoint(submarine.HiddenSubPosition); grid.InsertEntity(this); - rect.Location += submarine.HiddenSubPosition.ToPoint(); + rect.Location += MathUtils.ToPoint(submarine.HiddenSubPosition); return; } } diff --git a/BarotraumaShared/Source/Map/Levels/CaveGenerator.cs b/BarotraumaShared/Source/Map/Levels/CaveGenerator.cs index dc1b8e536..ce744e8f7 100644 --- a/BarotraumaShared/Source/Map/Levels/CaveGenerator.cs +++ b/BarotraumaShared/Source/Map/Levels/CaveGenerator.cs @@ -13,7 +13,7 @@ using FarseerPhysics.Factories; namespace Barotrauma { - static class CaveGenerator + static partial class CaveGenerator { public static List CarveCave(List cells, Vector2 startPoint, out List newCells) { @@ -360,10 +360,9 @@ namespace Barotrauma return pathCells; } - public static List GeneratePolygons(List cells, out List verticeList, bool setSolid=true) + public static List GeneratePolygons(List cells, out List renderTriangles, bool setSolid=true) { - //TODO: consider separating body generation from render triangle generation - verticeList = new List(); + renderTriangles = null; var bodies = new List(); List tempVertices = new List(); @@ -396,20 +395,8 @@ namespace Barotrauma continue; } - var triangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center); - for (int i = 0; i < triangles.Count; i++) - { - foreach (Vector2 vertex in triangles[i]) - { - //shift the coordinates around a bit to make the texture repetition less obvious - Vector2 uvCoords = new Vector2( - vertex.X / 2000.0f + (float)Math.Sin(vertex.X / 500.0f) * 0.15f, - vertex.Y / 2000.0f + (float)Math.Sin(vertex.Y / 700.0f) * 0.15f); - - verticeList.Add(new VertexPositionTexture(new Vector3(vertex, 1.0f), uvCoords)); - } - } - + renderTriangles = MathUtils.TriangulateConvexHull(tempVertices, cell.Center); + if (bodyPoints.Count < 2) continue; if (bodyPoints.Count < 3) @@ -431,7 +418,7 @@ namespace Barotrauma if (cell.CellType == CellType.Empty) continue; - triangles = MathUtils.TriangulateConvexHull(bodyPoints, ConvertUnits.ToSimUnits(cell.Center)); + var triangles = MathUtils.TriangulateConvexHull(bodyPoints, ConvertUnits.ToSimUnits(cell.Center)); Body cellBody = new Body(GameMain.World); @@ -459,135 +446,6 @@ namespace Barotrauma return bodies; } - public static VertexPositionTexture[] GenerateWallShapes(List cells) - { - float inwardThickness = 500.0f, outWardThickness = 30.0f; - - List verticeList = new List(); - - foreach (VoronoiCell cell in cells) - { - //if (cell.body == null) continue; - foreach (GraphEdge edge in cell.edges) - { - if (edge.cell1 != null && edge.cell1.body == null && edge.cell1.CellType != CellType.Empty) edge.cell1 = null; - if (edge.cell2 != null && edge.cell2.body == null && edge.cell2.CellType != CellType.Empty) edge.cell2 = null; - - CompareCCW compare = new CompareCCW(cell.Center); - if (compare.Compare(edge.point1, edge.point2) == -1) - { - var temp = edge.point1; - edge.point1 = edge.point2; - edge.point2 = temp; - } - } - } - - foreach (VoronoiCell cell in cells) - { - //if (cell.body == null) continue; - foreach (GraphEdge edge in cell.edges) - { - if (!edge.isSolid) continue; - - GraphEdge leftEdge = cell.edges.Find(e => e != edge && (edge.point1 == e.point1 || edge.point1 == e.point2)); - GraphEdge rightEdge = cell.edges.Find(e => e != edge && (edge.point2 == e.point1 || edge.point2 == e.point2)); - - Vector2 leftNormal = Vector2.Zero, rightNormal = Vector2.Zero; - - if (leftEdge == null) - { - leftNormal = GetEdgeNormal(edge, cell); - } - else - { - leftNormal = (leftEdge.isSolid) ? - Vector2.Normalize(GetEdgeNormal(leftEdge) + GetEdgeNormal(edge, cell)) : - Vector2.Normalize(leftEdge.Center - edge.point1); - } - - - if (!MathUtils.IsValid(leftNormal)) - { -#if DEBUG - DebugConsole.ThrowError("Invalid left normal"); -#endif - if (cell.body != null) - { - GameMain.World.RemoveBody(cell.body); - cell.body = null; - } - leftNormal = Vector2.UnitX; - break; - } - - - if (rightEdge == null) - { - rightNormal = GetEdgeNormal(edge, cell); - } - else - { - rightNormal = (rightEdge.isSolid) ? - Vector2.Normalize(GetEdgeNormal(rightEdge) + GetEdgeNormal(edge, cell)) : - Vector2.Normalize(rightEdge.Center - edge.point2); - } - - if (!MathUtils.IsValid(rightNormal)) - { -#if DEBUG - DebugConsole.ThrowError("Invalid right normal"); -#endif - if (cell.body != null) - { - GameMain.World.RemoveBody(cell.body); - cell.body = null; - } - rightNormal = Vector2.UnitX; - break; - } - - for (int i = 0; i < 2; i++) - { - Vector2[] verts = new Vector2[3]; - VertexPositionTexture[] vertPos = new VertexPositionTexture[3]; - - - if (i == 0) - { - verts[0] = edge.point1 - leftNormal * outWardThickness; - verts[1] = edge.point2 - rightNormal * outWardThickness; - verts[2] = edge.point1 + leftNormal * inwardThickness; - - vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), Vector2.Zero); - vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX); - vertPos[2] = new VertexPositionTexture(new Vector3(verts[2], 0.0f), new Vector2(0, 0.5f)); - } - else - { - verts[0] = edge.point1 + leftNormal * inwardThickness; - verts[1] = edge.point2 - rightNormal * outWardThickness; - verts[2] = edge.point2 + rightNormal * inwardThickness; - - vertPos[0] = new VertexPositionTexture(new Vector3(verts[0], 0.0f), new Vector2(0.0f, 0.5f)); - vertPos[1] = new VertexPositionTexture(new Vector3(verts[1], 0.0f), Vector2.UnitX); - vertPos[2] = new VertexPositionTexture(new Vector3(verts[2], 0.0f), new Vector2(1.0f, 0.5f)); - } - - var comparer = new CompareCCW((verts[0] + verts[1] + verts[2]) / 3.0f); - Array.Sort(verts, vertPos, comparer); - - for (int j = 0; j < 3; j++) - { - verticeList.Add(vertPos[j]); - } - } - } - } - - return verticeList.ToArray(); - } - /// /// find the index of the cell which the point is inside /// (actually finds the cell whose center is closest, but it's always the correct cell assuming the point is inside the borders of the diagram) diff --git a/BarotraumaShared/Source/Map/Levels/Level.cs b/BarotraumaShared/Source/Map/Levels/Level.cs index 87cf7682f..d9fe04fde 100644 --- a/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/BarotraumaShared/Source/Map/Levels/Level.cs @@ -440,11 +440,12 @@ namespace Barotrauma List cellsWithBody = new List(cells); - List bodyVertices; - bodies = CaveGenerator.GeneratePolygons(cellsWithBody, out bodyVertices); + List triangles; + bodies = CaveGenerator.GeneratePolygons(cellsWithBody, out triangles); #if CLIENT - + List bodyVertices = CaveGenerator.GenerateRenderVerticeList(triangles); + renderer.SetBodyVertices(bodyVertices.ToArray()); renderer.SetWallVertices(CaveGenerator.GenerateWallShapes(cells)); @@ -714,7 +715,7 @@ namespace Barotrauma } } - var ruin = new Ruin(closestPathCell, cells, new Rectangle((ruinPos - ruinSize * 0.5f).ToPoint(), ruinSize.ToPoint())); + var ruin = new Ruin(closestPathCell, cells, new Rectangle(MathUtils.ToPoint(ruinPos - ruinSize * 0.5f), MathUtils.ToPoint(ruinSize))); ruins.Add(ruin); ruin.RuinShapes.Sort((shape1, shape2) => shape2.DistanceFromEntrance.CompareTo(shape1.DistanceFromEntrance)); diff --git a/BarotraumaShared/Source/Map/LinkedSubmarine.cs b/BarotraumaShared/Source/Map/LinkedSubmarine.cs index 877395290..04d8e65ec 100644 --- a/BarotraumaShared/Source/Map/LinkedSubmarine.cs +++ b/BarotraumaShared/Source/Map/LinkedSubmarine.cs @@ -1,7 +1,6 @@ using Barotrauma.Items.Components; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.IO; @@ -157,7 +156,7 @@ namespace Barotrauma linkedSub.loadSub = true; - linkedSub.rect.Location = pos.ToPoint(); + linkedSub.rect.Location = MathUtils.ToPoint(pos); } linkedSub.filePath = ToolBox.GetAttributeString(element, "filepath", ""); diff --git a/BarotraumaShared/Source/Map/MapEntity.cs b/BarotraumaShared/Source/Map/MapEntity.cs index 6921d6677..1d56baa95 100644 --- a/BarotraumaShared/Source/Map/MapEntity.cs +++ b/BarotraumaShared/Source/Map/MapEntity.cs @@ -6,7 +6,6 @@ using System.Xml.Linq; using FarseerPhysics; using Microsoft.Xna.Framework; //using Microsoft.Xna.Framework.Graphics; -//using Microsoft.Xna.Framework.Input; using System.Collections.ObjectModel; using Barotrauma.Items.Components; diff --git a/BarotraumaShared/Source/Map/MapEntityPrefab.cs b/BarotraumaShared/Source/Map/MapEntityPrefab.cs index 9a9841ea2..752d388ef 100644 --- a/BarotraumaShared/Source/Map/MapEntityPrefab.cs +++ b/BarotraumaShared/Source/Map/MapEntityPrefab.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Reflection; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; namespace Barotrauma { @@ -152,7 +151,7 @@ namespace Barotrauma if (Submarine.MainSub != null) { - newRect.Location -= Submarine.MainSub.Position.ToPoint(); + newRect.Location -= MathUtils.ToPoint(Submarine.MainSub.Position); } if (PlayerInput.LeftButtonReleased()) diff --git a/BarotraumaShared/Source/Map/StructurePrefab.cs b/BarotraumaShared/Source/Map/StructurePrefab.cs index da1c24422..cc9a9a9e4 100644 --- a/BarotraumaShared/Source/Map/StructurePrefab.cs +++ b/BarotraumaShared/Source/Map/StructurePrefab.cs @@ -175,7 +175,7 @@ namespace Barotrauma //don't allow resizing width/height to zero if ((!resizeHorizontal || placeSize.X != 0.0f) && (!resizeVertical || placeSize.Y != 0.0f)) { - newRect.Location -= Submarine.MainSub.Position.ToPoint(); + newRect.Location -= MathUtils.ToPoint(Submarine.MainSub.Position); var structure = new Structure(newRect, this, Submarine.MainSub); structure.Submarine = Submarine.MainSub; diff --git a/BarotraumaShared/Source/Map/Submarine.cs b/BarotraumaShared/Source/Map/Submarine.cs index 92fefba7b..bf0c4aa5c 100644 --- a/BarotraumaShared/Source/Map/Submarine.cs +++ b/BarotraumaShared/Source/Map/Submarine.cs @@ -307,7 +307,7 @@ namespace Barotrauma Rectangle dockedSubBorders = dockedSub.Borders; dockedSubBorders.Y -= dockedSubBorders.Height; - dockedSubBorders.Location += diff.ToPoint(); + dockedSubBorders.Location += MathUtils.ToPoint(diff); dockedBorders = Rectangle.Union(dockedBorders, dockedSubBorders); } @@ -740,7 +740,7 @@ namespace Barotrauma foreach (Submarine sub in Submarine.Loaded) { Rectangle subBorders = sub.Borders; - subBorders.Location += sub.HiddenSubPosition.ToPoint() - new Microsoft.Xna.Framework.Point(0, sub.Borders.Height); + subBorders.Location += MathUtils.ToPoint(sub.HiddenSubPosition) - new Microsoft.Xna.Framework.Point(0, sub.Borders.Height); subBorders.Inflate(500.0f, 500.0f); diff --git a/BarotraumaShared/Source/Map/SubmarineBody.cs b/BarotraumaShared/Source/Map/SubmarineBody.cs index 9b45a5fc6..84e27994b 100644 --- a/BarotraumaShared/Source/Map/SubmarineBody.cs +++ b/BarotraumaShared/Source/Map/SubmarineBody.cs @@ -238,7 +238,7 @@ namespace Barotrauma if (Position.X < 0 || Position.X > Level.Loaded.Size.X) { Rectangle worldBorders = Borders; - worldBorders.Location += Position.ToPoint(); + worldBorders.Location += MathUtils.ToPoint(Position); //push the sub back below the upper "barrier" of the level if (worldBorders.Y > Level.Loaded.Size.Y) @@ -276,7 +276,7 @@ namespace Barotrauma private void DisplaceCharacters(Vector2 subTranslation) { Rectangle worldBorders = Borders; - worldBorders.Location += ConvertUnits.ToDisplayUnits(Body.SimPosition).ToPoint(); + worldBorders.Location += MathUtils.ToPoint(ConvertUnits.ToDisplayUnits(Body.SimPosition)); Vector2 translateDir = Vector2.Normalize(subTranslation); diff --git a/BarotraumaShared/Source/Map/WayPoint.cs b/BarotraumaShared/Source/Map/WayPoint.cs index 725559a18..fa3ab031f 100644 --- a/BarotraumaShared/Source/Map/WayPoint.cs +++ b/BarotraumaShared/Source/Map/WayPoint.cs @@ -5,7 +5,6 @@ using System.Xml.Linq; using FarseerPhysics; using Microsoft.Xna.Framework; //using Microsoft.Xna.Framework.Graphics; -//using Microsoft.Xna.Framework.Input; using System.Collections.ObjectModel; using Barotrauma.Items.Components; using FarseerPhysics.Dynamics; @@ -181,7 +180,7 @@ namespace Barotrauma borders.Width += outsideWaypointDist * 2; borders.Height += outsideWaypointDist * 2; - borders.Location -= submarine.HiddenSubPosition.ToPoint(); + borders.Location -= MathUtils.ToPoint(submarine.HiddenSubPosition); if (borders.Width <= outSideWaypointInterval*2) { diff --git a/BarotraumaShared/Source/Networking/NetworkMember.cs b/BarotraumaShared/Source/Networking/NetworkMember.cs index 8548b3875..09e48d9cc 100644 --- a/BarotraumaShared/Source/Networking/NetworkMember.cs +++ b/BarotraumaShared/Source/Networking/NetworkMember.cs @@ -2,7 +2,6 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using System.Collections.Generic; using Lidgren.Network; using Barotrauma.Items.Components; diff --git a/BarotraumaShared/Source/Physics/PhysicsBody.cs b/BarotraumaShared/Source/Physics/PhysicsBody.cs index caeea85dc..9764f2659 100644 --- a/BarotraumaShared/Source/Physics/PhysicsBody.cs +++ b/BarotraumaShared/Source/Physics/PhysicsBody.cs @@ -248,12 +248,6 @@ namespace Barotrauma set { body.CollidesWith = value; } } - private Texture2D bodyShapeTexture; - public Texture2D BodyShapeTexture - { - get { return bodyShapeTexture; } - } - public PhysicsBody(XElement element, float scale = 1.0f) : this(element, Vector2.Zero, scale) { @@ -538,11 +532,7 @@ namespace Barotrauma list.Remove(this); GameMain.World.RemoveBody(body); - if (bodyShapeTexture != null) - { - bodyShapeTexture.Dispose(); - bodyShapeTexture = null; - } + DisposeProjSpecific(); } } diff --git a/BarotraumaShared/Source/Screens/GameScreen.cs b/BarotraumaShared/Source/Screens/GameScreen.cs index 7d6ced9ca..d6a04df73 100644 --- a/BarotraumaShared/Source/Screens/GameScreen.cs +++ b/BarotraumaShared/Source/Screens/GameScreen.cs @@ -1,6 +1,5 @@ using Microsoft.Xna.Framework; #if CLIENT -using Microsoft.Xna.Framework.Input; #endif namespace Barotrauma diff --git a/BarotraumaShared/Source/Utils/MathUtils.cs b/BarotraumaShared/Source/Utils/MathUtils.cs index 48d73b9df..c8984c989 100644 --- a/BarotraumaShared/Source/Utils/MathUtils.cs +++ b/BarotraumaShared/Source/Utils/MathUtils.cs @@ -42,6 +42,11 @@ namespace Barotrauma return (float)Math.Atan2(vector.Y, vector.X); } + public static Point ToPoint(Vector2 vector) + { + return new Point((int)vector.X,(int)vector.Y); + } + public static bool IsValid(float value) { return (!float.IsInfinity(value) && !float.IsNaN(value)); diff --git a/Barotrauma_Solution.sln b/Barotrauma_Solution.sln index 718c95b44..7237fb4c8 100644 --- a/Barotrauma_Solution.sln +++ b/Barotrauma_Solution.sln @@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Barotrauma", "Barotrauma", EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{DE36F45F-F09E-4719-B953-00D148F7722A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Farseer Physics", "Farseer Physics Engine 3.5\Farseer Physics.csproj", "{A4610E4C-DD34-428B-BABB-779CA0B5993A}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution BarotraumaShared\BarotraumaShared.projitems*{008c0f83-e914-4966-9135-ea885059edd8}*SharedItemsImports = 4 @@ -408,6 +410,60 @@ Global {85232B20-074D-4723-B0C6-91495391E448}.Windows8|Mixed Platforms.Build.0 = Release|x86 {85232B20-074D-4723-B0C6-91495391E448}.Windows8|x86.ActiveCfg = Release|x86 {85232B20-074D-4723-B0C6-91495391E448}.Windows8|x86.Build.0 = Release|x86 + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Android|Any CPU.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Android|Any CPU.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Android|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Android|Mixed Platforms.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Android|x86.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Android|x86.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Debug|x86.ActiveCfg = Debug|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Debug|x86.Build.0 = Debug|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.iOS|Any CPU.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.iOS|Any CPU.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.iOS|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.iOS|Mixed Platforms.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.iOS|x86.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.iOS|x86.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Linux|Any CPU.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Linux|Any CPU.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Linux|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Linux|Mixed Platforms.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Linux|x86.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Linux|x86.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.OSX|Any CPU.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.OSX|Any CPU.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.OSX|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.OSX|Mixed Platforms.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.OSX|x86.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.OSX|x86.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.PSM|Any CPU.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.PSM|Any CPU.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.PSM|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.PSM|Mixed Platforms.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.PSM|x86.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.PSM|x86.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Release|Any CPU.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Release|x86.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Release|x86.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows|Any CPU.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows|Any CPU.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows|Mixed Platforms.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows|x86.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows|x86.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows8|Any CPU.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows8|Any CPU.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows8|Mixed Platforms.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows8|Mixed Platforms.Build.0 = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows8|x86.ActiveCfg = Release|Any CPU + {A4610E4C-DD34-428B-BABB-779CA0B5993A}.Windows8|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -422,5 +478,6 @@ Global {2E4773B7-961A-4328-9D77-9749F9071CA2} = {DE36F45F-F09E-4719-B953-00D148F7722A} {85232B20-074D-4723-B0C6-91495391E448} = {F35DF9BF-0BED-4FEF-A51C-DD83C531882F} {561357C2-DB28-4E01-B275-6BF545F70491} = {F35DF9BF-0BED-4FEF-A51C-DD83C531882F} + {A4610E4C-DD34-428B-BABB-779CA0B5993A} = {DE36F45F-F09E-4719-B953-00D148F7722A} EndGlobalSection EndGlobal diff --git a/Farseer Physics Engine 3.5/Common/MathHelper.cs b/Farseer Physics Engine 3.5/Common/MathHelper.cs index 3f48a8b76..02a4cbb0c 100644 --- a/Farseer Physics Engine 3.5/Common/MathHelper.cs +++ b/Farseer Physics Engine 3.5/Common/MathHelper.cs @@ -72,6 +72,18 @@ namespace Microsoft.Xna.Framework return value; } + public static int Clamp(int value, int min, int max) + { + // First we check to see if we're greater than the max + value = (value > max) ? max : value; + + // Then we check to see if we're less than the min. + value = (value < min) ? min : value; + + // There's no check to see if min > max. + return value; + } + public static float Distance(float value1, float value2) { return Math.Abs(value1 - value2);