Unstable 1.8.4.0
This commit is contained in:
@@ -7,8 +7,13 @@ namespace Barotrauma.Extensions
|
||||
public static Color Multiply(this Color color, float value, bool onlyAlpha = false)
|
||||
{
|
||||
return onlyAlpha ?
|
||||
new Color(color.R, color.G, color.B, (byte)(color.A * value)) :
|
||||
new Color((byte)(color.R * value), (byte)(color.G * value), (byte)(color.B * value), (byte)(color.A * value));
|
||||
new Color(color.R, color.G, color.B, MultiplyComponent(color.A, value)) :
|
||||
new Color(MultiplyComponent(color.R, value), MultiplyComponent(color.G, value), MultiplyComponent(color.B, value), MultiplyComponent(color.A, value));
|
||||
|
||||
static byte MultiplyComponent(float colorComponent, float multiplier)
|
||||
{
|
||||
return (byte)MathHelper.Clamp(colorComponent * multiplier, 0.0f, 255.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public static Color Multiply(this Color thisColor, Color color)
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// NOTE: We should use struct in addition to Enum in all the type constraints (at the end of the method signatures), as it
|
||||
// tells the compiler that we're only ever using value types, which enums always are anyway.
|
||||
// This avoids a lot of allocations caused by the compiler preparing for anything, which in turn happens because despite
|
||||
// how it works in practice, Enum is counted as a reference type in C#... for historical reasons.
|
||||
|
||||
// We use the (int)(object) cast because generic types can't be cast directly to int, so we box into object and unbox into int instead.
|
||||
// It avoids some memory allocations that Convert.ToInt32() seems to do.
|
||||
// NOTE: This should work fine as long as the enum values stay within - to + 2^31, so let's not use uint or long for them.
|
||||
|
||||
namespace Barotrauma.Extensions
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum.HasFlag() checks if all flags matches. This method checks if any of them matches.
|
||||
/// Enum.HasFlag() checks if all flags matches. This method checks if any of them matches. It also avoids boxing allocations that the built-in version might still sometimes cause.
|
||||
/// E.g. when myEnum = SomeEnum.First | SomeEnum.Second, myEnum.HasFlag(SomeEnum.First | SomeEnum.Third) returns false, because not all of the flags match, but HasAnyFlag(SomeEnum.First | SomeEnum.Third) returns true, because some of the flags match.
|
||||
/// </summary>
|
||||
public static bool HasAnyFlag<T>(this T type, T value) where T : Enum
|
||||
public static bool HasAnyFlag<T>(this T type, T value) where T : struct, Enum
|
||||
{
|
||||
int typeValue = Convert.ToInt32(type);
|
||||
int flagValue = Convert.ToInt32(value);
|
||||
int typeValue = (int)(object)type;
|
||||
int flagValue = (int)(object)value;
|
||||
return (typeValue & flagValue) != 0;
|
||||
}
|
||||
|
||||
@@ -19,10 +29,10 @@ namespace Barotrauma.Extensions
|
||||
/// Adds a flag value to an enum.
|
||||
/// Note that enums are value types, so you need to use the value returned from this method.
|
||||
/// </summary>
|
||||
public static T AddFlag<T>(this T @enum, T flag) where T : Enum
|
||||
public static T AddFlag<T>(this T @enum, T flag) where T : struct, Enum
|
||||
{
|
||||
int enumValue = Convert.ToInt32(@enum);
|
||||
int flagValue = Convert.ToInt32(flag);
|
||||
int enumValue = (int)(object)@enum;
|
||||
int flagValue = (int)(object)flag;
|
||||
return (T)(object)(enumValue | flagValue);
|
||||
}
|
||||
|
||||
@@ -30,11 +40,19 @@ namespace Barotrauma.Extensions
|
||||
/// Removes a flag value from an enum.
|
||||
/// Note that enums are value types, so you need to use the value returned from this method.
|
||||
/// </summary>
|
||||
public static T RemoveFlag<T>(this T @enum, T flag) where T : Enum
|
||||
public static T RemoveFlag<T>(this T @enum, T flag) where T : struct, Enum
|
||||
{
|
||||
int enumValue = Convert.ToInt32(@enum);
|
||||
int flagValue = Convert.ToInt32(flag);
|
||||
int enumValue = (int)(object)@enum;
|
||||
int flagValue = (int)(object)flag;
|
||||
return (T)(object)(enumValue & ~flagValue);
|
||||
}
|
||||
|
||||
public static IEnumerable<T> GetIndividualFlags<T>(T flagsEnum) where T : struct, Enum
|
||||
{
|
||||
foreach (T value in Enum.GetValues(typeof(T)))
|
||||
{
|
||||
if (flagsEnum.HasAnyFlag(value)) { yield return value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,9 @@ public sealed class EpicAccountId : AccountId
|
||||
public new static Option<EpicAccountId> Parse(string str)
|
||||
{
|
||||
if (str.IsNullOrWhiteSpace()) { return Option.None; }
|
||||
//according to the documentation, this is the maximum length of the ID
|
||||
const int MaxEpicAccountIDLength = 32 + 1;
|
||||
if (str.Length > MaxEpicAccountIDLength + prefix.Length) { return Option.None; }
|
||||
if (str.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { str = str[prefix.Length..]; }
|
||||
if (!str.IsHexString()) { return Option.None; }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -140,7 +141,25 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
public static Identifier[] ToIdentifiers(this string[] strings)
|
||||
=> ((IEnumerable<string>)strings).ToIdentifiers().ToArray();
|
||||
=> strings.AsEnumerable().ToIdentifiers().ToArray();
|
||||
|
||||
/// <summary>
|
||||
/// Parses identifiers from a comma separated string.
|
||||
/// </summary>
|
||||
public static IEnumerable<Identifier> ToIdentifiers(this string tagsString, string separator = ",")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(tagsString))
|
||||
{
|
||||
return Enumerable.Empty<Identifier>();
|
||||
}
|
||||
return tagsString.Split(separator, StringSplitOptions.TrimEntries).AsEnumerable().ToIdentifiers();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a comma separated string from a collection of identifier.
|
||||
/// </summary>
|
||||
public static string ConvertToString(this IEnumerable<Identifier> tags, string separator = ",")
|
||||
=> string.Join(separator, tags);
|
||||
|
||||
public static Identifier ToIdentifier(this string? s)
|
||||
{
|
||||
|
||||
@@ -375,7 +375,19 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the point where the line segment between a1 and a2 intersects the rectangle. Note that the rectangle's y-coordinate is handled so that up is lower and bottom is higher (the way rectangles work by default in XNA).
|
||||
/// </summary>
|
||||
public static bool GetLineRectangleIntersection(Vector2 a1, Vector2 a2, Rectangle rect, out Vector2 intersection)
|
||||
{
|
||||
rect.Y += rect.Height;
|
||||
return GetLineWorldRectangleIntersection(a1, a2, rect, out intersection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the point where the line segment between a1 and a2 intersects the rectangle. Note that the rectangle's y-coordinate is handled so that up is greater and down is lower (the way e.g. MapEntity rects are defined).
|
||||
/// </summary>
|
||||
public static bool GetLineWorldRectangleIntersection(Vector2 a1, Vector2 a2, Rectangle rect, out Vector2 intersection)
|
||||
{
|
||||
if (GetAxisAlignedLineIntersection(a1, a2,
|
||||
new Vector2(rect.X, rect.Y),
|
||||
@@ -678,7 +690,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// divide a convex hull into triangles
|
||||
/// Divide a convex hull into triangles
|
||||
/// </summary>
|
||||
/// <returns>List of triangle vertices (sorted counter-clockwise)</returns>
|
||||
public static List<Vector2[]> TriangulateConvexHull(List<Vector2> vertices, Vector2 center)
|
||||
@@ -1100,6 +1112,52 @@ namespace Barotrauma
|
||||
while (val > po2) { po2 <<= 1; }
|
||||
return po2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes an array of vectors to a different size. Uses bilinear interpolation to "scale" the values to the size of the new array:
|
||||
/// for instance, an array such as "1, 0" would become "1, 0.5, 0" when the width is scaled from 2 to 3.
|
||||
/// </summary>
|
||||
public static Vector2[,] ResizeVector2Array(Vector2[,] sourceArray, int newWidth, int newHeight)
|
||||
{
|
||||
if (newWidth < 1)
|
||||
{
|
||||
throw new ArgumentException("Width must be larger than zero.", nameof(newWidth));
|
||||
}
|
||||
if (newHeight < 1)
|
||||
{
|
||||
throw new ArgumentException("Height must be larger than zero.", nameof(newHeight));
|
||||
}
|
||||
|
||||
var destinationArray = new Vector2[newWidth, newHeight];
|
||||
int oldWidth = sourceArray.GetLength(0), oldHeight = sourceArray.GetLength(1);
|
||||
|
||||
for (int x = 0; x < newWidth; x++)
|
||||
{
|
||||
for (int y = 0; y < newHeight; y++)
|
||||
{
|
||||
// Calculate the position in the original array
|
||||
float sourceX = oldWidth == 1 ? 0 : (x / (float)(newWidth - 1)) * (oldWidth - 1);
|
||||
float sourceY = oldHeight == 1 ? 0 : (y / (float)(newHeight - 1)) * (oldHeight - 1);
|
||||
|
||||
// Find the indices of the surrounding points
|
||||
int startIndexX = (int)Math.Floor(sourceX);
|
||||
int endIndexX = Math.Min(startIndexX + 1, oldWidth - 1);
|
||||
int startIndexY = (int)Math.Floor(sourceY);
|
||||
int endIndexY = Math.Min(startIndexY + 1, oldHeight - 1);
|
||||
|
||||
// Calculate interpolation weights
|
||||
float tx = sourceX - startIndexX;
|
||||
float ty = sourceY - startIndexY;
|
||||
|
||||
// Perform bilinear interpolation
|
||||
Vector2 top = Vector2.Lerp(sourceArray[startIndexX, startIndexY], sourceArray[endIndexX, startIndexY], tx);
|
||||
Vector2 bottom = Vector2.Lerp(sourceArray[startIndexX, endIndexY], sourceArray[endIndexX, endIndexY], tx);
|
||||
destinationArray[x, y] = Vector2.Lerp(top, bottom, ty);
|
||||
}
|
||||
}
|
||||
|
||||
return destinationArray;
|
||||
}
|
||||
}
|
||||
|
||||
public class CompareCW : IComparer<Vector2>
|
||||
@@ -1156,4 +1214,5 @@ namespace Barotrauma
|
||||
return -CompareCW.Compare(a, b, center);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,10 +113,9 @@ namespace Barotrauma
|
||||
/// Gets a type by its name, with backwards compatibility for types that have been renamed.
|
||||
/// <see cref="TypePreviouslyKnownAs"/>
|
||||
/// </summary>
|
||||
public static Type? GetTypeWithBackwardsCompatibility(string nameSpace, string typeName, bool throwOnError, bool ignoreCase)
|
||||
public static Type? GetTypeWithBackwardsCompatibility(Assembly assembly, string nameSpace, string typeName, bool throwOnError, bool ignoreCase)
|
||||
{
|
||||
if (Assembly.GetEntryAssembly() is not { } entryAssembly) { return null; }
|
||||
var types = entryAssembly
|
||||
var types = assembly
|
||||
.GetTypes()
|
||||
.Where(t => NameMatches(t.Namespace, nameSpace, ignoreCase));
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace Steamworks.Data
|
||||
internal static extern bool InternalIsIPv6AllZeros( ref NetAddress self );
|
||||
|
||||
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_SteamNetworkingIPAddr_SetIPv6", CallingConvention = Platform.CC)]
|
||||
internal static extern void InternalSetIPv6( ref NetAddress self, ref byte ipv6, ushort nPort );
|
||||
internal static extern void InternalSetIPv6( ref NetAddress self, IntPtr ipv6, ushort nPort );
|
||||
|
||||
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_SteamNetworkingIPAddr_SetIPv4", CallingConvention = Platform.CC)]
|
||||
internal static extern void InternalSetIPv4( ref NetAddress self, uint nIP, ushort nPort );
|
||||
|
||||
@@ -60,18 +60,33 @@ namespace Steamworks.Data
|
||||
/// Specific IP, specific port
|
||||
/// </summary>
|
||||
public static NetAddress From( IPAddress address, ushort port )
|
||||
{
|
||||
var addr = address.GetAddressBytes();
|
||||
{
|
||||
var local = Cleared;
|
||||
switch (address.AddressFamily)
|
||||
{
|
||||
case System.Net.Sockets.AddressFamily.InterNetwork:
|
||||
InternalSetIPv4(ref local, address.IpToInt32(), port);
|
||||
return local;
|
||||
case System.Net.Sockets.AddressFamily.InterNetworkV6:
|
||||
var ptr = GetIpv6AddressBytesPtr(address);
|
||||
InternalSetIPv6(ref local, ptr, port);
|
||||
FreeMemory(ptr);
|
||||
return local;
|
||||
default:
|
||||
throw new System.NotImplementedException( $"Oops - no {address.AddressFamily} support yet?" );
|
||||
}
|
||||
|
||||
if ( address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork )
|
||||
{
|
||||
var local = Cleared;
|
||||
InternalSetIPv4( ref local, Utility.IpToInt32( address ), port );
|
||||
return local;
|
||||
}
|
||||
static System.IntPtr GetIpv6AddressBytesPtr(IPAddress address)
|
||||
{
|
||||
byte[] bytes = address.GetAddressBytes();
|
||||
var unmanagedPointer = Marshal.AllocHGlobal(bytes.Length);
|
||||
Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length);
|
||||
return unmanagedPointer;
|
||||
}
|
||||
|
||||
throw new System.NotImplementedException( "Oops - no IPV6 support yet?" );
|
||||
}
|
||||
void FreeMemory(System.IntPtr unmanagedMemory)
|
||||
=> Marshal.FreeHGlobal(unmanagedMemory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set everything to zero
|
||||
|
||||
@@ -116,10 +116,10 @@ namespace Steamworks.Ugc
|
||||
/// The number of downvotes of this item
|
||||
/// </summary>
|
||||
public uint VotesDown => details.VotesDown;
|
||||
/// <summary>
|
||||
/// Dependencies/children of this item or collection, available only from WithDependencies(true) queries
|
||||
/// </summary>
|
||||
public PublishedFileId[]? Children;
|
||||
/// <summary>
|
||||
/// Dependencies/children of this item or collection, available only from WithChildren(true) queries
|
||||
/// </summary>
|
||||
public PublishedFileId[]? Children;
|
||||
|
||||
/// <summary>
|
||||
/// Additional previews of this item or collection, available only from WithAdditionalPreviews(true) queries
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace FarseerPhysics.Collision
|
||||
internal int Height;
|
||||
internal int ParentOrNext;
|
||||
|
||||
public object Body;
|
||||
public Body Body;
|
||||
|
||||
internal T UserData;
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace FarseerPhysics.Collision
|
||||
return _nodes[proxyId].AABB;
|
||||
}
|
||||
|
||||
public object GetBody(int proxyId)
|
||||
public Body GetBody(int proxyId)
|
||||
{
|
||||
Debug.Assert(0 <= proxyId && proxyId < _nodeCapacity);
|
||||
return _nodes[proxyId].Body;
|
||||
@@ -344,7 +344,7 @@ namespace FarseerPhysics.Collision
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback.</param>
|
||||
/// <param name="aabb">The aabb.</param>
|
||||
public void Query(Func<int, bool> callback, ref AABB aabb, ref object body)
|
||||
public void Query(Func<int, bool> callback, ref AABB aabb, ref Body body)
|
||||
{
|
||||
_queryStack.Clear();
|
||||
_queryStack.Push(_root);
|
||||
@@ -357,22 +357,38 @@ namespace FarseerPhysics.Collision
|
||||
continue;
|
||||
}
|
||||
|
||||
//TreeNode<T>* node = &_nodes[nodeId];
|
||||
if (!ReferenceEquals(_nodes[nodeId].Body, body) && AABB.TestOverlap(ref _nodes[nodeId].AABB, ref aabb))
|
||||
TreeNode<T> node = _nodes[nodeId];
|
||||
if (node.Body != body && AABB.TestOverlap(ref node.AABB, ref aabb))
|
||||
{
|
||||
if (_nodes[nodeId].IsLeaf())
|
||||
if (node.IsLeaf())
|
||||
{
|
||||
if (node.Body.CollidesWithMatchesBetweenFixtures &&
|
||||
body.CollisionCategoriesMatchBetweenFixtures)
|
||||
{
|
||||
//equivalent to
|
||||
//collide = node.Body.CollidesWith.HasAnyFlag(body.CollisionCategories) && body.CollidesWith.HasAnyFlag(node.Body.CollisionCategories)
|
||||
//same check as in ContactManager.ShouldCollide
|
||||
//inlined here using binary operations because this is performance critical code
|
||||
bool collide =
|
||||
(node.Body.CollidesWith & body.CollisionCategories) != 0 &&
|
||||
(body.CollidesWith & node.Body.CollisionCategories) != 0;
|
||||
if (!collide)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
bool proceed = callback(nodeId);
|
||||
if (proceed == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_queryStack.Push(_nodes[nodeId].Child1);
|
||||
_queryStack.Push(_nodes[nodeId].Child2);
|
||||
}
|
||||
_queryStack.Push(node.Child1);
|
||||
_queryStack.Push(node.Child2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace FarseerPhysics.Collision
|
||||
// we don't fail to create a pair that may touch later.
|
||||
AABB fatAABB = _tree.GetFatAABB(_queryProxyId);
|
||||
|
||||
object body = _tree.GetBody(_queryProxyId);
|
||||
Body body = _tree.GetBody(_queryProxyId);
|
||||
|
||||
// Query tree, create pairs and add them pair buffer.
|
||||
_tree.Query(_queryCallback, ref fatAABB, ref body);
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace FarseerPhysics.Collision.Shapes
|
||||
}
|
||||
|
||||
// Find the point of intersection of the line with the circle.
|
||||
float a = -(c + (float)Math.Sqrt(sigma));
|
||||
float a = -(c + MathF.Sqrt(sigma));
|
||||
|
||||
// Is the intersection point on the segment?
|
||||
if (0.0f <= a && a <= input.MaxFraction * rr)
|
||||
@@ -177,8 +177,8 @@ namespace FarseerPhysics.Collision.Shapes
|
||||
|
||||
//Magic
|
||||
float l2 = l * l;
|
||||
float area = _2radius * (float)((Math.Asin(l / Radius) + MathHelper.Pi / 2) + l * Math.Sqrt(_2radius - l2));
|
||||
float com = -2.0f / 3.0f * (float)Math.Pow(_2radius - l2, 1.5f) / area;
|
||||
float area = _2radius * ((MathF.Asin(l / Radius) + MathHelper.Pi / 2) + l * MathF.Sqrt(_2radius - l2));
|
||||
float com = -2.0f / 3.0f * MathF.Pow(_2radius - l2, 1.5f) / area;
|
||||
|
||||
sc.X = p.X + normal.X * com;
|
||||
sc.Y = p.Y + normal.Y * com;
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace FarseerPhysics.Common.Decomposition.Seidel
|
||||
{
|
||||
Point a = (p.Next - p);
|
||||
Point b = (p.Prev - p);
|
||||
return (float)Math.Atan2(a.Cross(b), a.Dot(b));
|
||||
return MathF.Atan2(a.Cross(b), a.Dot(b));
|
||||
}
|
||||
|
||||
private bool AngleSign()
|
||||
|
||||
@@ -709,7 +709,7 @@ namespace FarseerPhysics.Common
|
||||
/// </summary>
|
||||
public void Normalize()
|
||||
{
|
||||
float d = MathHelper.TwoPi * (float)Math.Floor(A0 / MathHelper.TwoPi);
|
||||
float d = MathHelper.TwoPi * MathF.Floor(A0 / MathHelper.TwoPi);
|
||||
A0 -= d;
|
||||
A -= d;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace FarseerPhysics.Common.Maths
|
||||
|
||||
public float Phase
|
||||
{
|
||||
get { return (float)Math.Atan2(Imaginary, Real); }
|
||||
get { return MathF.Atan2(Imaginary, Real); }
|
||||
set
|
||||
{
|
||||
if (value == 0)
|
||||
@@ -26,14 +26,14 @@ namespace FarseerPhysics.Common.Maths
|
||||
this = Complex.One;
|
||||
return;
|
||||
}
|
||||
this.Real = (float)Math.Cos(value);
|
||||
this.Imaginary = (float)Math.Sin(value);
|
||||
this.Real = MathF.Cos(value);
|
||||
this.Imaginary = MathF.Sin(value);
|
||||
}
|
||||
}
|
||||
|
||||
public float Magnitude
|
||||
{
|
||||
get { return (float)Math.Round(Math.Sqrt(MagnitudeSquared())); }
|
||||
get { return MathF.Round(MathF.Sqrt(MagnitudeSquared())); }
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace FarseerPhysics.Common.Maths
|
||||
return Complex.One;
|
||||
|
||||
return new Complex(
|
||||
(float)Math.Cos(angle),
|
||||
(float)Math.Sin(angle));
|
||||
MathF.Cos(angle),
|
||||
MathF.Sin(angle));
|
||||
}
|
||||
|
||||
public void Conjugate()
|
||||
|
||||
@@ -315,7 +315,7 @@ namespace FarseerPhysics.Common
|
||||
for (int i = 1; i < divisions; i++)
|
||||
{
|
||||
Vector2 normal = GetPositionNormal(t);
|
||||
float angle = (float)Math.Atan2(normal.Y, normal.X);
|
||||
float angle = MathF.Atan2(normal.Y, normal.X);
|
||||
|
||||
verts.Add(new Vector3(end, angle));
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Original source Farseer Physics Engine:
|
||||
/* Original source Farseer Physics Engine:
|
||||
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com
|
||||
* Microsoft Permissive License (Ms-PL) v1.1
|
||||
*/
|
||||
@@ -14,7 +14,7 @@ using FarseerPhysics.Dynamics;
|
||||
namespace FarseerPhysics.Common.PhysicsLogic
|
||||
{
|
||||
// Original Code by Steven Lu - see http://www.box2d.org/forum/viewtopic.php?f=3&t=1688
|
||||
// Ported to Farseer 3.0 by Nicolás Hormazábal
|
||||
// Ported to Farseer 3.0 by Nicolás Hormazábal
|
||||
|
||||
internal struct ShapeData
|
||||
{
|
||||
@@ -185,7 +185,7 @@ namespace FarseerPhysics.Common.PhysicsLogic
|
||||
if ((shapes[i].Body.BodyType == BodyType.Dynamic) && ps != null)
|
||||
{
|
||||
Vector2 toCentroid = shapes[i].Body.GetWorldPoint(ps.MassData.Centroid) - pos;
|
||||
float angleToCentroid = (float)Math.Atan2(toCentroid.Y, toCentroid.X);
|
||||
float angleToCentroid = MathF.Atan2(toCentroid.Y, toCentroid.X);
|
||||
float min = float.MaxValue;
|
||||
float max = float.MinValue;
|
||||
float minAbsolute = 0.0f;
|
||||
@@ -194,7 +194,7 @@ namespace FarseerPhysics.Common.PhysicsLogic
|
||||
for (int j = 0; j < ps.Vertices.Count; ++j)
|
||||
{
|
||||
Vector2 toVertex = (shapes[i].Body.GetWorldPoint(ps.Vertices[j]) - pos);
|
||||
float newAngle = (float)Math.Atan2(toVertex.Y, toVertex.X);
|
||||
float newAngle = MathF.Atan2(toVertex.Y, toVertex.X);
|
||||
float diff = (newAngle - angleToCentroid);
|
||||
|
||||
diff = (diff - MathHelper.Pi) % (2 * MathHelper.Pi);
|
||||
@@ -253,7 +253,7 @@ namespace FarseerPhysics.Common.PhysicsLogic
|
||||
midpt = midpt / 2;
|
||||
|
||||
Vector2 p1 = pos;
|
||||
Vector2 p2 = radius * new Vector2((float)Math.Cos(midpt), (float)Math.Sin(midpt)) + pos;
|
||||
Vector2 p2 = radius * new Vector2(MathF.Cos(midpt), MathF.Sin(midpt)) + pos;
|
||||
|
||||
// RaycastOne
|
||||
bool hitClosest = false;
|
||||
@@ -343,7 +343,7 @@ namespace FarseerPhysics.Common.PhysicsLogic
|
||||
j += offset)
|
||||
{
|
||||
Vector2 p1 = pos;
|
||||
Vector2 p2 = pos + radius * new Vector2((float)Math.Cos(j), (float)Math.Sin(j));
|
||||
Vector2 p2 = pos + radius * new Vector2(MathF.Cos(j), MathF.Sin(j));
|
||||
Vector2 hitpoint = Vector2.Zero;
|
||||
float minlambda = float.MaxValue;
|
||||
|
||||
@@ -371,7 +371,7 @@ namespace FarseerPhysics.Common.PhysicsLogic
|
||||
float impulse = (arclen / (MinRays + insertedRays)) * maxForce * 180.0f / MathHelper.Pi * (1.0f - Math.Min(1.0f, minlambda));
|
||||
|
||||
// We Apply the impulse!!!
|
||||
Vector2 vectImp = Vector2.Dot(impulse * new Vector2((float)Math.Cos(j), (float)Math.Sin(j)), -ro.Normal) * new Vector2((float)Math.Cos(j), (float)Math.Sin(j));
|
||||
Vector2 vectImp = Vector2.Dot(impulse * new Vector2(MathF.Cos(j), MathF.Sin(j)), -ro.Normal) * new Vector2(MathF.Cos(j), MathF.Sin(j));
|
||||
_data[i].Body.ApplyLinearImpulse(ref vectImp, ref hitpoint);
|
||||
|
||||
// We gather the fixtures for returning them
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace FarseerPhysics.Common.PhysicsLogic
|
||||
float forcePercent = GetPercent(distance, radius);
|
||||
|
||||
Vector2 forceVector = pos - overlappingBody.Position;
|
||||
forceVector *= 1f / (float)Math.Sqrt(forceVector.X * forceVector.X + forceVector.Y * forceVector.Y);
|
||||
forceVector *= 1f / MathF.Sqrt(forceVector.X * forceVector.X + forceVector.Y * forceVector.Y);
|
||||
forceVector *= MathHelper.Min(force * forcePercent, maxForce);
|
||||
forceVector *= -1;
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace FarseerPhysics.Common.PhysicsLogic
|
||||
private float GetPercent(float distance, float radius)
|
||||
{
|
||||
//(1-(distance/radius))^power-1
|
||||
float percent = (float)Math.Pow(1 - ((distance - radius) / radius), Power) - 1;
|
||||
float percent = MathF.Pow(1 - ((distance - radius) / radius), Power) - 1;
|
||||
|
||||
if (float.IsNaN(percent))
|
||||
return 0f;
|
||||
|
||||
@@ -137,8 +137,8 @@ namespace FarseerPhysics.Common.PolygonManipulation
|
||||
float dy0 = vertices[middle].Y - vertices[lower].Y;
|
||||
float dx1 = vertices[upper].Y - vertices[middle].X;
|
||||
float dy1 = vertices[upper].Y - vertices[middle].Y;
|
||||
float norm0 = (float)Math.Sqrt(dx0 * dx0 + dy0 * dy0);
|
||||
float norm1 = (float)Math.Sqrt(dx1 * dx1 + dy1 * dy1);
|
||||
float norm0 = MathF.Sqrt(dx0 * dx0 + dy0 * dy0);
|
||||
float norm1 = MathF.Sqrt(dx1 * dx1 + dy1 * dy1);
|
||||
|
||||
if (!(norm0 > 0.0f && norm1 > 0.0f) && newNVertices > 3)
|
||||
{
|
||||
|
||||
@@ -112,8 +112,8 @@ namespace FarseerPhysics.Common
|
||||
phase--;
|
||||
}
|
||||
|
||||
vertices.Add(posOffset + new Vector2(xRadius * (float)Math.Cos(stepSize * -(i + phase)),
|
||||
-yRadius * (float)Math.Sin(stepSize * -(i + phase))));
|
||||
vertices.Add(posOffset + new Vector2(xRadius * MathF.Cos(stepSize * -(i + phase)),
|
||||
-yRadius * MathF.Sin(stepSize * -(i + phase))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,8 +160,8 @@ namespace FarseerPhysics.Common
|
||||
|
||||
vertices.Add(new Vector2(xRadius, 0));
|
||||
for (int i = numberOfEdges - 1; i > 0; --i)
|
||||
vertices.Add(new Vector2(xRadius * (float)Math.Cos(stepSize * i),
|
||||
-yRadius * (float)Math.Sin(stepSize * i)));
|
||||
vertices.Add(new Vector2(xRadius * MathF.Cos(stepSize * i),
|
||||
-yRadius * MathF.Sin(stepSize * i)));
|
||||
|
||||
return vertices;
|
||||
}
|
||||
@@ -177,8 +177,8 @@ namespace FarseerPhysics.Common
|
||||
float stepSize = radians / sides;
|
||||
for (int i = sides - 1; i > 0; i--)
|
||||
{
|
||||
vertices.Add(new Vector2(radius * (float)Math.Cos(stepSize * i),
|
||||
radius * (float)Math.Sin(stepSize * i)));
|
||||
vertices.Add(new Vector2(radius * MathF.Cos(stepSize * i),
|
||||
radius * MathF.Sin(stepSize * i)));
|
||||
}
|
||||
|
||||
return vertices;
|
||||
@@ -252,8 +252,8 @@ namespace FarseerPhysics.Common
|
||||
float stepSize = MathHelper.Pi / topEdges;
|
||||
for (int i = 1; i < topEdges; i++)
|
||||
{
|
||||
vertices.Add(new Vector2(topRadius * (float)Math.Cos(stepSize * i),
|
||||
topRadius * (float)Math.Sin(stepSize * i) + newHeight));
|
||||
vertices.Add(new Vector2(topRadius * MathF.Cos(stepSize * i),
|
||||
topRadius * MathF.Sin(stepSize * i) + newHeight));
|
||||
}
|
||||
|
||||
vertices.Add(new Vector2(-topRadius, newHeight));
|
||||
@@ -264,8 +264,8 @@ namespace FarseerPhysics.Common
|
||||
stepSize = MathHelper.Pi / bottomEdges;
|
||||
for (int i = 1; i < bottomEdges; i++)
|
||||
{
|
||||
vertices.Add(new Vector2(-bottomRadius * (float)Math.Cos(stepSize * i),
|
||||
-bottomRadius * (float)Math.Sin(stepSize * i) - newHeight));
|
||||
vertices.Add(new Vector2(-bottomRadius * MathF.Cos(stepSize * i),
|
||||
-bottomRadius * MathF.Sin(stepSize * i) - newHeight));
|
||||
}
|
||||
|
||||
vertices.Add(new Vector2(bottomRadius, -newHeight));
|
||||
@@ -298,24 +298,24 @@ namespace FarseerPhysics.Common
|
||||
{
|
||||
vertices.Add(
|
||||
new Vector2(radius *
|
||||
(float)Math.Cos(stepSize * i + toothAngleStepSize * 2f + toothTipStepSize),
|
||||
MathF.Cos(stepSize * i + toothAngleStepSize * 2f + toothTipStepSize),
|
||||
-radius *
|
||||
(float)Math.Sin(stepSize * i + toothAngleStepSize * 2f + toothTipStepSize)));
|
||||
MathF.Sin(stepSize * i + toothAngleStepSize * 2f + toothTipStepSize)));
|
||||
|
||||
vertices.Add(
|
||||
new Vector2((radius + toothHeight) *
|
||||
(float)Math.Cos(stepSize * i + toothAngleStepSize + toothTipStepSize),
|
||||
MathF.Cos(stepSize * i + toothAngleStepSize + toothTipStepSize),
|
||||
-(radius + toothHeight) *
|
||||
(float)Math.Sin(stepSize * i + toothAngleStepSize + toothTipStepSize)));
|
||||
MathF.Sin(stepSize * i + toothAngleStepSize + toothTipStepSize)));
|
||||
}
|
||||
|
||||
vertices.Add(new Vector2((radius + toothHeight) *
|
||||
(float)Math.Cos(stepSize * i + toothAngleStepSize),
|
||||
MathF.Cos(stepSize * i + toothAngleStepSize),
|
||||
-(radius + toothHeight) *
|
||||
(float)Math.Sin(stepSize * i + toothAngleStepSize)));
|
||||
MathF.Sin(stepSize * i + toothAngleStepSize)));
|
||||
|
||||
vertices.Add(new Vector2(radius * (float)Math.Cos(stepSize * i),
|
||||
-radius * (float)Math.Sin(stepSize * i)));
|
||||
vertices.Add(new Vector2(radius * MathF.Cos(stepSize * i),
|
||||
-radius * MathF.Sin(stepSize * i)));
|
||||
}
|
||||
|
||||
return vertices;
|
||||
|
||||
@@ -287,8 +287,8 @@ namespace FarseerPhysics.Common
|
||||
{
|
||||
Debug.Assert(!AttachedToBody, "Rotating vertices that are used by a Body can result in unstable behavior.");
|
||||
|
||||
float num1 = (float)Math.Cos(value);
|
||||
float num2 = (float)Math.Sin(value);
|
||||
float num1 = MathF.Cos(value);
|
||||
float num2 = MathF.Sin(value);
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace FarseerPhysics.Controllers
|
||||
f = Strength / r2 * worldBody.Mass * controllerBody.Mass * d;
|
||||
break;
|
||||
case GravityType.Linear:
|
||||
f = Strength / (float)Math.Sqrt(r2) * worldBody.Mass * controllerBody.Mass * d;
|
||||
f = Strength / MathF.Sqrt(r2) * worldBody.Mass * controllerBody.Mass * d;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace FarseerPhysics.Controllers
|
||||
f = Strength / r2 * worldBody.Mass * d;
|
||||
break;
|
||||
case GravityType.Linear:
|
||||
f = Strength / (float)Math.Sqrt(r2) * worldBody.Mass * d;
|
||||
f = Strength / MathF.Sqrt(r2) * worldBody.Mass * d;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace FarseerPhysics.Controllers
|
||||
|
||||
if (result > dt * _maxLinearSqared)
|
||||
{
|
||||
float sq = (float)Math.Sqrt(result);
|
||||
float sq = MathF.Sqrt(result);
|
||||
|
||||
float ratio = _maxLinearVelocity / sq;
|
||||
body._linearVelocity.X *= ratio;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using FarseerPhysics.Collision;
|
||||
using FarseerPhysics.Collision.Shapes;
|
||||
using FarseerPhysics.Common;
|
||||
@@ -98,7 +99,7 @@ namespace FarseerPhysics.Dynamics
|
||||
/// <value>The revolutions.</value>
|
||||
public float Revolutions
|
||||
{
|
||||
get { return Rotation / (float)Math.PI; }
|
||||
get { return Rotation / MathF.PI; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -614,6 +615,10 @@ namespace FarseerPhysics.Dynamics
|
||||
|
||||
fixture.Body = this;
|
||||
this.FixtureList.Add(fixture);
|
||||
|
||||
RefreshCollidesWithMatchesBetweenFixtures();
|
||||
RefreshCollisionCategoriesMatchBetweenFixtures();
|
||||
|
||||
#if DEBUG
|
||||
if (fixture.Shape.ShapeType == ShapeType.Polygon)
|
||||
((PolygonShape)fixture.Shape).Vertices.AttachedToBody = true;
|
||||
@@ -685,6 +690,8 @@ namespace FarseerPhysics.Dynamics
|
||||
|
||||
fixture.Body = null;
|
||||
FixtureList.Remove(fixture);
|
||||
RefreshCollidesWithMatchesBetweenFixtures();
|
||||
RefreshCollisionCategoriesMatchBetweenFixtures();
|
||||
#if DEBUG
|
||||
if (fixture.Shape.ShapeType == ShapeType.Polygon)
|
||||
((PolygonShape)fixture.Shape).Vertices.AttachedToBody = false;
|
||||
@@ -1241,29 +1248,89 @@ namespace FarseerPhysics.Dynamics
|
||||
FixtureList[i].Friction = friction;
|
||||
}
|
||||
|
||||
public bool CollisionCategoriesMatchBetweenFixtures
|
||||
{
|
||||
get; private set;
|
||||
} = false;
|
||||
|
||||
private Category _collisionCategories;
|
||||
public Category CollisionCategories
|
||||
{
|
||||
get { return _collisionCategories; }
|
||||
set { SetCollisionCategories(value); }
|
||||
}
|
||||
|
||||
public bool CollidesWithMatchesBetweenFixtures
|
||||
{
|
||||
get; private set;
|
||||
} = false;
|
||||
|
||||
private Category _collidesWith;
|
||||
public Category CollidesWith
|
||||
{
|
||||
get { return _collidesWith; }
|
||||
set { SetCollidesWith(value); }
|
||||
}
|
||||
|
||||
public void RefreshCollisionCategoriesMatchBetweenFixtures()
|
||||
{
|
||||
if (FixtureList.Count < 2)
|
||||
{
|
||||
if (FixtureList.Count > 0) { _collisionCategories = FixtureList[0].CollisionCategories; }
|
||||
CollisionCategoriesMatchBetweenFixtures = true;
|
||||
return;
|
||||
}
|
||||
for (int i = 1; i < FixtureList.Count; i++)
|
||||
{
|
||||
if (FixtureList[i].CollisionCategories != FixtureList[0].CollisionCategories)
|
||||
{
|
||||
CollisionCategoriesMatchBetweenFixtures = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
CollisionCategoriesMatchBetweenFixtures = true;
|
||||
_collisionCategories = FixtureList[0].CollisionCategories;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Warning: This method applies the value on existing Fixtures. It's not a property of Body.
|
||||
/// </summary>
|
||||
public void SetCollisionCategories(Category category)
|
||||
{
|
||||
CollisionCategoriesMatchBetweenFixtures = true;
|
||||
_collisionCategories = category;
|
||||
for (int i = 0; i < FixtureList.Count; i++)
|
||||
FixtureList[i].CollisionCategories = category;
|
||||
}
|
||||
|
||||
public void RefreshCollidesWithMatchesBetweenFixtures()
|
||||
{
|
||||
if (FixtureList.Count < 2)
|
||||
{
|
||||
if (FixtureList.Count > 0) { _collidesWith = FixtureList[0].CollidesWith; }
|
||||
CollidesWithMatchesBetweenFixtures = true;
|
||||
return;
|
||||
}
|
||||
for (int i = 1; i < FixtureList.Count; i++)
|
||||
{
|
||||
if (FixtureList[i].CollidesWith != FixtureList[0].CollidesWith)
|
||||
{
|
||||
CollidesWithMatchesBetweenFixtures = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
CollidesWithMatchesBetweenFixtures = true;
|
||||
_collidesWith = FixtureList[0].CollidesWith;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Warning: This method applies the value on existing Fixtures. It's not a property of Body.
|
||||
/// </summary>
|
||||
public void SetCollidesWith(Category category)
|
||||
{
|
||||
CollidesWithMatchesBetweenFixtures = true;
|
||||
_collidesWith = category;
|
||||
for (int i = 0; i < FixtureList.Count; i++)
|
||||
FixtureList[i].CollidesWith = category;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,6 @@ namespace FarseerPhysics.Dynamics
|
||||
if (bodyB.ShouldCollide(bodyA) == false)
|
||||
return;
|
||||
|
||||
//Check default filter
|
||||
if (ShouldCollide(fixtureA, fixtureB) == false)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2017 Kastellanos Nikolaos
|
||||
// Copyright (c) 2017 Kastellanos Nikolaos
|
||||
|
||||
/* Original source Farseer Physics Engine:
|
||||
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com
|
||||
@@ -139,6 +139,10 @@ namespace FarseerPhysics.Dynamics
|
||||
|
||||
_collidesWith = value;
|
||||
Refilter();
|
||||
if (Body != null)
|
||||
{
|
||||
Body.RefreshCollidesWithMatchesBetweenFixtures();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,13 +155,17 @@ namespace FarseerPhysics.Dynamics
|
||||
{
|
||||
get { return _collisionCategories; }
|
||||
|
||||
set
|
||||
internal set
|
||||
{
|
||||
if (_collisionCategories == value)
|
||||
return;
|
||||
|
||||
_collisionCategories = value;
|
||||
Refilter();
|
||||
if (Body != null)
|
||||
{
|
||||
Body.RefreshCollisionCategoriesMatchBetweenFixtures();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Original source Farseer Physics Engine:
|
||||
/* Original source Farseer Physics Engine:
|
||||
* Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com
|
||||
* Microsoft Permissive License (Ms-PL) v1.1
|
||||
*/
|
||||
@@ -243,7 +243,7 @@ namespace FarseerPhysics.Dynamics.Joints
|
||||
Enabled = false;
|
||||
|
||||
if (Broke != null)
|
||||
Broke(this, (float)Math.Sqrt(jointErrorSquared));
|
||||
Broke(this, MathF.Sqrt(jointErrorSquared));
|
||||
}
|
||||
|
||||
internal abstract void SolveVelocityConstraints(ref SolverData data);
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace FarseerPhysics.Fluids
|
||||
|
||||
if (u > 0.0f)
|
||||
{
|
||||
q = 1.0f - (float)Math.Sqrt(q) / Definition.InfluenceRadius;
|
||||
q = 1.0f - MathF.Sqrt(q) / Definition.InfluenceRadius;
|
||||
|
||||
float impulseFactor = 0.5f * timeStep * q * (u * (Definition.ViscositySigma + Definition.ViscosityBeta * u));
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace FarseerPhysics.Fluids
|
||||
// _distanceCache[_j] = _q;
|
||||
// if (_q < _influenceRadiusSquared && _q != 0)
|
||||
// {
|
||||
// _q = (float)Math.Sqrt(_q);
|
||||
// _q = MathF.Sqrt(_q);
|
||||
// _q /= Definition.InfluenceRadius;
|
||||
// _qq = ((1 - _q) * (1 - _q));
|
||||
// _density += _qq;
|
||||
@@ -170,7 +170,7 @@ namespace FarseerPhysics.Fluids
|
||||
// _q = _distanceCache[_j];
|
||||
// if (_q < _influenceRadiusSquared && _q != 0)
|
||||
// {
|
||||
// _q = (float)Math.Sqrt(_q);
|
||||
// _q = MathF.Sqrt(_q);
|
||||
// _rij = p.Neighbours[_j].Position;
|
||||
// _rij -= p.Position;
|
||||
// _rij *= 1 / _q;
|
||||
@@ -209,7 +209,7 @@ namespace FarseerPhysics.Fluids
|
||||
if (q > _influenceRadiusSquared)
|
||||
continue;
|
||||
|
||||
q = 1.0f - (float)Math.Sqrt(q) / Definition.InfluenceRadius;
|
||||
q = 1.0f - MathF.Sqrt(q) / Definition.InfluenceRadius;
|
||||
|
||||
float densityDelta = q * q;
|
||||
_density += densityDelta;
|
||||
@@ -237,7 +237,7 @@ namespace FarseerPhysics.Fluids
|
||||
if (q > _influenceRadiusSquared)
|
||||
continue;
|
||||
|
||||
q = 1.0f - (float)Math.Sqrt(q) / Definition.InfluenceRadius;
|
||||
q = 1.0f - MathF.Sqrt(q) / Definition.InfluenceRadius;
|
||||
|
||||
float dispFactor = deltaTime2 * (q * (_pressure + _pressureNear * q));
|
||||
|
||||
@@ -281,7 +281,7 @@ namespace FarseerPhysics.Fluids
|
||||
if (!_springs.ContainsKey(hash))
|
||||
{
|
||||
//TODO: Use pool?
|
||||
Spring spring = new Spring(p, neighbour) { RestLength = (float)Math.Sqrt(q) };
|
||||
Spring spring = new Spring(p, neighbour) { RestLength = MathF.Sqrt(q) };
|
||||
_springs.Add(hash, spring);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace FarseerPhysics.Fluids
|
||||
Vector2.DistanceSquared(ref particle.Position, ref tempParticle.Position, out q);
|
||||
if ((q < InfluenceRadiusSquared) && (q != 0))
|
||||
{
|
||||
q = (float)Math.Sqrt(q);
|
||||
q = MathF.Sqrt(q);
|
||||
Vector2.Subtract(ref tempParticle.Position, ref particle.Position, out _rij);
|
||||
Vector2.Divide(ref _rij, q, out _rij);
|
||||
|
||||
@@ -329,7 +329,7 @@ namespace FarseerPhysics.Fluids
|
||||
Vector2.DistanceSquared(ref particle.Position, ref tempParticle.Position, out q);
|
||||
if (q < InfluenceRadiusSquared && q != 0)
|
||||
{
|
||||
q = (float)Math.Sqrt(q);
|
||||
q = MathF.Sqrt(q);
|
||||
q /= InfluenceRadius;
|
||||
float qq = ((1 - q) * (1 - q));
|
||||
particle.Density += qq;
|
||||
@@ -348,7 +348,7 @@ namespace FarseerPhysics.Fluids
|
||||
Vector2.DistanceSquared(ref particle.Position, ref tempParticle.Position, out q);
|
||||
if ((q < InfluenceRadiusSquared) && (q != 0))
|
||||
{
|
||||
q = (float)Math.Sqrt(q);
|
||||
q = MathF.Sqrt(q);
|
||||
Vector2.Subtract(ref tempParticle.Position, ref particle.Position, out _rij);
|
||||
Vector2.Divide(ref _rij, q, out _rij);
|
||||
q /= InfluenceRadius;
|
||||
|
||||
@@ -220,7 +220,7 @@ namespace FarseerPhysics
|
||||
/// <returns></returns>
|
||||
public static float MixFriction(float friction1, float friction2)
|
||||
{
|
||||
return (float)Math.Sqrt(friction1 * friction2);
|
||||
return MathF.Sqrt(friction1 * friction2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Microsoft.Xna.Framework
|
||||
{
|
||||
public static class Display
|
||||
{
|
||||
public static int GetNumberOfDisplays()
|
||||
=> Sdl.Display.GetNumVideoDisplays();
|
||||
|
||||
public static string GetDisplayName(int displayIndex)
|
||||
=> Sdl.Display.GetDisplayName(displayIndex);
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,8 @@ namespace Microsoft.Xna.Framework {
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int TargetDisplay { get => 0; set => throw new NotImplementedException(); }
|
||||
|
||||
internal MouseState MouseState;
|
||||
internal TouchPanelState TouchPanelState;
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<Compile Include="Clipboard.cs" />
|
||||
<Compile Include="FileDropEventArgs.cs" />
|
||||
<Compile Include="MessageBox.cs" />
|
||||
<Compile Include="Display.cs" />
|
||||
<Compile Include="CurveContinuity.cs" />
|
||||
<Compile Include="Curve.cs" />
|
||||
<Compile Include="CurveKeyCollection.cs" />
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<Compile Include="Clipboard.cs" />
|
||||
<Compile Include="FileDropEventArgs.cs" />
|
||||
<Compile Include="MessageBox.cs" />
|
||||
<Compile Include="Display.cs" />
|
||||
<Compile Include="CurveContinuity.cs" />
|
||||
<Compile Include="Curve.cs" />
|
||||
<Compile Include="CurveKeyCollection.cs" />
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
<Compile Include="IUpdateable.cs" />
|
||||
<Compile Include="LaunchParameters.cs" />
|
||||
<Compile Include="MessageBox.cs" />
|
||||
<Compile Include="Display.cs" />
|
||||
<Compile Include="NamespaceDocs.cs" />
|
||||
<Compile Include="PlayerIndex.cs" />
|
||||
<Compile Include="PreparingDeviceSettingsEventArgs.cs" />
|
||||
|
||||
@@ -87,6 +87,22 @@ namespace Microsoft.Xna.Framework
|
||||
}
|
||||
}
|
||||
|
||||
public override int TargetDisplay
|
||||
{
|
||||
get => Sdl.Window.GetDisplayIndex(Handle);
|
||||
set
|
||||
{
|
||||
int maxDisplayIndex = Sdl.Display.GetNumVideoDisplays() - 1;
|
||||
|
||||
// if the value is out of range, set it to 0 (the primary display)
|
||||
if (value > maxDisplayIndex || value < 0) { value = 0; }
|
||||
|
||||
if (value == Sdl.Window.GetDisplayIndex(Handle)) { return; }
|
||||
|
||||
Sdl.Window.SetPosition(Handle, Sdl.Window.PosCentered | value, Sdl.Window.PosCentered | value);
|
||||
}
|
||||
}
|
||||
|
||||
public static GameWindow Instance;
|
||||
public uint? Id;
|
||||
public bool IsFullScreen;
|
||||
@@ -163,13 +179,6 @@ namespace Microsoft.Xna.Framework
|
||||
var winx = Sdl.Window.PosCentered;
|
||||
var winy = Sdl.Window.PosCentered;
|
||||
|
||||
// if we are on Linux, start on the current screen
|
||||
if (CurrentPlatform.OS == OS.Linux)
|
||||
{
|
||||
winx |= GetMouseDisplay();
|
||||
winy |= GetMouseDisplay();
|
||||
}
|
||||
|
||||
_handle = Sdl.Window.Create(AssemblyHelper.GetDefaultWindowTitle(),
|
||||
winx, winy, _width, _height, initflags);
|
||||
|
||||
@@ -269,11 +278,8 @@ namespace Microsoft.Xna.Framework
|
||||
|
||||
OnClientSizeChanged();
|
||||
|
||||
int ignore, minx = 0, miny = 0;
|
||||
Sdl.Window.GetBorderSize(_handle, out miny, out minx, out ignore, out ignore);
|
||||
|
||||
var centerX = Math.Max(prevBounds.X + ((prevBounds.Width - clientWidth) / 2), minx);
|
||||
var centerY = Math.Max(prevBounds.Y + ((prevBounds.Height - clientHeight) / 2), miny);
|
||||
var centerX = prevBounds.X + ((prevBounds.Width - clientWidth) / 2);
|
||||
var centerY = prevBounds.Y + ((prevBounds.Height - clientHeight) / 2);
|
||||
|
||||
if (IsFullScreen && !_willBeFullScreen)
|
||||
{
|
||||
@@ -291,7 +297,7 @@ namespace Microsoft.Xna.Framework
|
||||
// after the window gets resized, window position information
|
||||
// becomes wrong (for me it always returned 10 8). Solution is
|
||||
// to not try and set the window position because it will be wrong.
|
||||
if ((Sdl.Patch > 4 || !AllowUserResizing) && !_wasMoved)
|
||||
if (((Sdl.Patch > 4 && Sdl.Minor == 0) || !AllowUserResizing) && !_wasMoved)
|
||||
Sdl.Window.SetPosition(Handle, centerX, centerY);
|
||||
|
||||
Sdl.Window.Show(Handle);
|
||||
|
||||
Reference in New Issue
Block a user