2022-04-08 05:52:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2022-04-08 05:52:03 +00:00
|
|
|
|
namespace MoonTools.ECS
|
2022-03-06 06:12:27 +00:00
|
|
|
|
{
|
2022-04-08 05:52:03 +00:00
|
|
|
|
public struct FilterSignature
|
2022-03-06 06:12:27 +00:00
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
public readonly HashSet<int> Included;
|
|
|
|
|
public readonly HashSet<int> Excluded;
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
public FilterSignature(HashSet<int> included, HashSet<int> excluded)
|
2022-04-08 05:52:03 +00:00
|
|
|
|
{
|
|
|
|
|
Included = included;
|
|
|
|
|
Excluded = excluded;
|
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2022-04-08 05:52:03 +00:00
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
|
{
|
|
|
|
|
return obj is FilterSignature signature && Equals(signature);
|
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
|
2022-04-08 05:52:03 +00:00
|
|
|
|
public bool Equals(FilterSignature other)
|
2022-03-06 06:12:27 +00:00
|
|
|
|
{
|
2022-04-08 05:52:03 +00:00
|
|
|
|
return Included.SetEquals(other.Included) && Excluded.SetEquals(other.Excluded);
|
2022-03-06 06:12:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 05:52:03 +00:00
|
|
|
|
private int GuidToInt(Guid guid)
|
2022-03-06 06:12:27 +00:00
|
|
|
|
{
|
2022-04-08 05:52:03 +00:00
|
|
|
|
return BitConverter.ToInt32(guid.ToByteArray());
|
2022-03-06 06:12:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-08 05:52:03 +00:00
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
var hashcode = 1;
|
|
|
|
|
|
2022-04-08 05:52:03 +00:00
|
|
|
|
foreach (var type in Included)
|
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
hashcode = HashCode.Combine(hashcode, type);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var type in Excluded)
|
|
|
|
|
{
|
2022-12-03 07:43:54 +00:00
|
|
|
|
hashcode = HashCode.Combine(hashcode, type);
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-03 07:43:54 +00:00
|
|
|
|
return hashcode;
|
2022-04-08 05:52:03 +00:00
|
|
|
|
}
|
2022-03-06 06:12:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|