Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix many compiler warnings #487

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class DefaultGamelogicEngine : MonoBehaviour, IGamelogicEngine
{
public string Name => "Default Game Engine";

#pragma warning disable CS0067
public event EventHandler<CoilEventArgs> OnCoilChanged;
public event EventHandler<LampEventArgs> OnLampChanged;
public event EventHandler<LampsEventArgs> OnLampsChanged;
Expand All @@ -52,6 +53,7 @@ public class DefaultGamelogicEngine : MonoBehaviour, IGamelogicEngine
public event EventHandler<string> OnDisplayClear;
public event EventHandler<DisplayFrameData> OnDisplayUpdateFrame;
public event EventHandler<EventArgs> OnStarted;
#pragma warning restore CS0067

private const int DmdWidth = 128;
private const int DmdHeight = 32;
Expand Down
3 changes: 2 additions & 1 deletion VisualPinball.Unity/VisualPinball.Unity/Game/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Player : MonoBehaviour
[NonSerialized]
public BallManager BallManager;

public event EventHandler OnPlayeStarted;
public event EventHandler OnPlayerStarted;

public List<SwitchMapping> SwitchMapping => _tableComponent.MappingConfig.Switches;
public List<CoilMapping> CoilMapping => _tableComponent.MappingConfig.Coils;
Expand Down Expand Up @@ -175,6 +175,7 @@ private void Start()
_wirePlayer.OnStart();

GamelogicEngine?.OnInit(this, TableApi, BallManager);
OnPlayerStarted?.Invoke(this, EventArgs.Empty);
}

private void Update()
Expand Down
53 changes: 33 additions & 20 deletions VisualPinball.Unity/VisualPinball.Unity/Physics/Collision/Aabb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using Unity.Mathematics;
using UnityEngine;

namespace VisualPinball.Unity
{
public struct Aabb
public struct Aabb : IEquatable<Aabb>
{
public float Left;
public float Top;
Expand All @@ -28,20 +29,20 @@ public struct Aabb
public float ZLow;
public float ZHigh;

public float Width => math.abs(Left - Right);
public float Height => math.abs(Top - Bottom);
public float Depth => math.abs(ZLow - ZHigh);
public readonly float Width => math.abs(Left - Right);
public readonly float Height => math.abs(Top - Bottom);
public readonly float Depth => math.abs(ZLow - ZHigh);

public Vector3 Min => new Vector3(Left, Top, ZLow);
public Vector3 Max => new Vector3(Right, Bottom, ZHigh);
public readonly Vector3 Min => new Vector3(Left, Top, ZLow);
public readonly Vector3 Max => new Vector3(Right, Bottom, ZHigh);

public Vector3 Center => new Vector3(
public readonly Vector3 Center => new Vector3(
(Right + Left) / 2f,
(Bottom + Top) / 2f,
(ZHigh + ZLow) / 2f
);

public Vector3 Size => new Vector3(Width, Height, Depth);
public readonly Vector3 Size => new Vector3(Width, Height, Depth);

public Aabb(float left, float right, float top, float bottom, float zLow, float zHigh)
{
Expand Down Expand Up @@ -74,7 +75,7 @@ public void Extend(Aabb other)
ZHigh = math.max(ZHigh, other.ZHigh);
}

public bool IntersectSphere(float3 sphereP, float sphereRsqr)
public readonly bool IntersectSphere(float3 sphereP, float sphereRsqr)
{
var ex = math.max(Left - sphereP.x, 0) + math.max(sphereP.x - Right, 0);
var ey = math.max(Top - sphereP.y, 0) + math.max(sphereP.y - Bottom, 0);
Expand All @@ -87,16 +88,16 @@ public bool IntersectSphere(float3 sphereP, float sphereRsqr)

// Checking Aabb 442.2034 → 509.7966 | 976.6798 ↘ 1044.273 | -8.79384 ↑ 58.79945 against Aabb 431 → 521 | 1036 ↘ 1126 | 90 ↑ 0 (2)

public bool IntersectRect(Aabb rc)
public readonly bool IntersectRect(Aabb rc)
{
return Right >= rc.Left // 521 >= 442.2034
&& Bottom >= rc.Top // 1126 >= 976.6798
&& Left <= rc.Right // 431 <= 509.7966
&& Top <= rc.Bottom // 1036 <= 1044.273
&& ZLow <= rc.ZHigh // 0 <= -8.79384
&& ZHigh >= rc.ZLow; // 90 >= 58.79945
&& Bottom >= rc.Top // 1126 >= 976.6798
&& Left <= rc.Right // 431 <= 509.7966
&& Top <= rc.Bottom // 1036 <= 1044.273
&& ZLow <= rc.ZHigh // 0 <= -8.79384
&& ZHigh >= rc.ZLow; // 90 >= 58.79945
}

public static implicit operator NativeTrees.AABB(Aabb aabb)
{
return new NativeTrees.AABB(aabb.Min, aabb.Max);
Expand All @@ -107,11 +108,11 @@ public static implicit operator NativeTrees.AABB2D(Aabb aabb)
return new NativeTrees.AABB2D(new float2(aabb.Min.x, aabb.Min.y), new float2(aabb.Min.x, aabb.Max.y));
}

public static bool operator == (Aabb a, Aabb b) => a.Equals(b);
public static bool operator ==(Aabb a, Aabb b) => a.Equals(b);

public static bool operator != (Aabb a, Aabb b) => !a.Equals(b);
public static bool operator !=(Aabb a, Aabb b) => !a.Equals(b);

private bool Equals(Aabb a)
public readonly bool Equals(Aabb a)
{
return
a.Right == Left &&
Expand All @@ -122,9 +123,21 @@ private bool Equals(Aabb a)
a.ZHigh == ZHigh;
}

public override string ToString()
public override readonly bool Equals(object obj)
{
if (obj is Aabb)
return Equals(obj);
return false;
}

public override readonly string ToString()
{
return $"Aabb {Left} → {Right} | {Top} ↘ {Bottom} | {ZLow} ↑ {ZHigh}";
}

public override readonly int GetHashCode()
{
return HashCode.Combine(Right, Left, Bottom, Top, ZLow, ZHigh);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace VisualPinball.Unity
///
/// These are all read-only.
/// </summary>
public struct ColliderHeader
public struct ColliderHeader : IEquatable<ColliderHeader>
{
public ColliderType Type;
public ItemType ItemType;
Expand All @@ -48,7 +48,11 @@ public struct ColliderHeader
/// <see cref="HitLine3D"/> check this in order to know whether to emit
/// the hit event.
/// </remarks>
public bool IsPrimitive => ItemType == ItemType.Primitive || ItemType == ItemType.Ramp || ItemType == ItemType.Rubber || ItemType == ItemType.MetalWireGuide;
public readonly bool IsPrimitive
=> ItemType == ItemType.Primitive
|| ItemType == ItemType.Ramp
|| ItemType == ItemType.Rubber
|| ItemType == ItemType.MetalWireGuide;

public void Init(ColliderInfo info, ColliderType colliderType)
{
Expand All @@ -64,19 +68,26 @@ public void Init(ColliderInfo info, ColliderType colliderType)
FireEvents = info.FireEvents;
}

public static bool operator == (ColliderHeader a, ColliderHeader b) => a.Equals(b);
public static bool operator != (ColliderHeader a, ColliderHeader b) => !a.Equals(b);
public static bool operator ==(ColliderHeader a, ColliderHeader b) => a.Equals(b);
public static bool operator !=(ColliderHeader a, ColliderHeader b) => !a.Equals(b);

public bool Equals(ColliderHeader other)
public readonly bool Equals(ColliderHeader other)
=> Type == other.Type
&& ItemType == other.ItemType
&& Id == other.Id
&& ItemId == other.ItemId
&& Material == other.Material
&& Threshold == other.Threshold
&& FireEvents == other.FireEvents;

public override readonly bool Equals(object obj)
{
return
Type == other.Type &&
ItemType == other.ItemType &&
Id == other.Id &&
ItemId == other.ItemId &&
Material == other.Material &&
Threshold == other.Threshold &&
FireEvents == other.FireEvents;
if (obj is ColliderHeader)
return Equals(obj);
return false;
}

public override readonly int GetHashCode() => HashCode.Combine(
Type, ItemType, Id, ItemId, Material, Threshold, FireEvents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using Unity.Collections;
using System;

namespace VisualPinball.Unity
{
public struct PhysicsMaterialData
public struct PhysicsMaterialData : IEquatable<PhysicsMaterialData>
{
public float Elasticity;
public float ElasticityFalloff;
Expand All @@ -29,10 +30,10 @@ public struct PhysicsMaterialData
public FixedList512Bytes<float> FrictionOverVelocityLUT;
public bool UseFrictionOverVelocity;

public static bool operator == (PhysicsMaterialData a, PhysicsMaterialData b) => a.Equals(b);
public static bool operator != (PhysicsMaterialData a, PhysicsMaterialData b) => !a.Equals(b);
public static bool operator ==(PhysicsMaterialData a, PhysicsMaterialData b) => a.Equals(b);
public static bool operator !=(PhysicsMaterialData a, PhysicsMaterialData b) => !a.Equals(b);

public bool Equals(PhysicsMaterialData other)
public readonly bool Equals(PhysicsMaterialData other)
{
return
Elasticity == other.Elasticity &&
Expand All @@ -42,5 +43,18 @@ public bool Equals(PhysicsMaterialData other)
UseElasticityOverVelocity == other.UseElasticityOverVelocity &&
UseFrictionOverVelocity == other.UseFrictionOverVelocity;
}

public override readonly bool Equals(object obj)
{
if (obj is PhysicsMaterialData other) {
return Equals(other);
}
return false;
}

public override readonly int GetHashCode()
{
return HashCode.Combine(Elasticity, ElasticityFalloff, Friction, ScatterAngleRad, UseElasticityOverVelocity, UseFrictionOverVelocity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class PlayfieldComponent : MainRenderableComponent<TableData>
[Tooltip("How much the playfield should be rotated during runtime (in edit time, we keep it horizontal)")]
public float RenderSlope = 3.6f;

public int PlayfieldDetailLevel = 10;
public new int PlayfieldDetailLevel = 10;

[SerializeField] private string _playfieldImage;
[SerializeField] private string _playfieldMaterial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TableComponent : MainRenderableComponent<TableData>
[SerializeReference] public MappingConfig MappingConfig = new MappingConfig();

[SerializeField] public SerializableDictionary<string, string> TableInfo = new SerializableDictionary<string, string>();
[SerializeField] public CustomInfoTags CustomInfoTags = new CustomInfoTags();
[SerializeField] [Obsolete("Use MappingConfig")] public CustomInfoTags CustomInfoTags = new CustomInfoTags();
[SerializeField] public List<CollectionData> Collections = new List<CollectionData>();

#region Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ private void OnEntryCoilEnabled()

case TroughType.ClassicSingleBall:
throw new InvalidOperationException("Single ball trough does not have an entry coil.");
break;

default:
throw new ArgumentOutOfRangeException();
Expand Down